Java exception upon installation -- Ubuntu 18.04 JDK 17+35

2,846 views
Skip to first unread message

tmasti...@gmail.com

unread,
Apr 8, 2022, 7:13:23 AM4/8/22
to OpenPnP
Hi,

I have installed the latest OpenPNP 2 from 'Downloads'.
My Java is
java --version
openjdk 17 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)

I get the following exception on running /usr/local/bin/OpenPnp

java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1ea0fbbc
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    at javassist.util.proxy.SecurityActions.setAccessible(SecurityActions.java:159)
    at javassist.util.proxy.DefineClassHelper$JavaOther.defineClass(DefineClassHelper.java:213)
    at javassist.util.proxy.DefineClassHelper$Java11.defineClass(DefineClassHelper.java:52)
    at javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.java:260)
    at javassist.ClassPool.toClass(ClassPool.java:1240)
    at javassist.ClassPool.toClass(ClassPool.java:1098)
    at javassist.ClassPool.toClass(ClassPool.java:1056)
    at javassist.CtClass.toClass(CtClass.java:1298)
    at org.openpnp.Main.monkeyPatchBeansBinding(Main.java:101)
    at org.openpnp.Main.main(Main.java:121)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:84)
    at com.install4j.runtime.launcher.UnixLauncher.start(UnixLauncher.java:66)
    at install4j.org.openpnp.Main.main(Unknown Source)
Uncaught error fetching image:
java.lang.NullPointerException: Cannot invoke "java.net.URL.openConnection()" because "this.url" is null
    at java.desktop/sun.awt.image.URLImageSource.getConnection(URLImageSource.java:103)
    at java.desktop/sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:113)
    at java.desktop/sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:264)
    at java.desktop/sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:212)
    at java.desktop/sun.awt.image.ImageFetcher.run(ImageFetcher.java:176

Any ideas how I can fix this?

Thanks!

tmasti...@gmail.com

unread,
Apr 8, 2022, 8:07:59 AM4/8/22
to OpenPnP
Ok, this was due to the Java monkey patching being done.
Added extra arg to the jvm invocation as follows (just before the -classpath argument)

--add-opens java.base/java.lang=ALL-UNNAMED

and that pacified the Java reflection's checker.

Not sure why that's not standard.

Ian Arkver

unread,
Apr 8, 2022, 9:29:18 AM4/8/22
to OpenPnP
The official supported versions of Java are < 17 which is why this isn't a default.

Adding this add-opens flag fixes the monkey patching but doesn't fix all the reflection requirements. You also need (at least)
--add-opens java.desktop/java.awt=ALL-UNNAMED
otherwise machine.xml load/save will fail.

Thanks for bringing add-opens to my attention btw. I'm not a java developer when I can avoid it. I wonder though what the advantage of Java 17 is if you disable the reflection checkers like this?

I changed my pom.xml to target java 17 and added these flags to the surefire launch args and all the tests passed! I've not tried the generated package on the actual machine. I think it would need a lot more testing before a PR would be accepted.

Regards,
Ian

tmasti...@gmail.com

unread,
Apr 8, 2022, 10:18:13 AM4/8/22
to OpenPnP
Thanks Ian, for shining more light.

Guess I should go with Java version <= 16 to play it safe.

Thanks!

Ian Arkver

unread,
Apr 8, 2022, 11:21:27 AM4/8/22
to OpenPnP
No problems.


I looked at this a while back but got totally bogged down in it and ran out of time. Using "add-opens" may be a quick/hacky fix.

Regards,
Ian
Reply all
Reply to author
Forward
0 new messages