diff --git a/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/ObjIdSubstitutions.java b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/ObjIdSubstitutions.java new file mode 100644 index 00000000000000..9f3881b5805bbe --- /dev/null +++ b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/ObjIdSubstitutions.java @@ -0,0 +1,44 @@ +package io.quarkus.jdbc.oracle.runtime.graal; + +import java.security.SecureRandom; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.InjectAccessors; +import com.oracle.svm.core.annotate.TargetClass; + +/** + * Substitutions required when `jdbc-oracle` is combined with `jdbc-h2`. + */ +@TargetClass(className = "java.rmi.server.ObjID") +public final class ObjIdSubstitutions { + + @Alias + @InjectAccessors(SecureRandomAccessor.class) + private static SecureRandom secureRandom; + +} + +class SecureRandomAccessor { + private static volatile SecureRandom RANDOM; + + static SecureRandom get() { + SecureRandom result = RANDOM; + if (result == null) { + /* Lazy initialization on first access. */ + result = initializeOnce(); + } + return result; + } + + private static synchronized SecureRandom initializeOnce() { + SecureRandom result = RANDOM; + if (result != null) { + /* Double-checked locking is OK because INSTANCE is volatile. */ + return result; + } + + result = new SecureRandom(); + RANDOM = result; + return result; + } +} \ No newline at end of file