@RegisterForProxy(targets={MyInterface.class, MySecondInterface.class})
public class MyReflectionConfiguration {
There are cases where the initialization of certain classes is done in a static block needs to be postponed to runtime.
Typically, omitting such configuration would result in a runtime exception like the following:
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.security.provider.NativePRNG
Trace: object java.security.SecureRandom
method com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode)
Call path from entry point to com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode):
Another common source of errors is when the image heap taken by GraalVM contains a Random
/SplittableRandom
instance:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.
Which is more often than not caused by Quarkus initializing at build time a class with a static Random
/SplittableRandom
field,
causing this particular instance to be tentatively included in the image heap.
In these cases, delaying the infringing class initialization at runtime might be the solution and, to achieve that,
you can use the --initialize-at-run-time=<package or class>
configuration knob.
It should be added to the native-image
configuration using the quarkus.native.additional-build-args
configuration property as shown in the examples above.
When multiple classes or packages need to be specified via the quarkus.native.additional-build-args
configuration property, the ,
symbol needs to be escaped.
An example of this is the following:
quarkus.native.additional-build-args=--initialize-at-run-time=com.example.SomeClass\\,org.acme.SomeOtherClass
and in the case of using the Maven configuration instead of application.properties
:
<quarkus.native.additional-build-args>--initialize-at-run-time=com.example.SomeClass\,org.acme.SomeOtherClass</quarkus.native.additional-build-args>