United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7144064 [macosx] "Could not find class" error in JTree's ctor when called in headless mode
JDK-7144064 : [macosx] "Could not find class" error in JTree's ctor when called in headless mode

Details
Type:
Bug
Submit Date:
2012-02-09
Status:
Closed
Updated Date:
2012-10-01
Project Name:
JDK
Resolved Date:
2012-03-14
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
7,7u4
Fixed Versions:
7u4 (b13)

Related Reports
Backport:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
Here is a very simple test which throws error on Mac:

import java.awt.Toolkit;
import javax.swing.JTree;

public final class JTreeTest {
    public static void main(final String... args) {
        System.setProperty("java.awt.headless", "true");
        System.out.println(Toolkit.getDefaultToolkit());
        final JTree tree = new JTree();
        System.out.println(tree.getPreferredSize());
    }
}

The error is:
Exception in thread "main" java.lang.Error: Could not find class: sun.awt.HeadlessGraphicsEnvironment
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:116)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at sun.swing.SwingUtilities2.isLocalDisplay(SwingUtilities2.java:1457)
        at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1556)
        at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:148)
        at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1592)
        at javax.swing.UIManager.setLookAndFeel(UIManager.java:535)
        at javax.swing.UIManager.setLookAndFeel(UIManager.java:575)
        at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1343)
        at javax.swing.UIManager.initialize(UIManager.java:1432)
        at javax.swing.UIManager.maybeInitialize(UIManager.java:1420)
        at javax.swing.UIManager.getUI(UIManager.java:1002)
        at javax.swing.JTree.updateUI(JTree.java:714)
        at javax.swing.JTree.<init>(JTree.java:667)
        at javax.swing.JTree.<init>(JTree.java:564)
        at JTreeTest.main(JTreeTest.java:8)
Version of jdk:
java version "1.7.0_04-ea"
Java(TM) SE Runtime Environment (build 1.7.0_04-ea-b227)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b12, mixed mode)

                                    

Comments
EVALUATION

In src/solaris/native/java/lang/java_props_md.c:

#ifdef MACOSX
            break;
        default:
            sprops.graphics_env = "sun.awt.HeadlessGraphicsEnvironment";
            break;
    }
#endif

This is obviously wrong as HeadlessGraphicsEnvironment is in the sun.java2d package.
                                     
2012-02-09



Hardware and Software, Engineered to Work Together