ClassNotFoundException: sun.misc.Unsafe

1,541 views
Skip to first unread message

Dmitry

unread,
Nov 14, 2023, 10:18:53 AM11/14/23
to WildFly
Hello,
I am trying to upgrade from Wildfly 28 to 29/30 (JDK17), but facing this exception on deployment.

Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe from [Module \"deployment.beacon-nosql-server-2.0.4.war\" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:200)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at deployment.beacon-nosql-server-2.0.4.war//nonapi.io.github.classgraph.utils.FileUtils.lookupCleanMethodPrivileged(FileUtils.java:529)

The problem is in the "classgraph" library that uses sun.misc.Unsafe, but as far as I understand, "jdk.unsupported" should work.

What has changed from 28 -> 29 that deployer see no Unsafe?

Thank you,

Dmitry 

Brian Stansberry

unread,
Nov 14, 2023, 3:13:07 PM11/14/23
to WildFly
Hi Dmitry,

https://issues.redhat.com/browse/WFCORE-6249 is the reason you need to do this. WildFly used to add its own sun.jdk module as a dependency to all deployments, but that overly broadly breaks JDK encapsulation. Deployments can add dependencies on specific JDK JPMS modules they need by listing them in the 'dependencies' section of a jboss-deployment-structure.xml, as discussed in https://docs.wildfly.org/29/Developer_Guide.html#jboss-deployment-structure-file. In your case you'd name 'jdk.unsupported'. Since WildFly now requires SE 11 or later and all such SE versions provide curated-by-OpenJDK JPMS modules that can be depended upon, it's better that users specify which of those they need.

Best regards,
Brian

Brian Stansberry

unread,
Nov 14, 2023, 3:15:40 PM11/14/23
to WildFly
You can also list jdk.unsupported in MANIFEST.MF

Dependencies: jdk.unsupported

Dmitry

unread,
Nov 15, 2023, 8:05:22 AM11/15/23
to WildFly
Hi Brian,

The solution with MANIFEST.MF works either putting it into the classgraph  jar or the *.war file (via maven-war-plugin ) .
I wrote an issue to the classgraph library github.

Thank you very much for the solution.

Dmitry
Reply all
Reply to author
Forward
0 new messages