'Detected an instance of Random/SplittableRandom class in the image heap

I'm using a Quarkus-Kotlin-Gradle combo and I would like to build in native

I build the app with (native marked in the app.props: quarkus.package.type=native):

quarkus build

I got the following error:

Detected an instance of Random/SplittableRandom class in the image heap.

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. To see how this object got instantiated use --trace-object-instantiation=java.security.SecureRandom. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=. Or you can write your own initialization methods and call them explicitly from your main entry point.

I got this error because of the following codepart (If I remove this, the native build is successful):

org.apache.http.ssl.SSLContextBuilder
    .create()
    .loadKeyMaterial(
        keyStore("path\\to\\key\\key.p12", password),
        password
    )
.loadTrustMaterial(null, TrustSelfSignedStrategy())
.build()

I was trying to solve this problems with this solutions but non of them was working, I still get the same error:

@RegisterForReflection(targets = [java.security.SecureRandom::class])
class SecureRandomReflection

And in app.props:

quarkus.native.additional-build-args=\
  --initialize-at-run-time=java.security.SecureRandom\
  --trace-object-instantiation=java.security.SecureRandom

Is it possible the a problem is that the SecureRandom init is in a dependency? Or any idea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source