From 49ecb24cc5c50c340ee67b3c78f17d2d390a6e25 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 24 Jul 2024 11:52:36 +0300 Subject: [PATCH] Register sun.security.provider.NativePRNG# for reflection When instantiating a SecureRandom the constructor reflectively looks for the NativePRNG constructor and invokes it. Although the lookup succeeds without the explicit registration, it's better to explicitly request it. This also prevents getting a `MissingRegistrationError` when using `-H:+ThrowMissingRegistrationErrors` or `--exact-reachability-metadata`. Relates to https://github.com/quarkusio/quarkus/issues/41995 --- .../deployment/SecureRandomProcessor.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 core/deployment/src/main/java/io/quarkus/deployment/SecureRandomProcessor.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/SecureRandomProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/SecureRandomProcessor.java new file mode 100644 index 00000000000000..7eb9296a024469 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/SecureRandomProcessor.java @@ -0,0 +1,16 @@ +package io.quarkus.deployment; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; + +public class SecureRandomProcessor { + + @BuildStep + void registerReflectiveMethods(BuildProducer reflectiveMethods) { + // Called reflectively through java.security.SecureRandom.SecureRandom() + reflectiveMethods.produce(new ReflectiveMethodBuildItem("sun.security.provider.NativePRNG", "", + java.security.SecureRandomParameters.class)); + } + +}