Java17 compatibility error ??

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Java17 compatibility error ??

Jerome
Hello,

I'm developing CodeLab IDE & Simulators using Java3D. To remain compatible with other libraries, I need to upgrade to Java 17 (https://adoptium.net/temurin/releases/?version=17), but apparently Java3D is causing compatibility problems. When will a Java3D version compatible with Java17 be available?

Thank you for help me!

Jerome
https://codelab.univ-lemans.fr


Caught AppContextInfo(Bug 1004) InaccessibleObjectException: Unable to make public static sun.awt.AppContext sun.awt.AppContext.getAppContext() accessible: module java.desktop does not "exports sun.awt" to unnamed module @4ee22985 on thread J3D-Renderer-1
    [0]: java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    [1]: java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    [2]: java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    [3]: java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    [4]: com.jogamp.nativewindow.awt.AppContextInfo$1$1.run(AppContextInfo.java:40)
    [5]: com.jogamp.common.util.UnsafeUtil.doWithoutIllegalAccessLogger(UnsafeUtil.java:219)
    [6]: com.jogamp.nativewindow.awt.AppContextInfo$1.run(AppContextInfo.java:34)
    [7]: java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    [8]: com.jogamp.nativewindow.awt.AppContextInfo.<clinit>(AppContextInfo.java:31)
    [9]: com.jogamp.nativewindow.awt.JAWTWindow.<init>(JAWTWindow.java:128)
    [10]: jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow.<init>(MacOSXJAWTWindow.java:79)
    [11]: java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [12]: java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    [13]: java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    [14]: java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    [15]: java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    [16]: jogamp.nativewindow.NativeWindowFactoryImpl.getAWTNativeWindow(NativeWindowFactoryImpl.java:105)
    [17]: jogamp.nativewindow.NativeWindowFactoryImpl.getNativeWindowImpl(NativeWindowFactoryImpl.java:66)
    [18]: com.jogamp.nativewindow.NativeWindowFactory.getNativeWindow(NativeWindowFactory.java:654)
    [19]: org.jogamp.java3d.JoglPipeline$QueryCanvas.addNotify(JoglPipeline.java:8665)
    [20]: java.desktop/java.awt.Container.addNotify(Container.java:2804)
    [21]: java.desktop/java.awt.Window.addNotify(Window.java:791)
    [22]: java.desktop/java.awt.Dialog.addNotify(Dialog.java:770)
    [23]: java.desktop/java.awt.Dialog.conditionalShow(Dialog.java:917)
    [24]: java.desktop/java.awt.Dialog.show(Dialog.java:1048)
    [25]: java.desktop/java.awt.Component.show(Component.java:1728)
    [26]: java.desktop/java.awt.Component.setVisible(Component.java:1675)
    [27]: java.desktop/java.awt.Window.setVisible(Window.java:1036)
    [28]: java.desktop/java.awt.Dialog.setVisible(Dialog.java:1016)
    [29]: org.jogamp.java3d.JoglPipeline.getBestConfiguration(JoglPipeline.java:8439)
    [30]: org.jogamp.java3d.Renderer.doWork(Renderer.java:497)
    [31]: org.jogamp.java3d.J3dThread.run(J3dThread.java:271)
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
As I replied in a private message, you just have to use the usual "--add-opens" clause I mentioned in my tutorial to make it work.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

goodwilling
In reply to this post by Jerome
In our case, we use the following options when using Java 17.

(Windows)
--add-exports=java.desktop/sun.awt=ALL-UNNAMED

(Linux)
--add-exports=java.desktop/sun.awt=ALL-UNNAMED  --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED

By the way, it is unfortunately found that the "--add exports" option is ignored in some Windows systems if it is added in .l4j.ini for Launch4j (an old version), whereas the option works if added to a Windows .bat file.
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
Thank you for the feedback. It's strange, "--add-opens java.desktop/sun.awt=ALL-UNNAMED" was enough to make it work under GNU Linux the last time I tried.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

Sven Gothel
Administrator
Currently used in master tip
--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.awt.windows=ALL-UNNAMED --add-opens java.desktop/sun.java2d=ALL-UNNAMED
The added one to have background erase working w/ AWT
https://jogamp.org/bugzilla//show_bug.cgi?id=1430#c3
--add-opens java.desktop/sun.awt.windows=ALL-UNNAMED
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
In reply to this post by gouessej
Hi!
I have the same error/exception =>

Caught AppContextInfo(Bug 1004) InaccessibleObjectException: Unable to make public static sun.awt.AppContext sun.awt.AppContext.getAppContext() accessible: module java.desktop does not "exports sun.awt" to unnamed module @eb21112 on thread J3D-Renderer-1

As you suggested to OP, I added "‐‐add-opens=java.desktop/sun.awt=ALL-UNNAMED" to the VM arguments in Eclipse IDE 'Run Configurations..."

However, this did not work. Now I get:

Error: Could not find or load main class ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED
Caused by: java.lang.ClassNotFoundException: ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED

It appears it's trying to load the VM arguments as a class...?!?!??!?
WTF?

What am I missing?

I'm using:
MacOS Big Sur
Eclipse 4.33
Java SDK 23
JOGL 2.5.0
Java3D 1.7.1
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
Hello

As far as I can tell, Eclipse seems to generate the command line by placing the arguments in the wrong order, it doesn't mean that Eclipse has a bug but maybe there's something wrong in your project. You can probably reproduce your problem in command line by inverting the main class and the --add-opens clause. How do you specify the main class?

P.S: Please indicate how you fill the "Main" and the "Arguments" tabs.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
Thanks for your response Julien.

The main class is Demo.LightingExample
The program arguments are blank.
The VM arguments are ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED

Here is my full command line generated by Eclipse (with the —add-opens option):
/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home/bin/java ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED -Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -p /Library/Java/Extensions -classpath /Users/andrew/Documents/eclipse-workspace/3D Stuff/bin:/Users/andrew/Miscellaneous JARS/vrml97.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/bin:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/bin:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-core.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-utils.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/vecmath.jar Demo.LightingExample

This raises the ClassNotFoundException when executing both in Eclipse and from the command line.
Error: Could not find or load main class ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED
Caused by: java.lang.ClassNotFoundException: ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED

If I don't include the —add-opens option, the program appears to run (including the 3D components) but I get several exceptions:
AppContextInfo(Bug 1004) InaccessibleObjectException: Unable to make public static sun.awt.AppContext sun.awt.AppContext.getAppContext() accessible: module java.desktop does not "exports sun.awt" to unnamed module @eb21112 on thread J3D-Renderer-1

Here is the command line without the —add-opens option:
/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -p /Library/Java/Extensions -classpath /Users/andrew/Documents/eclipse-workspace/3D Stuff/bin:/Users/andrew/Miscellaneous JARS/vrml97.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/bin:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/bin:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-core.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-utils.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/vecmath.jar Demo.LightingExample

Note that when I execute in the command line I have to add " marks around classpath...

Any idea what's going on?

Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
This post was updated on .
You're welcome, thank you for your detailed information.

At first, the extension mechanism has been removed from Java a long time ago and your version of Java doesn't support it, -p is a shortcut of --module-path and JogAmp's Java has never been an extension and shouldn't be mixed with an old version of Java3D installed as an extension. It will probably not be enough to solve your problem but you shouldn't use "-p /Library/Java/Extensions".

Secondly, your version of Java uses UTF-8 by default on all operating systems, "-Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8" is useless too in this case.

Thirdly, either avoid spaces in directory names or escape them correctly, i.e "3D Stuff" and "Miscellaneous JARS". Yes you have to add " marks around the classpath because of these spaces. Maybe Eclipse doesn't do that correctly.

Fourthly, you can simplify your classpath by using jogamp-all.jar instead of separate JogAmp JARs.

Moreover, there is no need to put bin/ into the classpath, don't confuse the classpath with the library path. If you don't want to change too much things, remove the spaces from your directory names, update your Eclipse run configuration to take this change into account, try again with --add-opens and if it still fails to work, try to remove the useless stuff I mentioned.

This should work:
/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home/bin/java ‐‐add-opens=java.desktop/sun.awt=ALL-UNNAMED  -classpath /Users/andrew/Documents/eclipse-workspace/3D\ Stuff/bin:/Users/andrew/Miscellaneous\ JARS/vrml97.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/bin:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/bin:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-core.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-utils.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/vecmath.jar Demo.LightingExample
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
Ok, I removed all the unnecessary stuff and renamed 3D Stuff to 3D_Stuff...
No change. Still get Error: Could not find or load main class ‐‐add-opens=java.desktop.sun.awt=ALL-UNNAMED

So I wondered if the —add-opens option need to be AFTER the -classpath option...?
Tried this but now I get:
Error occurred during initialization of boot layer
java.lang.RuntimeException: Unable to parse --add-opens <module>/<package>: java.desktop.sun.awt

I had to change the order of the —add-opens option on the command line because Eclipse always places it first before the classpath. Not sure whether you can change it in Eclipse.

I take it that this is an issue introduced by Java 9..?
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
This post was updated on .
You wrote :
-‐add-opens=java.desktop.sun.awt=ALL-UNNAMED

instead of :
-‐add-opens=java.desktop/sun.awt=ALL-UNNAMED

Do you see the difference?

By the way, I mentioned two directories to rename, not only one. Yes, the --add-opens clause should appear first before the classpath.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
Thanks again for your responses.
Duh! What a dope!

Changed the option to:
--add-opens=java.desktop/sun.awt=ALL-UNNAMED

and also:
--add-opens java.desktop/sun.awt=ALL-UNNAMED

Either way, I get:
Unrecognized option: -‐add-opens
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

This is ridiculous!
Java 23 specifies --add-opens (see java --help-extra), yet the error says it's unrecognised!
What the hell is going on???
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
In reply to this post by gouessej
BTW, I removed the 'Miscellaneous JARS' directory altogether. It was not necessary/required.
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
In reply to this post by andrewk1972
Both syntaxes are valid but Eclipse needs the first one:
--add-opens=java.desktop/sun.awt=ALL-UNNAMED

Please can you post the whole command line?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
Here is the complete command line generated by Eclipse:
/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home/bin/java
-‐add-opens=java.desktop/sun.awt=ALL-UNNAMED
-classpath /Users/andrew/Documents/eclipse-workspace/3D_Stuff/bin:/Users/andrew/Documents/eclipse-workspace/JOGL/bin:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/gluegen-rt-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all.jar:/Users/andrew/Documents/eclipse-workspace/JOGL/lib/jogl-all-natives-macosx-universal.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/bin:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-core.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/java3d-utils.jar:/Users/andrew/Documents/eclipse-workspace/Java3D/lib/vecmath.jar Demo.LightingExample

Executing the above in Eclipse generates:
Unrecognized option: -‐add-opens=java.desktop/sun.awt=ALL-UNNAMED
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Thanks for looking into this. It's driving me nuts!
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
This post was updated on .
Does this command line work in Eclipse without the --add-opens clause?

Does this command line work outside of Eclipse when it remained unchanged, i.e with the --add-opens clause?

I'm going to give it a try under GNU Linux with OpenJDK 23, the classpath separator is the same than under OS X, it should work.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
Well yes in the sense that the Java3D app executes and the 3D lighting demo displays and user can interact with it, but a series of InaccessibleObjectException errors are raised, eg.
Caught AppContextInfo(Bug 1004) InaccessibleObjectException: Unable to make public static sun.awt.AppContext sun.awt.AppContext.getAppContext() accessible: module java.desktop does not "exports sun.awt" to unnamed module @6043cd28 on thread J3D-Renderer-1
    [0]: java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:388)
    [1]: java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:364)
    [2]: java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:312)
    [3]: java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:203)
    [4]: java.base/java.lang.reflect.Method.setAccessible(Method.java:197)
    [5]: com.jogamp.nativewindow.awt.AppContextInfo$1$1.run(AppContextInfo.java:40)
    [6]: com.jogamp.common.util.UnsafeUtil.doWithoutIllegalAccessLogger(UnsafeUtil.java:218)
    [7]: com.jogamp.nativewindow.awt.AppContextInfo$1.run(AppContextInfo.java:34)
    [8]: com.jogamp.common.util.SecurityUtil.doPrivileged(SecurityUtil.java:80)
    [9]: com.jogamp.nativewindow.awt.AppContextInfo.<clinit>(AppContextInfo.java:31)
    [10]: com.jogamp.nativewindow.awt.JAWTWindow.<init>(JAWTWindow.java:124)
    [11]: jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow.<init>(MacOSXJAWTWindow.java:78)
    [12]: java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
    [13]: java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:501)
    [14]: java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:485)
    [15]: jogamp.nativewindow.NativeWindowFactoryImpl.getAWTNativeWindow(NativeWindowFactoryImpl.java:105)
    [16]: jogamp.nativewindow.NativeWindowFactoryImpl.getNativeWindowImpl(NativeWindowFactoryImpl.java:66)
    [17]: com.jogamp.nativewindow.NativeWindowFactory.getNativeWindow(NativeWindowFactory.java:623)
    [18]: org.jogamp.java3d.JoglPipeline$QueryCanvas.addNotify(JoglPipeline.java:8701)
    [19]: java.desktop/java.awt.Container.addNotify(Container.java:2804)
    [20]: java.desktop/java.awt.Window.addNotify(Window.java:791)
    [21]: java.desktop/java.awt.Dialog.addNotify(Dialog.java:769)
    [22]: java.desktop/java.awt.Dialog.conditionalShow(Dialog.java:916)
    [23]: java.desktop/java.awt.Dialog.show(Dialog.java:1047)
    [24]: java.desktop/java.awt.Component.show(Component.java:1728)
    [25]: java.desktop/java.awt.Component.setVisible(Component.java:1675)
    [26]: java.desktop/java.awt.Window.setVisible(Window.java:1036)
    [27]: java.desktop/java.awt.Dialog.setVisible(Dialog.java:1015)
    [28]: org.jogamp.java3d.JoglPipeline.getBestConfiguration(JoglPipeline.java:8446)
    [29]: org.jogamp.java3d.Renderer.doWork(Renderer.java:497)
    [30]: org.jogamp.java3d.J3dThread.run(J3dThread.java:271)

No, it always raises:
Error: Could not find or load main class Demo.LightingExample
Caused by: java.lang.ClassNotFoundException: Demo.LightingExample
with or without --add-opens

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
You can fix the ClassNotFoundException by adding the directory containing your packages (and then your .class files) into your classpath. It's important to make it work first outside of your favorite IDE in order to exclude Java itself from the possible root causes.

Then, when it works in command line, we can suspect that Eclipse doesn't show all directories included in its classpath and maybe it really has a problem with escaping spaces in paths.

In which directory is your Eclipse project? Please provide the absolute path.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

andrewk1972
Absolute path:
/Users/andrew/Documents/eclipse-workspace/3D_Stuff

Added /Users/andrew/Documents/eclipse-workspace/3D_Stuff/bin to classpath...

YAY!!! Now it works! With no exceptions!

So yes, it appears Eclipse is screwing something up...

Stirling effort Julien!
Reply | Threaded
Open this post in threaded view
|

Re: Java17 compatibility error ??

gouessej
Administrator
It's a good piece of news.

I advise you to recreate your Eclipse project from scratch in a directory containing no special characters and no spaces in order to exclude the possibility of something having been broken when you renamed the directory. If the problem persists, you'll have to report it to the Eclipse community. I assume that Eclipse still includes an unescaped directory name that it badly parsed.
Julien Gouesse | Personal blog | Website