JDK-5004298 : Running in Headless mode still produces Headless exception with GTK UI
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8.0pe,1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,solaris_9
  • CPU: x86
  • Submitted: 2004-02-26
  • Updated: 2010-07-09
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b03Fixed
Description
Name: rmT116609			Date: 02/26/2004


FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.20-gentoo-r6

EXTRA RELEVANT SYSTEM CONFIGURATION :
Console only - X has been turned off.

A DESCRIPTION OF THE PROBLEM :
The server is running Java in headless mode, ie,  -Djava.awt.headless=true

Using a JPanel in our image conversion tool attempts to use the GTK look and feel.  Pango then attempts to call sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(...), which throws a Headless exception.

This should not be the case since the headless=true option was on the command line.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Get a linux server.

Compile the test  case below.

%java -Djava.awt.headless=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel Test

I have a properties file which stipulates that the GTK look and feel should be used for all java apps, and this is why the original command would not work for me.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For the application to terminate normally.
ACTUAL -
ExceptionInInitializerError is thrown.

See the below stack trace.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.ExceptionInInitializerError
     at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.handleParsedData(GTKLookAndFeel.java:353)
     at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.access$100(GTKLookAndFeel.java:23)
     at com.sun.java.swing.plaf.gtk.GTKLookAndFeel$1.run(GTKLookAndFeel.java:270)
     at java.security.AccessController.doPrivileged(Native Method)
     at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.loadStylesFromThemeFiles(GTKLookAndFeel.java:205)
     at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.initialize(GTKLookAndFeel.java:181)
     at javax.swing.UIManager.setLookAndFeel(UIManager.java:393)
     at javax.swing.UIManager.setLookAndFeel(UIManager.java:424)
     at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1085)
     at javax.swing.UIManager.initialize(UIManager.java:1181)
     at javax.swing.UIManager.maybeInitialize(UIManager.java:1164)
     at javax.swing.UIManager.getUI(UIManager.java:775)
     at javax.swing.JPanel.updateUI(JPanel.java:104)
     at javax.swing.JPanel.<init>(JPanel.java:64)
     at javax.swing.JPanel.<init>(JPanel.java:87)
     at javax.swing.JPanel.<init>(JPanel.java:95)
     at Test.main(Test.java:8)
Caused by: java.awt.HeadlessException
     at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:66)
     at com.sun.java.swing.plaf.gtk.PangoFonts.<clinit>(PangoFonts.java:36)
     ... 17 more

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import javax.swing.JPanel;

public class Test
{
    public static void main(String[] args)
    {
        JPanel p = new JPanel();
    }
}


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

CUSTOMER SUBMITTED WORKAROUND :
Don't use a JPanel, or run with X turned on!!
(Incident Review ID: 239279) 
======================================================================
###@###.### 11/3/04 18:34 GMT

Comments
EVALUATION Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=11673&forumID=1463
27-02-2006

EVALUATION Name: omR10226 Date: 03/02/2004 Not reproducible with 1.5.0-beta-b32. ====================================================================== ###@###.### 11/3/04 18:34 GMT
03-11-0004