mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-24 17:20:06 +00:00
7077826: Unset and empty DISPLAY variable is handled differently by JDK
Reviewed-by: azvegint, ant
This commit is contained in:
parent
d2295af274
commit
05705c949e
@ -28,6 +28,7 @@ package java.awt;
|
||||
|
||||
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 @@ public abstract class GraphicsEnvironment {
|
||||
*/
|
||||
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;
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
} else if (nm.equals("true")) {
|
||||
headless = Boolean.TRUE;
|
||||
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 {
|
||||
headless = Boolean.FALSE;
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
|
||||
System.getProperty("awt.toolkit")))
|
||||
{
|
||||
headless = defaultHeadless = Boolean.TRUE;
|
||||
} else {
|
||||
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());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
headless = Boolean.valueOf(nm);
|
||||
}
|
||||
}
|
||||
);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return headless.booleanValue();
|
||||
return headless;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
#
|
||||
|
||||
# @test
|
||||
# @bug 8058930
|
||||
# @bug 8058930 7077826
|
||||
# @summary java.awt.GraphicsEnvironment.getHeadlessProperty() does not work for AIX
|
||||
#
|
||||
# @build TestDetectHeadless
|
||||
@ -36,11 +36,21 @@
|
||||
|
||||
OS=`uname -s`
|
||||
case "$OS" in
|
||||
Windows* | CYGWIN* )
|
||||
Windows* | CYGWIN* | Darwin)
|
||||
echo "Passed"; exit 0 ;;
|
||||
* ) unset DISPLAY ;;
|
||||
esac
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} \
|
||||
-cp ${TESTCLASSES} TestDetectHeadless
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
DISPLAY=
|
||||
export DISPLAY
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} \
|
||||
-cp ${TESTCLASSES} TestDetectHeadless
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
exit $?
|
||||
DISPLAY=SomeBadDisplay
|
||||
export DISPLAY
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest
|
||||
|
||||
exit $?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user