--- old/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java 2014-12-07 17:16:16.000000000 +0300 +++ new/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java 2014-12-07 17:16:16.000000000 +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() { - public Object run() { - 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; + AccessController.doPrivileged((PrivilegedAction) () -> { + 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 { - 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.isEmpty()); } - } else if (nm.equals("true")) { - headless = Boolean.TRUE; - } else { - headless = Boolean.FALSE; } - return null; - } + } else { + headless = "true".equals(nm); } - ); + return null; + }); } - return headless.booleanValue(); + return headless; } /** --- old/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh 2014-12-07 17:16:17.000000000 +0300 +++ new/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh 2014-12-07 17:16:17.000000000 +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 $? --- old/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh 2014-12-07 17:16:18.000000000 +0300 +++ new/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh 2014-12-07 17:16:17.000000000 +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 -exit $? +DISPLAY=SomeBadDisplay +export DISPLAY + +${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest +exit $?