'PrivilegedActionException in quarkus when using JOOQ
First up; the code works. I'm getting an exception in my log but no actual error actually occurs. The correct output gets sent to the client, the app keeps running, as far as I can tell everything is fine. Yet I have an error.
I'm using Quarkus and JOOQ. There is an endpoint that triggers a select().fetchInto(Custom.class). The endpoint still returns the correct data. But the log shows this error:
2021-07-02 12:58:25,938 SEVERE [com.sun.xml.bin.v2.run.ref.opt.Injector] (executor-thread-1) null: java.security.PrivilegedActionException: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:558)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.java:166)
at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:51)
The exception is long. And goes through a bunch of different pieces of code:
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:99)
...
at javax.xml.bind.ContextFinder.find(ContextFinder.java:393)
...
at org.jooq.tools.Convert.<clinit>(Convert.java:223)
...
at org.jooq.impl.SelectImpl.fetchInto(SelectImpl.java:3936)
...
at my-code-here-somewhere
Right now I'm running as a simple uber-jar. Native compilation worked fine a while ago but I haven't tested if this error persists in the native binary.
I'd like the error to not be there. I'm fine with a solution to suppress it but if possible I'd like to know who is failing to do something here and if there is a real problem.
Some versions and stuff:
- Installed Java: 16
- Targeted Java: 11
- Quarkus: 1.13.7.Final
- io.quarkiverse.jooq:quarkus-jooq : 0.2.0
Solution 1:[1]
When you use jOOQ with Quarkus native (GraalVM) you must register all jOOQ generated classes like POJOs and Records for reflection, so GraalVM does not remove the classes/methods/fields that are not used directly.
This is because jOOQ DSL.fetchInto(Class<?>) uses reflection.
You can register the jOOQ generated classes manually or do it automatically with the Gradle task I'm using myself for production software. https://stackoverflow.com/a/70870930/5666188
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ThoSap |
