Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6189824

REGRESSION: HeadlessException in JComponent.paint() when java.awt.headless=true

    Details

    • Subcomponent:
    • Resolved In Build:
      b46
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_8, solaris_9

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                svioletsunw Scott Violet (Inactive)
                Reporter:
                jleesunw Jon Lee (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: