Bug 1317 - JOGL AWT sample crashes on Java 9
Summary: JOGL AWT sample crashes on Java 9
Status: IN_PROGRESS
Alias: None
Product: Nativewindow
Classification: JogAmp
Component: core (show other bugs)
Version: 2.4.0
Hardware: pc_x86_64 windows
: P1 critical
Assignee: Sven Gothel
URL:
Depends on:
Blocks: 1363
  Show dependency treegraph
 
Reported: 2016-07-14 15:41 CEST by Stijn Debruyckere
Modified: 2019-08-20 06:59 CEST (History)
2 users (show)

See Also:
Type: DEFECT
SCM Refs:
Workaround: TRUE


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stijn Debruyckere 2016-07-14 15:41:10 CEST
The JOGL AWT sample crashes on Java 9.

To reproduce, just start the JOGL AWT sample that can be found here:
  https://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing

Environment: Windows 64-bit, Java 9 (build 9-ea+126).

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
	at jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(WindowsAWTWGLGraphicsConfigurationFactory.java:171)
	at com.jogamp.nativewindow.GraphicsConfigurationFactory.chooseGraphicsConfiguration(GraphicsConfigurationFactory.java:424)
	at com.jogamp.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1560)
	at com.jogamp.opengl.awt.GLCanvas.addNotify(GLCanvas.java:611)
	at java.awt.Container.addNotify(java.desktop@9-ea/Container.java:2795)
	at java.awt.Window.addNotify(java.desktop@9-ea/Window.java:768)
	at java.awt.Frame.addNotify(java.desktop@9-ea/Frame.java:490)
	at java.awt.Window.show(java.desktop@9-ea/Window.java:1030)
	at java.awt.Component.show(java.desktop@9-ea/Component.java:1694)
	at java.awt.Component.setVisible(java.desktop@9-ea/Component.java:1641)
	at java.awt.Window.setVisible(java.desktop@9-ea/Window.java:1013)
	at OneTriangleAWT.main(OneTriangleAWT.java:62)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:533)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Comment 1 Stijn Debruyckere 2016-07-14 15:49:56 CEST
Note that both OneTriangleAWT and OneTriangleSwingGLCanvas crash with the same error. OneTriangleSwingGLJPanel crashes as well, but that seems due to a JDK bug: 
  https://bugs.openjdk.java.net/browse/JDK-8160421
Comment 2 Julien Gouesse 2016-07-26 14:33:29 CEST
(In reply to Stijn Debruyckere from comment #1)
> Note that both OneTriangleAWT and OneTriangleSwingGLCanvas crash with the
> same error. OneTriangleSwingGLJPanel crashes as well, but that seems due to
> a JDK bug: 
>   https://bugs.openjdk.java.net/browse/JDK-8160421

Why do you think that it seems to be due to this bug?
Comment 3 Stijn Debruyckere 2016-07-27 17:05:08 CEST
For all clarity: OneTriangleAWT and OneTriangleSwingGLCanvas crashed with the ArrayIndexOutOfBoundsException mentioned in the description.

OneTriangleSwingGLJPanel crashed with a NullPointerException, the exact same one as JDK-8160421 which leads me to believe it was due to that bug ;-) The resolution is set to fixed, but the fix version still says 'team' instead of '9' so I believe it's not yet available in the EA builds.
Comment 4 Julien Gouesse 2016-07-27 20:33:04 CEST
(In reply to Stijn Debruyckere from comment #3)
> For all clarity: OneTriangleAWT and OneTriangleSwingGLCanvas crashed with
> the ArrayIndexOutOfBoundsException mentioned in the description.
> 
> OneTriangleSwingGLJPanel crashed with a NullPointerException, the exact same
> one as JDK-8160421 which leads me to believe it was due to that bug ;-) The
> resolution is set to fixed, but the fix version still says 'team' instead of
> '9' so I believe it's not yet available in the EA builds.

Ok, thanks, it's crystal clear now. Please let me know when the fix is available in a EA build.
Comment 5 Julien Gouesse 2017-04-20 15:35:45 CEST
(In reply to Stijn Debruyckere from comment #3)
> For all clarity: OneTriangleAWT and OneTriangleSwingGLCanvas crashed with
> the ArrayIndexOutOfBoundsException mentioned in the description.
> 
> OneTriangleSwingGLJPanel crashed with a NullPointerException, the exact same
> one as JDK-8160421 which leads me to believe it was due to that bug ;-) The
> resolution is set to fixed, but the fix version still says 'team' instead of
> '9' so I believe it's not yet available in the EA builds.

OneTriangleSwingGLJPanel should work now as JDK-8160421 is fixed in the latest early build. Please can you give it a try?
Comment 6 Julien Gouesse 2017-06-05 13:34:20 CEST
When I run JOGLQuad (my example from the wiki) with the build 172, I get:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
        at jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(WindowsAWTWGLGraphicsConfigurationFactory.java:171)
        at com.jogamp.nativewindow.GraphicsConfigurationFactory.chooseGraphicsConfiguration(GraphicsConfigurationFactory.java:424)
        at com.jogamp.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1560)
        at com.jogamp.opengl.awt.GLCanvas.addNotify(GLCanvas.java:611)
        at java.desktop/java.awt.Container.addNotify(Container.java:2796)
        at java.desktop/java.awt.Window.addNotify(Window.java:772)
        at java.desktop/java.awt.Frame.addNotify(Frame.java:490)
        at java.desktop/java.awt.Window.show(Window.java:1034)
        at java.desktop/java.awt.Component.show(Component.java:1669)
        at java.desktop/java.awt.Component.setVisible(Component.java:1616)
        at java.desktop/java.awt.Window.setVisible(Window.java:1017)
        at JOGLQuad.main(JOGLQuad.java:86)
Comment 7 Julien Gouesse 2017-06-05 13:38:37 CEST
I entered this:
"C:\Program Files\Java\jdk-9\bin\java.exe" --permit-illegal-access  -cp .;C:\checkout-svn\HEAD1\java\lib\jogamp-fat.jar JOGLQuad

