The Java Module System (sometimes also called JPMS) encapsulates modules and prevents applications from accessing JDK internals (JEP 260, JEP 396, JEP 403).

NetBeans has to break this encapsulation occasionally and therefore sets JVM flags to override the default.

The list of JVM options NetBeans itself sets can be found here:

https://github.com/apache/netbeans/tree/master/nbbuild/jms-config

(those will land in your netbeans.conf and ensure that NetBeans can run on modern JDKs)


The same rule applies to any application, like for example a NetBeans platform application. The concrete set of options however highly depends on what dependencies the application actually uses and also what it does at runtime (some might not need any flags).

If you see exceptions like this:

java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.net.URLStreamHandler java.net.URL.handler accessible: module java.base does not "opens java.net" to unnamed module @2e0fa5d3
	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.Field.checkCanSetAccessible(Field.java:180)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:174)
	at org.netbeans.ProxyURLStreamHandlerFactory.register(ProxyURLStreamHandlerFactory.java:59)
	at org.netbeans.JarClassLoader.<clinit>(JarClassLoader.java:142)
	at org.netbeans.MainImpl.execute(MainImpl.java:153)
	at org.netbeans.MainImpl.main(MainImpl.java:60)
	at org.netbeans.Main.main(Main.java:58)

you probably have to set some flags too! (--add-opens=java.base/java.net=ALL-UNNAMED in this example)


There are many blog entries about this issue since it is fairly common and not unique to NetBeans platform applications:

https://blogs.oracle.com/javamagazine/post/a-peek-into-java-17-continuing-the-drive-to-encapsulate-the-java-runtime-internals

...

  • No labels