From e5120d948ad17b49b51167760291607ad59f7c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Fri, 30 Dec 2022 15:14:23 +0100 Subject: [PATCH] Fix native mode build when `jdbc-oracle` is combined with `jdbc-h2` Fixes native build when `jdbc-oracle` is combined with `jdbc-h2`. This fix was kindly provided Severin Gehwolf and is added as second commit of this PR as 1. integration tests need the fix 2. no point of creating additional integration test module that combines jdbc-oracle and jdbc-h2 as we already have them here. --- .../runtime/graal/ObjIdSubstitutions.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/ObjIdSubstitutions.java 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