--- old/src/java.base/share/native/libjava/java_props.h 2019-05-06 14:44:22.809071293 -0700 +++ new/src/java.base/share/native/libjava/java_props.h 2019-05-06 14:44:22.653071296 -0700 @@ -68,8 +68,6 @@ char *sun_stdout_encoding; char *sun_stderr_encoding; - char *awt_toolkit; - char *unicode_encoding; /* The default endianness of unicode i.e. UnicodeBig or UnicodeLittle */ --- old/src/java.base/unix/native/libjava/java_props_md.c 2019-05-06 14:44:23.205071287 -0700 +++ new/src/java.base/unix/native/libjava/java_props_md.c 2019-05-06 14:44:23.053071289 -0700 @@ -394,14 +394,6 @@ /* patches/service packs installed */ sprops.patch_level = NULL; // leave it undefined - /* Java 2D/AWT properties */ -#ifdef MACOSX - // Always the same Toolkit on Mac OS X - sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit"; -#else - sprops.awt_toolkit = "sun.awt.X11.XToolkit"; -#endif - #ifdef SI_ISALIST /* supported instruction sets */ { --- old/src/java.base/windows/native/libjava/java_props_md.c 2019-05-06 14:44:23.573071281 -0700 +++ new/src/java.base/windows/native/libjava/java_props_md.c 2019-05-06 14:44:23.449071283 -0700 @@ -365,9 +365,6 @@ return &sprops; } - /* AWT properties */ - sprops.awt_toolkit = "sun.awt.windows.WToolkit"; - /* tmp dir */ { WCHAR tmpdir[MAX_PATH + 1]; --- old/src/java.base/share/native/libjava/System.c 2019-05-06 14:44:23.945071274 -0700 +++ new/src/java.base/share/native/libjava/System.c 2019-05-06 14:44:23.809071277 -0700 @@ -204,8 +204,6 @@ /* patch level */ PUTPROP(propArray, _sun_os_patch_level_NDX, sprops->patch_level); - PUTPROP(propArray, _awt_toolkit_NDX, sprops->awt_toolkit); - PUTPROP_PlatformString(propArray, _java_io_tmpdir_NDX, sprops->tmp_dir); PUTPROP_PlatformString(propArray, _user_name_NDX, sprops->user_name); --- old/src/java.base/share/classes/jdk/internal/util/SystemProps.java 2019-05-06 14:44:24.297071269 -0700 +++ new/src/java.base/share/classes/jdk/internal/util/SystemProps.java 2019-05-06 14:44:24.165071271 -0700 @@ -90,7 +90,6 @@ putIfAbsent(props, "http.nonProxyHosts", raw.propDefault(Raw._http_nonProxyHosts_NDX)); putIfAbsent(props, "ftp.nonProxyHosts", raw.propDefault(Raw._ftp_nonProxyHosts_NDX)); putIfAbsent(props, "socksNonProxyHosts", raw.propDefault(Raw._socksNonProxyHosts_NDX)); - putIfAbsent(props, "awt.toolkit", raw.propDefault(Raw._awt_toolkit_NDX)); putIfAbsent(props, "sun.arch.abi", raw.propDefault(Raw._sun_arch_abi_NDX)); putIfAbsent(props, "sun.arch.data.model", raw.propDefault(Raw._sun_arch_data_model_NDX)); putIfAbsent(props, "sun.os.patch.level", raw.propDefault(Raw._sun_os_patch_level_NDX)); @@ -185,8 +184,7 @@ public static class Raw { // Array indices written by native vmProperties() // The order is arbitrary (but alphabetic for convenience) - @Native private static final int _awt_toolkit_NDX = 0; - @Native private static final int _display_country_NDX = 1 + _awt_toolkit_NDX; + @Native private static final int _display_country_NDX = 0; @Native private static final int _display_language_NDX = 1 + _display_country_NDX; @Native private static final int _display_script_NDX = 1 + _display_language_NDX; @Native private static final int _display_variant_NDX = 1 + _display_script_NDX; --- old/src/java.desktop/share/classes/java/awt/Toolkit.java 2019-05-06 14:44:24.673071262 -0700 +++ new/src/java.desktop/share/classes/java/awt/Toolkit.java 2019-05-06 14:44:24.541071265 -0700 @@ -78,6 +78,7 @@ import sun.awt.AppContext; import sun.awt.HeadlessToolkit; import sun.awt.PeerEvent; +import sun.awt.PlatformGraphicsInfo; import sun.awt.SunToolkit; /** @@ -582,43 +583,17 @@ * specified. * * @return the default toolkit. - * @exception AWTError if a toolkit could not be found, or - * if one could not be accessed or instantiated. + * @throws AWTError in case of an error loading assistive technologies. * @see java.util.ServiceLoader * @see javax.accessibility.AccessibilityProvider */ public static synchronized Toolkit getDefaultToolkit() { if (toolkit == null) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - Class cls = null; - String nm = System.getProperty("awt.toolkit"); - try { - cls = Class.forName(nm); - } catch (ClassNotFoundException e) { - ClassLoader cl = ClassLoader.getSystemClassLoader(); - if (cl != null) { - try { - cls = cl.loadClass(nm); - } catch (final ClassNotFoundException ignored) { - throw new AWTError("Toolkit not found: " + nm); - } - } - } - try { - if (cls != null) { - toolkit = (Toolkit)cls.getConstructor().newInstance(); - if (GraphicsEnvironment.isHeadless()) { - toolkit = new HeadlessToolkit(toolkit); - } - } - } catch (final ReflectiveOperationException ignored) { - throw new AWTError("Could not create Toolkit: " + nm); - } - return null; - } - }); + toolkit = PlatformGraphicsInfo.createToolkit(); + if (GraphicsEnvironment.isHeadless() && + !(toolkit instanceof HeadlessToolkit)) { + toolkit = new HeadlessToolkit(toolkit); + } if (!GraphicsEnvironment.isHeadless()) { loadAssistiveTechnologies(); } --- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java 2019-05-06 14:44:25.049071256 -0700 +++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java 2019-05-06 14:44:24.913071258 -0700 @@ -190,10 +190,16 @@ private static final boolean inAWT; public LWCToolkit() { - areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true")); - //set system property if not yet assigned - System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); - initAppkit(ThreadGroupUtils.getRootThreadGroup(), GraphicsEnvironment.isHeadless()); + final String extraButtons = "sun.awt.enableExtraMouseButtons"; + AccessController.doPrivileged((PrivilegedAction) () -> { + areExtraMouseButtonsEnabled = + Boolean.parseBoolean(System.getProperty(extraButtons, "true")); + //set system property if not yet assigned + System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled); + initAppkit(ThreadGroupUtils.getRootThreadGroup(), + GraphicsEnvironment.isHeadless()); + return null; + }); } /* --- old/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java 2019-05-06 14:44:25.421071250 -0700 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java 2019-05-06 14:44:25.285071252 -0700 @@ -346,10 +346,14 @@ arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(), XCursorFontConstants.XC_arrow); - areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true")); - //set system property if not yet assigned - System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); - + final String extraButtons = "sun.awt.enableExtraMouseButtons"; + AccessController.doPrivileged((PrivilegedAction) () -> { + areExtraMouseButtonsEnabled = + Boolean.parseBoolean(System.getProperty(extraButtons, "true")); + //set system property if not yet assigned + System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled); + return null; + }); // Detect display mode changes XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask); XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() { --- old/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java 2019-05-06 14:44:25.813071244 -0700 +++ new/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java 2019-05-06 14:44:25.689071246 -0700 @@ -245,10 +245,13 @@ ThreadGroup rootTG = AccessController.doPrivileged( (PrivilegedAction) ThreadGroupUtils::getRootThreadGroup); if (!startToolkitThread(this, rootTG)) { - String name = "AWT-Windows"; - Thread toolkitThread = new Thread(rootTG, this, name, 0, false); - toolkitThread.setDaemon(true); - toolkitThread.start(); + final String name = "AWT-Windows"; + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread toolkitThread = new Thread(rootTG, this, name, 0, false); + toolkitThread.setDaemon(true); + toolkitThread.start(); + return null; + }); } try { @@ -264,10 +267,14 @@ // Enabled "live resizing" by default. It remains controlled // by the native system though. setDynamicLayout(true); - - areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true")); - //set system property if not yet assigned - System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); + final String extraButtons = "sun.awt.enableExtraMouseButtons"; + AccessController.doPrivileged((PrivilegedAction) () -> { + areExtraMouseButtonsEnabled = + Boolean.parseBoolean(System.getProperty(extraButtons, "true")); + //set system property if not yet assigned + System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled); + return null; + }); setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled); } --- old/src/java.desktop/macosx/classes/sun/awt/PlatformGraphicsInfo.java 2019-05-06 14:44:26.217071237 -0700 +++ new/src/java.desktop/macosx/classes/sun/awt/PlatformGraphicsInfo.java 2019-05-06 14:44:26.069071239 -0700 @@ -26,6 +26,7 @@ package sun.awt; import java.awt.GraphicsEnvironment; +import java.awt.Toolkit; import java.security.AccessController; import java.security.PrivilegedAction; @@ -42,6 +43,10 @@ return new CGraphicsEnvironment(); } + public static Toolkit createToolkit() { + return new sun.lwawt.macosx.LWCToolkit(); + } + /** * Returns true if the WindowServer is available, false otherwise. * --- old/src/java.desktop/unix/classes/sun/awt/PlatformGraphicsInfo.java 2019-05-06 14:44:26.597071231 -0700 +++ new/src/java.desktop/unix/classes/sun/awt/PlatformGraphicsInfo.java 2019-05-06 14:44:26.477071233 -0700 @@ -26,6 +26,7 @@ package sun.awt; import java.awt.GraphicsEnvironment; +import java.awt.Toolkit; import java.security.AccessController; import java.security.PrivilegedAction; @@ -35,6 +36,10 @@ return new X11GraphicsEnvironment(); } + public static Toolkit createToolkit() { + return new sun.awt.X11.XToolkit(); + } + /** * Called from java.awt.GraphicsEnvironment when * to check if on this platform, the JDK should default to --- old/src/java.desktop/windows/classes/sun/awt/PlatformGraphicsInfo.java 2019-05-06 14:44:26.945071225 -0700 +++ new/src/java.desktop/windows/classes/sun/awt/PlatformGraphicsInfo.java 2019-05-06 14:44:26.821071227 -0700 @@ -26,6 +26,7 @@ package sun.awt; import java.awt.GraphicsEnvironment; +import java.awt.Toolkit; public class PlatformGraphicsInfo { @@ -33,6 +34,10 @@ return new Win32GraphicsEnvironment(); } + public static Toolkit createToolkit() { + return new sun.awt.windows.WToolkit(); + } + public static boolean getDefaultHeadlessProperty() { // On Windows, we assume we can always create headful apps. // Here is where we can add code that would actually check. --- /dev/null 2019-03-20 14:24:34.066737717 -0700 +++ new/test/jdk/java/awt/Toolkit/ToolkitPropertyTest/CheckToolkitSystemProperty.java 2019-05-06 14:44:27.157071222 -0700 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8212700 + * @summary verify the AWT Toolkit implementation class name is not + * polluting system properties + */ + +public class CheckToolkitSystemProperty { + + public static void main(String[] args) { + String tkProp = System.getProperty("awt.toolkit"); + if (tkProp != null) { + throw new RuntimeException("tkProp = " + tkProp); + } + } +}