Exception in code generation on Java 22 - NoSuchMethodError: void sun.misc.Unsafe.ensureClassInitialized
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
I created a minimal Gradle project to demonstrate the issue. https://github.com/edward3h/pkl-java22-unsafe
When using the pkl code generator in Gradle, on Java 22, I get an exception where this is the root cause:
```
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoSuchMethodError: 'void sun.misc.Unsafe.ensureClassInitialized(java.lang.Class)' [in thread "Execution worker Thread 2"]
at org.pkl.thirdparty.truffle.api.library.LibraryFactory.ensureLibraryInitialized(LibraryFactory.java:384)
at org.pkl.thirdparty.truffle.api.library.LibraryFactory.getUncached(LibraryFactory.java:364)
at org.pkl.thirdparty.truffle.api.library.LibraryFactory.(LibraryFactory.java:210)
at org.pkl.thirdparty.truffle.api.interop.InteropLibraryGen.(InteropLibraryGen.java:178)
at org.pkl.thirdparty.truffle.api.interop.InteropLibraryGen.(InteropLibraryGen.java:169)
at org.pkl.thirdparty.truffle.api.library.LibraryFactory.loadGeneratedClass(LibraryFactory.java:791)
at org.pkl.thirdparty.truffle.api.library.LibraryFactory.resolveImpl(LibraryFactory.java:740)
at org.pkl.thirdparty.truffle.api.library.LibraryFactory.resolve(LibraryFactory.java:733)
at org.pkl.thirdparty.truffle.api.interop.InteropLibrary.(InteropLibrary.java:2941)
at org.pkl.thirdparty.truffle.polyglot.PolyglotValueDispatch.(PolyglotValueDispatch.java:170)
at org.pkl.thirdparty.truffle.polyglot.PolyglotImpl.initialize(PolyglotImpl.java:166)
at org.pkl.thirdparty.graalvm.polyglot.impl.AbstractPolyglotImpl.setConstructors(AbstractPolyglotImpl.java:288)
at org.pkl.thirdparty.graalvm.polyglot.Engine$1.loadAndValidateProviders(Engine.java:1107)
at org.pkl.thirdparty.graalvm.polyglot.Engine$1.run(Engine.java:1067)
at org.pkl.thirdparty.graalvm.polyglot.Engine$1.run(Engine.java:1061)
at org.pkl.thirdparty.graalvm.polyglot.Engine.initEngineImpl(Engine.java:1061)
at org.pkl.thirdparty.graalvm.polyglot.Engine$ImplHolder.(Engine.java:143)
at org.pkl.thirdparty.graalvm.polyglot.Engine.getImpl(Engine.java:367)
at org.pkl.thirdparty.graalvm.polyglot.Engine$Builder.build(Engine.java:665)
at org.pkl.core.runtime.VmUtils.(VmUtils.java:74)
```
My projects work ok on Java 21.
Contributor guide
Research direction
Start with the linked minimal Gradle project and reproduce the failure on Java 22, comparing with Java 21. Trace the reported call through org.pkl.thirdparty.truffle.api.library.LibraryFactory and the Pkl code-generation path; done means generation succeeds on Java 22 without regressing Java 21.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100