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
  • Loading branch information
zakkak committed Jul 24, 2024
1 parent ec8e234 commit 0e8f9cd
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 0e8f9cd

Please sign in to comment.