Skip to content

Commit

Permalink
Register sun.security.provider.NativePRNG#<init> for reflection
Browse files Browse the repository at this point in the history
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 quarkusio#41995

(cherry picked from commit 0e8f9cd)
  • Loading branch information
zakkak authored and gsmet committed Aug 1, 2024
1 parent a30d82d commit 937991c
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ReflectiveMethodBuildItem> reflectiveMethods) {
// Called reflectively through java.security.SecureRandom.SecureRandom()
reflectiveMethods.produce(new ReflectiveMethodBuildItem("sun.security.provider.NativePRNG", "<init>",
java.security.SecureRandomParameters.class));
}

}

0 comments on commit 937991c

Please sign in to comment.