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

[macosx] Unable to use headless mode

XMLWordPrintable

    • b22
    • x86
    • os_x
    • Verified

        FULL PRODUCT VERSION :
        java version "1.7.0_05"
        Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
        Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Darwin dhcp-36.trollworks.com 11.4.2 Darwin Kernel Version 11.4.2: Wed May 30 20:13:51 PDT 2012; root:xnu-1699.31.2~1/RELEASE_X86_64 x86_64

        A DESCRIPTION OF THE PROBLEM :
        This is effectively a duplicate of bug 7144064. However, that bug was marked as fixed in 7u4, which doesn't seem to be the case. My particular situation can be demonstrated with the following:

        1) Connect to an OSX machine via ssh. DISPLAY is not set.

        2) try the following code:

        import java.awt.*;
        import java.awt.image.*;

        public class Test {
            public static final void main(String[] args) {
                System.setProperty("java.awt.headless", Boolean.TRUE.toString());
                BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
                Graphics graphics = img.getGraphics();
            }
        }

        3) get the following exception:

        Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
        at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
        at Test.main(Test.java:9)

        Please note that the same code runs without an exception when executed locally (i.e. no ssh).

        REGRESSION. Last worked in version 6u31

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1) Connect to an OSX machine via ssh. DISPLAY is not set.

        2) try the following code:

        import java.awt.*;
        import java.awt.image.*;

        public class Test {
            public static final void main(String[] args) {
                System.setProperty("java.awt.headless", Boolean.TRUE.toString());
                BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
                Graphics graphics = img.getGraphics();
            }
        }

        3) get the following exception:

        Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
        at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
        at Test.main(Test.java:9)

        Please note that the same code runs without an exception when executed locally (i.e. no ssh).

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No exception thrown.
        ACTUAL -
        Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
        at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
        at Test.main(Test.java:9)

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" java.lang.Error: Could not instantiate Graphics Environment: sun.java2d.HeadlessGraphicsEnvironment
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:118)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1152)
        at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1142)
        at Test.main(Test.java:9)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import java.awt.image.*;

        public class Test {
            public static final void main(String[] args) {
                System.setProperty("java.awt.headless", Boolean.TRUE.toString());
                BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
                Graphics graphics = img.getGraphics();
            }
        }

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

              leonidr Leonid Romanov (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: