JDK-6189824 : REGRESSION: HeadlessException in JComponent.paint() when java.awt.headless=true
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2_08,5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_8,solaris_9
  • CPU: generic,x86,sparc
  • Submitted: 2004-11-03
  • Updated: 2012-03-23
  • Resolved: 2005-08-03
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 6
6 b46Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

And "1.4.2_06-b03"

ADDITIONAL OS VERSION INFORMATION :
SunOS SUNSVR6.americas.cpqcorp.net 5.9 Generic_112233-10 sun4u sparc SUNW,Sun-Fire-V440

Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Running with the -Djava.awt.headless=true, I try to call JComponent.setBounds(), the headless exception occurs during JComponent.paint().

I have tested with jdk1.4.1_05 and it works fine, but version 1.4.2_06 and 1.5.0 both throw the HeadlessException.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. javac Headless.java
2. java -Djava.awt.headless=true Headless


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Paint worked ... ok

ACTUAL -
java.awt.HeadlessException
        at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(Headles
sGraphicsEnvironment.java:65)
        at javax.swing.RepaintManager.getVolatileOffscreenBuffer(RepaintManager.
java:583)
        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4869)
        at javax.swing.JComponent.paint(JComponent.java:993)
        at Headless.main(Headless.java:27)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class Headless {
    public static void main( String[] args ) {
        BufferedImage img;
        try {
            img = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB );

            Graphics2D graphics = img.createGraphics();

            graphics.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON );
            graphics.setColor( Color.white );
            graphics.fillRect( 0, 0, 600, 400 );

            JComponent comp = new JPanel();

            comp.setBounds( 0, 0, 600, 400 );

            // Un-comment the following line to allow it work on jdk1.4.2
            // and jdk1.5.0
            //comp.setDoubleBuffered(  false );
            comp.paint( graphics );
            System.out.println( "Paint worked ... ok" );
        }
        catch ( Exception e ) {
            e.printStackTrace();
            System.exit( 1 );
        }
        System.exit( 0 );
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The only workaround I found is to not set -Djava.awt.headless=true and to use Xvfb.

Release Regression From : 1.4.1_05
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
###@###.### 11/3/04 00:47 GMT

Comments
WORK AROUND Call RepaintManager.currentManager(null).setDoubleBufferingEnabled(false); ###@###.### 2005-07-01 21:20:19 GMT
01-07-2005

EVALUATION Looks like a swing issue. VolatileImages shouldn't be used in a headless environment. ###@###.### 11/3/04 18:09 GMT The checks for headless have already been added, but casts in RepaintManager to SunToolkit are not valid if headless. If headless BufferStrategyPaintManager should not be used. The fix will turn off use of BufferStrategyPaintManager if headless, and all will work again. ###@###.### 2005-07-01 21:20:19 GMT
03-11-2004