changeset 10714:e0ef653b2225

7077826: Unset and empty DISPLAY variable is handled differently by JDK Reviewed-by: azvegint, ant
author serb
date Tue, 16 Dec 2014 20:23:46 +0300
parents f7096aae3a2a
children 05a4f138a4b2
files src/share/classes/java/awt/GraphicsEnvironment.java test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh
diffstat 3 files changed, 47 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/GraphicsEnvironment.java	Tue Jan 13 16:06:28 2015 +0300
+++ b/src/share/classes/java/awt/GraphicsEnvironment.java	Tue Dec 16 20:23:46 2014 +0300
@@ -28,6 +28,7 @@
 
 import java.awt.image.BufferedImage;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Locale;
 
 import sun.font.FontManager;
@@ -160,43 +161,38 @@
      */
     private static boolean getHeadlessProperty() {
         if (headless == null) {
-            java.security.AccessController.doPrivileged(
-            new java.security.PrivilegedAction<Object>() {
-                public Object run() {
-                    String nm = System.getProperty("java.awt.headless");
+            AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                String nm = System.getProperty("java.awt.headless");
 
-                    if (nm == null) {
-                        /* No need to ask for DISPLAY when run in a browser */
-                        if (System.getProperty("javaplugin.version") != null) {
-                            headless = defaultHeadless = Boolean.FALSE;
+                if (nm == null) {
+                    /* No need to ask for DISPLAY when run in a browser */
+                    if (System.getProperty("javaplugin.version") != null) {
+                        headless = defaultHeadless = Boolean.FALSE;
+                    } else {
+                        String osName = System.getProperty("os.name");
+                        if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
+                                System.getProperty("awt.toolkit")))
+                        {
+                            headless = defaultHeadless = Boolean.TRUE;
                         } else {
-                            String osName = System.getProperty("os.name");
-                            if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
-                                    System.getProperty("awt.toolkit")))
-                            {
-                                headless = defaultHeadless = Boolean.TRUE;
-                            } else {
-                                headless = defaultHeadless =
-                                    Boolean.valueOf(("Linux".equals(osName) ||
-                                                     "SunOS".equals(osName) ||
-                                                     "FreeBSD".equals(osName) ||
-                                                     "NetBSD".equals(osName) ||
-                                                     "OpenBSD".equals(osName) ||
-                                                     "AIX".equals(osName)) &&
-                                                     (System.getenv("DISPLAY") == null));
-                            }
+                            final String display = System.getenv("DISPLAY");
+                            headless = defaultHeadless =
+                                ("Linux".equals(osName) ||
+                                 "SunOS".equals(osName) ||
+                                 "FreeBSD".equals(osName) ||
+                                 "NetBSD".equals(osName) ||
+                                 "OpenBSD".equals(osName) ||
+                                 "AIX".equals(osName)) &&
+                                 (display == null || display.trim().isEmpty());
                         }
-                    } else if (nm.equals("true")) {
-                        headless = Boolean.TRUE;
-                    } else {
-                        headless = Boolean.FALSE;
                     }
-                    return null;
+                } else {
+                    headless = Boolean.valueOf(nm);
                 }
-                }
-            );
+                return null;
+            });
         }
-        return headless.booleanValue();
+        return headless;
     }
 
     /**
--- a/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh	Tue Jan 13 16:06:28 2015 +0300
+++ b/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh	Tue Dec 16 20:23:46 2014 +0300
@@ -28,7 +28,7 @@
 #
 
 # @test
-# @bug 8058930
+# @bug 8058930 7077826
 # @summary java.awt.GraphicsEnvironment.getHeadlessProperty() does not work for AIX
 #
 # @build TestDetectHeadless
@@ -36,7 +36,7 @@
 
 OS=`uname -s`
 case "$OS" in
-    Windows* | CYGWIN* )
+    Windows* | CYGWIN* | Darwin)
         echo "Passed"; exit 0 ;;
     * ) unset DISPLAY ;;
 esac
@@ -44,4 +44,14 @@
 ${TESTJAVA}/bin/java ${TESTVMOPTS} \
     -cp ${TESTCLASSES} TestDetectHeadless
 
+if [ $? -ne 0 ]; then
+	exit 1;
+fi
+
+DISPLAY=
+export DISPLAY
+
+${TESTJAVA}/bin/java ${TESTVMOPTS} \
+    -cp ${TESTCLASSES} TestDetectHeadless
+
 exit $?
--- a/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh	Tue Jan 13 16:06:28 2015 +0300
+++ b/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh	Tue Dec 16 20:23:46 2014 +0300
@@ -1,4 +1,4 @@
-# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2014, 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
@@ -21,23 +21,15 @@
 
 ${TESTJAVA}/bin/javac -cp ${TESTSRC} -d . ${TESTSRC}/BadDisplayTest.java
 
+OS=`uname -s`
+case "$OS" in
+    Windows* | CYGWIN* | Darwin)
+        echo "Passed"; exit 0 ;;
+esac
 
-DISPLAY=
+DISPLAY=SomeBadDisplay
 export DISPLAY
 
-OS=`uname -s`
-case "$OS" in
-  SunOS )
-    ${TESTJAVA}/bin/java BadDisplayTest
-    ;;
-  Linux )
-    ${TESTJAVA}/bin/java BadDisplayTest
-     ;;
-  * )
-    echo "Unsupported System: ${OS}"
-    exit 0;
-    ;;
-esac
+${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest
 
 exit $?
-