United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7181027 [macosx] Unable to use headless mode
JDK-7181027 : [macosx] Unable to use headless mode

Details
Type:
Bug
Submit Date:
2012-07-02
Status:
Closed
Updated Date:
2012-08-14
Project Name:
JDK
Resolved Date:
2012-08-03
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u6 (b22)

Related Reports
Backport:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Darwin dhcp-36.trollworks.com 11.4.2 Darwin Kernel Version 11.4.2: Wed May 30 20:13:51 PDT 2012; root:xnu-1699.31.2~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
This is effectively a duplicate of bug 7144064. However, that bug was marked as fixed in 7u4, which doesn't seem to be the case. My particular situation can be demonstrated with the following:

1) Connect to an OSX machine via ssh. DISPLAY is not set.

2) try the following code:

import java.awt.*;
import java.awt.image.*;

public class Test {
    public static final void main(String[] args) {
        System.setProperty("java.awt.headless", Boolean.TRUE.toString());
        BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
        Graphics graphics = img.getGraphics();
    }
}

3) get the following exception:

Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
	at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
	at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
	at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
	at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
	at Test.main(Test.java:9)

Please note that the same code runs without an exception when executed locally (i.e. no ssh).

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Connect to an OSX machine via ssh. DISPLAY is not set.

2) try the following code:

import java.awt.*;
import java.awt.image.*;

public class Test {
    public static final void main(String[] args) {
        System.setProperty("java.awt.headless", Boolean.TRUE.toString());
        BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
        Graphics graphics = img.getGraphics();
    }
}

3) get the following exception:

Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
	at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
	at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
	at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
	at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
	at Test.main(Test.java:9)

Please note that the same code runs without an exception when executed locally (i.e. no ssh).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception thrown.
ACTUAL -
Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
	at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
	at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
	at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
	at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
	at Test.main(Test.java:9)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
	at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
	at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
	at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
	at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
	at Test.main(Test.java:9)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.image.*;

public class Test {
    public static final void main(String[] args) {
        System.setProperty("java.awt.headless", Boolean.TRUE.toString());
        BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
        Graphics graphics = img.getGraphics();
    }
}

---------- END SOURCE ----------

                                    

Comments
EVALUATION

The problem here is that for headless mode "java.awt.graphicsenv" system property should be CGraphicsEnvironment because the way GraphicsEnvironment.createGE() method works: it first instantiates GraphicsEnvironment instance and then wraps it with HeadlessGraphicsEnvironment if in headless mode.
                                     
2012-07-11
EVALUATION

http://hg.openjdk.java.net/hsx/hotspot-comp/jdk/rev/b1c5e4a843f3
                                     
2012-08-14



Hardware and Software, Engineered to Work Together