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

'new StyleSheet()' fails for headless applications

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • tools
    • x86
    • linux



      Name: gm110360 Date: 04/15/2004


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


      FULL OS VERSION :
      Linux credence.dstc.edu.au 2.4.18-27.8.0 #1 Fri Mar 14 06:45:49 EST 2003 i686 i686 i386 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      DISPLAY unset, or set to an inaccessible X server

      A DESCRIPTION OF THE PROBLEM :
      We have some applications that extract metadata from HTML documents, using
      javax.swing.text.html.HTMDocument and associated parsers. In order to instantiate an HTMLDocument, we must supply it with a StyleSheet object. Instantiating a StyleSheet fails when there is no accessible X server (on Linux); e.g. when
      our applications are run from a 'cron' job, or on a headless server.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the following program with the DISPLAY environment variable
      either unset or set to the name of a non-existent X server.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Nothing
      ACTUAL -
      Stack trace

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
              at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
              at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:141)
              at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
              at sun.awt.motif.MToolkit.<clinit>(MToolkit.java:81)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:141)
              at java.awt.Toolkit$2.run(Toolkit.java:748)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:739)
              at java.awt.Toolkit.getEventQueue(Toolkit.java:1519)
              at java.awt.EventQueue.isDispatchThread(EventQueue.java:651)
              at javax.swing.SwingUtilities.isEventDispatchThread(SwingUtilities.java:1238)
              at javax.swing.text.StyleContext.reclaim(StyleContext.java:419)
              at javax.swing.text.StyleContext.addAttribute(StyleContext.java:276)
              at javax.swing.text.html.StyleSheet.addAttribute(StyleSheet.java:538)
              at javax.swing.text.StyleContext$NamedStyle.addAttribute(StyleContext.java:1468)
              at javax.swing.text.StyleContext$NamedStyle.setName(StyleContext.java:1278)
              at javax.swing.text.StyleContext$NamedStyle.<init>(StyleContext.java:1226)
              at javax.swing.text.StyleContext.addStyle(StyleContext.java:88)
              at javax.swing.text.StyleContext.<init>(StyleContext.java:68)
              at javax.swing.text.html.StyleSheet.<init>(StyleSheet.java:147)
              at foo.main(foo.java:5)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.text.html.*;
      public class foo
      {
        public static void main(String[] args) {
          new StyleSheet();
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Supplying the argument "-Djava.awt.headless=true" when running the application
      avoids the problem.

      If this bug is closed as "will not fix" or "not a bug", a documentation bug
      should be opened against the javadoc for StyleSheet (etcetera) to note this
      workaround.
      (Incident Review ID: 198615)
      ======================================================================

            mr Mark Reinhold
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: