7077826: Unset and empty DISPLAY variable is handled differently by JDK
Reviewed-by: azvegint, ant
--- a/jdk/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java Tue Dec 16 19:26:06 2014 +0300
+++ b/jdk/src/java.desktop/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;
@@ -161,43 +162,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/jdk/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh Tue Dec 16 19:26:06 2014 +0300
+++ b/jdk/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/jdk/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh Tue Dec 16 19:26:06 2014 +0300
+++ b/jdk/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
-
-DISPLAY=
-export DISPLAY
-
OS=`uname -s`
case "$OS" in
- SunOS )
- ${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest
- ;;
- Linux )
- ${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest
- ;;
- * )
- echo "Unsupported System: ${OS}"
- exit 0;
- ;;
+ Windows* | CYGWIN* | Darwin)
+ echo "Passed"; exit 0 ;;
esac
+DISPLAY=SomeBadDisplay
+export DISPLAY
+
+${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest
+
exit $?
-