On 8 apr 2014, at 22:10, shanliang <shanliang.ji...@oracle.com> wrote:

> Hi Staffan,
> 
> I did work on this bug and I thought the problem was from a bad DISPLAY 
> setting (see my comments in the bug), I might miss something here.
> 
> I looked at the class GraphicsEnvironment.java, getLocalGraphicsEnvironment() 
> calls createGE(), and the latter has the following code:
> 
>           Class<GraphicsEnvironment> geCls;
>            ......
>           ge = geCls.newInstance();
> //          long t1 = System.currentTimeMillis();
> //          System.out.println("GE creation took " + (t1-t0)+ "ms.");
>           if (isHeadless()) {
>               ge = new HeadlessGraphicsEnvironment(ge);
>           }
> 
> so we should not get an AWTError in case of headless, instead we get a 
> HeadlessGraphicsEnvironment.

If you look at the exception you can see that it is Class.forName() inside 
createGE() that throws the AWTError. We never get to the if(isHeadless()) 
statement.

/Staffan

> 
> Look at the following 2 methods:
> 
>   public static boolean isHeadless() {
>       return getHeadlessProperty();
>   }
> 
>   public boolean isHeadlessInstance() {
>       // By default (local graphics environment), simply check the
>       // headless property.
>       return getHeadlessProperty();
>   }
> 
> it seems no difference to call
>   GraphicsEnvironment.getLocalGraphicsEnvironement().isHeadlessInstance()
> and
>   GraphicsEnvironment.isHeadless()   
> yes better to cal the static method, but I am not sure that the direct call 
> would fix the failure.
> 
> Thanks,
> Shanliang
> 
> 
> Staffan Larsen wrote:
>> This test causes exceptions that looks like this:
>> 
>> java.awt.AWTError: Can't connect to X11 window server using ‘REDACTED:503' 
>> as the value of the DISPLAY variable.
>>      at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
>>      at 
>> sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
>>      at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
>>      at java.security.AccessController.doPrivileged(Native Method)
>>      at 
>> sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
>>      at java.lang.Class.forName0(Native Method)
>>      at java.lang.Class.forName(Class.java:259)
>>      at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
>>      at 
>> java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
>>      at TraceJFrame.main(TraceJFrame.java:39)
>>      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>      at 
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>      at 
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>      at java.lang.reflect.Method.invoke(Method.java:484)
>>      at 
>> com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:754)
>>      at java.lang.Thread.run(Thread.java:744)
>> 
>> 
>> The fix seems to be to not call 
>> GraphicsEnvironment.getLocalGraphicsEnvironement().isHeadlessInstance() but 
>> GraphicsEnvironment.isHeadless() directly.
>> 
>> Please review the fix below,
>> 
>> Thanks,
>> /Staffan
>> 
>> 
>> 
>> diff --git a/test/demo/jvmti/mtrace/TraceJFrame.java 
>> b/test/demo/jvmti/mtrace/TraceJFrame.java
>> --- a/test/demo/jvmti/mtrace/TraceJFrame.java
>> +++ b/test/demo/jvmti/mtrace/TraceJFrame.java
>> @@ -36,7 +36,7 @@
>> 
>> public class TraceJFrame {
>>     public static void main(String args[]) throws Exception {
>> -        if 
>> (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
>> +        if (GraphicsEnvironment.isHeadless()) {
>>             System.out.println("JFrame test was skipped due to headless 
>> mode");
>>         } else {
>>             DemoRun demo;
> 

Reply via email to