It seems to work:
WARNING: --permit-illegal-access will be removed in the next major release
WARNING: Illegal access by com.jogamp.common.os.NativeLibrary$3 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method java.lang.ClassLoader.findLibrary(java.lang.String) (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.opengl.awt.Java2D$2 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to field sun.java2d.opengl.OGLUtilities.UNDEFINED (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.opengl.awt.Java2D$2 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to field sun.java2d.opengl.OGLUtilities.WINDOW (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.opengl.awt.Java2D$2 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to field sun.java2d.opengl.OGLUtilities.TEXTURE (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.opengl.awt.Java2D$2 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to field sun.java2d.opengl.OGLUtilities.FLIP_BACKBUFFER (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.opengl.awt.Java2D$2 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to field sun.java2d.opengl.OGLUtilities.FBOBJECT (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.nativewindow.jawt.JAWTUtil$1 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method sun.awt.SunToolkit.awtLock() (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.nativewindow.jawt.JAWTUtil$1 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method sun.awt.SunToolkit.awtUnlock() (permitted by --permit-illegal-access)
WARNING: Illegal access by com.jogamp.opengl.awt.GLCanvas$14 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method sun.awt.windows.WToolkit.disableBackgroundErase(java.awt.Canvas) (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.nativewindow.jawt.windows.Win32SunJDKReflection$1 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method sun.awt.Win32GraphicsConfig.getConfig(sun.awt.Win32GraphicsDevice,int) (permitted by --permit-illegal-access)
WARNING: Illegal access by jogamp.nativewindow.jawt.windows.Win32SunJDKReflection$1 (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method sun.awt.Win32GraphicsConfig.getVisual() (permitted by --permit-illegal-access)
WARNING: Illegal access by com.jogamp.nativewindow.awt.AppContextInfo (file:/C:/checkout-svn/HEAD1/java/lib/jogamp-fat.jar) to method sun.awt.AppContext.getAppContext() (permitted by --permit-illegal-access)

We have a workaround for sure.
Comment 8 Julien Gouesse 2017-06-05 13:39:30 CEST
It's no longer a blocker as we have a workaround.
Comment 9 Julien Gouesse 2017-06-09 11:33:13 CEST
It should help to break the encapsulation when --permit-illegal-access stops being supported in Java 1.10:
--add-exports=java.base/java.lang=ALL-UNNAMED
--add-exports=java.desktop/sun.awt=ALL-UNNAMED
--add-exports=java.desktop/sun.java2d=ALL-UNNAMED

The very first exports addition should work on the long term to remove the warning about java.lang.ClassLoader.findLibrary(java.lang.String). However, the packages in sun.awt and sun.java2d might be moved or substantially modified.

It works with Java Webstart too:
https://bugs.openjdk.java.net/browse/JDK-8172986

I need to test my suggestions. If they work, I'll lower the severity of this bug to "normal".
Comment 10 Andy Skinner 2017-09-08 16:32:05 CEST
My understanding is that the reflective access will work, but that a warning will appear.  Is that correct?

Since we use JOGL in a product used by many customers, we would see that warning as a major issue.  I'm still reading up on this, but do we know what might be done about it?

thanks
andy
Comment 11 Julien Gouesse 2017-09-08 16:59:00 CEST
(In reply to Andy Skinner from comment #10)
> My understanding is that the reflective access will work, but that a warning
> will appear.  Is that correct?
> 
> Since we use JOGL in a product used by many customers, we would see that
> warning as a major issue.  I'm still reading up on this, but do we know what
> might be done about it?
> 
> thanks
> andy

The warning appears when using the dumbest workaround based on --permit-illegal-access but the second solution shouldn't print any warning.
Comment 12 Andy Skinner 2017-09-08 17:38:09 CEST
The second solution is using the other add exports?
--add-exports=java.base/java.lang=ALL-UNNAMED
--add-exports=java.desktop/sun.awt=ALL-UNNAMED
--add-exports=java.desktop/sun.java2d=ALL-UNNAMED

That does seem to work for me, and will do for now.

thanks
andy
Comment 13 Julien Gouesse 2017-09-08 18:38:39 CEST
(In reply to Andy Skinner from comment #12)
> The second solution is using the other add exports?
> --add-exports=java.base/java.lang=ALL-UNNAMED
> --add-exports=java.desktop/sun.awt=ALL-UNNAMED
> --add-exports=java.desktop/sun.java2d=ALL-UNNAMED
> 
> That does seem to work for me, and will do for now.
> 
> thanks
> andy

Yes. Thank you for the feedback.
Comment 14 Julien Gouesse 2017-12-08 07:43:18 CET
Oops, maybe something wrong happens under Mac OS X (in jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory) but it has to be tested without mixing JOGL 2 with JOGL 1:
http://forum.jogamp.org/Jogl-Jogamp-on-Java-9-tp4038012p4038383.html
Comment 15 Andy Skinner 2018-04-20 18:16:47 CEST
What is the plan for this in the longer term?

I am told that in Java 10, the suppressed warnings will become errors.

thanks
andy
Comment 16 Julien Gouesse 2018-04-27 14:53:36 CEST
(In reply to Andy Skinner from comment #15)
> What is the plan for this in the longer term?
> 
> I am told that in Java 10, the suppressed warnings will become errors.
> 
> thanks
> andy

The second solution you tested with Java 1.9 should go on working in Java 1.10 until Oracle does breaking changes under the hood but I'm almost sure that the first solution breaks in Java 1.10.
Comment 17 Andy Skinner 2018-05-10 20:59:55 CEST
I'm told that add-exports still works right now in Java 11, but that we have no idea whether it will stay.

Is there a plan for addressing the issue?  What is involved?

thanks
andy
Comment 18 Julien Gouesse 2018-05-11 10:25:13 CEST
(In reply to Andy Skinner from comment #17)
> I'm told that add-exports still works right now in Java 11, but that we have
> no idea whether it will stay.
> 
> Is there a plan for addressing the issue?  What is involved?
> 
> thanks
> andy

Hey Andy

There is nothing to fix yet. If Oracle moves the internal classes of AWT that we use in JogAmp, we'll have to use the reflection to find them in order to make it work both with the current location and the new location.

The addition of exports can be done in module-info.java or in a JAR manifest too, it would allow us not to do it in command line. Let me know whether you find this solution smarter.
Comment 19 Andy Skinner 2018-05-11 14:29:28 CEST
We've got a spot to do the add-exports, so we're OK with that for now.

Could you write or point me to a clear explanation of the problem?  I know it it has to do with access to things in AWT and changes in Java 9, but I'd like to put it all together.  I have looked through the forum post and this bug report, but still think it would be good to have clarity on what the problem is that we're working around with add-exports, and what the future options are.  This was prompted by me not really understanding what is meant that there is nothing to fix at this point.

thanks
andy
Comment 20 Sven Gothel 2019-03-28 17:47:36 CET
(In reply to Andy Skinner from comment #19)
> We've got a spot to do the add-exports, so we're OK with that for now.
> 
> Could you write or point me to a clear explanation of the problem?  I know
> it it has to do with access to things in AWT and changes in Java 9, but I'd
> like to put it all together.  I have looked through the forum post and this
> bug report, but still think it would be good to have clarity on what the
> problem is that we're working around with add-exports, and what the future
> options are.  This was prompted by me not really understanding what is meant
> that there is nothing to fix at this point.
> 
> thanks
> andy

The problem here causing incompatibility is the new encapsulation of the module system for Java > 8, which by now you surely are aware of.

Related JEP's 260 and 261

I have created Bug 1363 to address all these issues and coordinate work towards a clean Java 11 JogAmp build.
Comment 21 Julien Gouesse 2019-08-16 12:59:17 CEST
This should work in the meantime:
--add-exports java.base/java.lang=ALL-UNNAMED
--add-exports java.desktop/sun.awt=ALL-UNNAMED
--add-exports java.desktop/sun.java2d=ALL-UNNAMED
Comment 22 Sven Gothel 2019-08-20 06:59:44 CEST
(In reply to Julien Gouesse from comment #21)
> This should work in the meantime:
> --add-exports java.base/java.lang=ALL-UNNAMED
> --add-exports java.desktop/sun.awt=ALL-UNNAMED
> --add-exports java.desktop/sun.java2d=ALL-UNNAMED

As our java11 capable release comes to a closing,
passing the unit tests will close this bug.

However, Java9 will not be officially supported.