8212701: remove sun.desktop property from launcher code
authorprr
Wed, 24 Apr 2019 09:21:02 -0700
changeset 54858 bbc7c176c168
parent 54857 1353a7ca8a37
child 54859 360c0955b06b
8212701: remove sun.desktop property from launcher code Reviewed-by: serb, alanb, rriggs
src/demo/share/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java
src/java.base/share/classes/jdk/internal/util/SystemProps.java
src/java.base/share/native/libjava/System.c
src/java.base/share/native/libjava/java_props.h
src/java.base/unix/native/libjava/java_props_md.c
src/java.base/windows/native/libjava/java_props_md.c
src/java.desktop/share/classes/javax/swing/UIManager.java
src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java
src/java.desktop/share/classes/sun/awt/SunToolkit.java
src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java
test/jdk/java/awt/Toolkit/SunDesktopProperty/CheckSunDesktopProperty.java
--- a/src/demo/share/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/demo/share/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java	Wed Apr 24 09:21:02 2019 -0700
@@ -1223,8 +1223,6 @@
                       sysProps.get("os.version") + "</td></tr>");
         buffer.append("<tr><td bgcolor=\"#f0f0f0\">os.arch</td><td>" +
                       sysProps.get("os.arch") + "</td></tr>");
-        buffer.append("<tr><td bgcolor=\"#f0f0f0\">sun.desktop</td><td>" +
-                      sysProps.get("sun.desktop") + "</td></tr>");
 
         buffer.append("</table>");
 
--- a/src/java.base/share/classes/jdk/internal/util/SystemProps.java	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.base/share/classes/jdk/internal/util/SystemProps.java	Wed Apr 24 09:21:02 2019 -0700
@@ -93,7 +93,6 @@
         putIfAbsent(props, "awt.toolkit", raw.propDefault(Raw._awt_toolkit_NDX));
         putIfAbsent(props, "java.awt.headless", raw.propDefault(Raw._java_awt_headless_NDX));
         putIfAbsent(props, "java.awt.graphicsenv", raw.propDefault(Raw._java_awt_graphicsenv_NDX));
-        putIfAbsent(props, "sun.desktop", raw.propDefault(Raw._sun_desktop_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));
@@ -222,8 +221,7 @@
         @Native private static final int _sun_arch_data_model_NDX = 1 + _sun_arch_abi_NDX;
         @Native private static final int _sun_cpu_endian_NDX = 1 + _sun_arch_data_model_NDX;
         @Native private static final int _sun_cpu_isalist_NDX = 1 + _sun_cpu_endian_NDX;
-        @Native private static final int _sun_desktop_NDX = 1 + _sun_cpu_isalist_NDX;
-        @Native private static final int _sun_io_unicode_encoding_NDX = 1 + _sun_desktop_NDX;
+        @Native private static final int _sun_io_unicode_encoding_NDX = 1 + _sun_cpu_isalist_NDX;
         @Native private static final int _sun_jnu_encoding_NDX = 1 + _sun_io_unicode_encoding_NDX;
         @Native private static final int _sun_os_patch_level_NDX = 1 + _sun_jnu_encoding_NDX;
         @Native private static final int _sun_stderr_encoding_NDX = 1 + _sun_os_patch_level_NDX;
--- a/src/java.base/share/native/libjava/System.c	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.base/share/native/libjava/System.c	Wed Apr 24 09:21:02 2019 -0700
@@ -221,11 +221,6 @@
      */
     PUTPROP(propArray, _java_awt_graphicsenv_NDX, sprops->graphics_env);
 
-    /*
-     * The sun.desktop property is currently only set for Gnome and Windows desktops.
-     */
-    PUTPROP(propArray, _sun_desktop_NDX, sprops->desktop);
-
     PUTPROP_PlatformString(propArray, _java_io_tmpdir_NDX, sprops->tmp_dir);
 
     PUTPROP_PlatformString(propArray, _user_name_NDX, sprops->user_name);
--- a/src/java.base/share/native/libjava/java_props.h	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.base/share/native/libjava/java_props.h	Wed Apr 24 09:21:02 2019 -0700
@@ -82,8 +82,6 @@
 
     char *patch_level;          /* patches/service packs installed */
 
