Skip to content

Commit

Permalink
Add information about how to deal with Random in native
Browse files Browse the repository at this point in the history
Fixes #26835
  • Loading branch information
gsmet committed Aug 3, 2022
1 parent 505770c commit 31a6330
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/src/main/asciidoc/writing-native-applications-tips.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,23 @@ method com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode)
Call path from entry point to com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode):
----

If you need to delay the initialization of a class, you can use the `--initialize-at-run-time=<package or class>` configuration knob.
Another common source of errors is when the image heap taken by GraalVM contains a `Random`/`SplittableRandom` instance:

[source]
----
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.

[TIP]
====
You can find detailed information about this `Random`/`SplittableRandom` issue in https://foivos.zakkak.net/tutorials/working-with-randoms-native-images/[this blog post].
====

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.

Expand Down

0 comments on commit 31a6330

Please sign in to comment.