quarkus: caffeine error while building native image: detected the ForkJoinPool.commonPool() in the image heap
Describe the bug
Error: Detected the ForkJoinPool.commonPool() in the image heap. The common pool must be created at run time because the parallelism depends on the number of cores available at run time. Therefore the common pool used during image generation must not be reachable, e.g., via a static field that caches a copy of the common pool. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Detailed message:
Trace: object com.github.benmanes.caffeine.cache.SSLMS
object com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalManualCache
object io.quarkus.it.caffeine.Application_ClientProxy
object io.quarkus.it.caffeine.Application_Bean
object java.lang.Object[]
object java.util.ArrayList
object io.quarkus.arc.ArcContainerImpl
object java.util.concurrent.atomic.AtomicReference
method io.quarkus.arc.Arc.shutdown()
Call path from entry point to io.quarkus.arc.Arc.shutdown():
at io.quarkus.arc.Arc.shutdown(Arc.java:34)
at io.quarkus.arc.runtime.ArcRecorder$1.run(ArcRecorder.java:37)
at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:612)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:479)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
To Reproduce
- checkout https://github.com/quarkusio/quarkus/pull/3301
- run caffeine’s integration-test
Environment (please complete the following information):
- Output of
java -version
: 1.8 - GraalVM version (if different from Java): 19.1.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (16 by maintainers)
@lburgazzoli I’ve just accross the same exception (see here) and I figured out what causes it. You get this exception when you instantiate something for which there’s a substitution.
In my case, I had something like this:
The fix was to use
Kind.NewInstance
and then point to the declaring class, e.g.Note that I don’t know if this would have worked in your case, but thought I’d post it here for posterity, in case anyone faces a similar issue.