-    char *desktop;              /* Desktop name. */
-
 #ifdef MACOSX
     // These are for proxy-related information.
     // Note that if these platform-specific extensions get out of hand we should make a new
--- a/src/java.base/unix/native/libjava/java_props_md.c	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.base/unix/native/libjava/java_props_md.c	Wed Apr 24 09:21:02 2019 -0700
@@ -452,13 +452,6 @@
 #endif /* MACOSX */
 
         sprops.os_arch = ARCHPROPNAME;
-
-        if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) {
-            sprops.desktop = "gnome";
-        }
-        else {
-            sprops.desktop = NULL;
-        }
     }
 
     /* ABI property (optional) */
--- a/src/java.base/windows/native/libjava/java_props_md.c	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.base/windows/native/libjava/java_props_md.c	Wed Apr 24 09:21:02 2019 -0700
@@ -577,7 +577,6 @@
 #else
         sprops.os_arch = "unknown";
 #endif
-        sprops.desktop = "windows";
     }
 
     /* Endianness of platform */
--- a/src/java.desktop/share/classes/javax/swing/UIManager.java	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.desktop/share/classes/javax/swing/UIManager.java	Wed Apr 24 09:21:02 2019 -0700
@@ -657,13 +657,14 @@
         if (osType == OSInfo.OSType.WINDOWS) {
             return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
         } else {
-            String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
             Toolkit toolkit = Toolkit.getDefaultToolkit();
-            if ("gnome".equals(desktop) &&
-                    toolkit instanceof SunToolkit &&
-                    ((SunToolkit) toolkit).isNativeGTKAvailable()) {
-                // May be set on Linux and Solaris boxs.
-                return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
+            if (toolkit instanceof SunToolkit) {
+                SunToolkit suntk = (SunToolkit)toolkit;
+                String desktop = suntk.getDesktop();
+                boolean gtkAvailable = suntk.isNativeGTKAvailable();
+                if ("gnome".equals(desktop) && gtkAvailable) {
+                    return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
+                }
             }
             if (osType == OSInfo.OSType.MACOSX) {
                 if (toolkit.getClass() .getName()
--- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java	Wed Apr 24 09:21:02 2019 -0700
@@ -803,8 +803,9 @@
      */
     private static boolean useLAFConditions() {
         String language = Locale.getDefault().getLanguage();
+        Toolkit tk = Toolkit.getDefaultToolkit();
         String desktop =
-            AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
+            (tk instanceof SunToolkit) ? ((SunToolkit)tk).getDesktop() : null;
 
         boolean isCjkLocale = (Locale.CHINESE.getLanguage().equals(language) ||
                 Locale.JAPANESE.getLanguage().equals(language) ||
--- a/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Wed Apr 24 09:21:02 2019 -0700
@@ -1823,6 +1823,10 @@
         return sunAwtDisableMixing.booleanValue();
     }
 
+    public String getDesktop() {
+        return null;
+    }
+
     /**
      * Returns true if the native GTK libraries are available.  The
      * default implementation returns false, but UNIXToolkit overrides this
--- a/src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java	Tue Apr 23 14:22:34 2019 +0530
+++ b/src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java	Wed Apr 24 09:21:02 2019 -0700
@@ -93,6 +93,14 @@
         }
     }
 
+    @Override
+    public String getDesktop() {
+        String gsi = AccessController.doPrivileged(
+                        (PrivilegedAction<String>) ()
+                                -> System.getenv("GNOME_SESSION_ID"));
+        return (gsi != null) ? "gnome" : null;
+    }
+
     /**
      * Returns true if the native GTK libraries are capable of being
      * loaded and are expected to work properly, false otherwise.  Note
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/awt/Toolkit/SunDesktopProperty/CheckSunDesktopProperty.java	Wed Apr 24 09:21:02 2019 -0700
@@ -0,0 +1,38 @@
+/*
+ * 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 8212701
+  @summary verify sun.desktop system property is not set by default.
+*/
+
+public class CheckSunDesktopProperty {
+
+     public static void main(String[] args) {
+         String pjProp = System.getProperty("sun.desktop");
+         if (pjProp != null) {
+             throw new RuntimeException("pjProp = " + pjProp);
+         }
+     }
+}