Skip to content

Commit

Permalink
Fix native mode build when jdbc-oracle is combined with jdbc-h2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michalvavrik committed Dec 30, 2022
1 parent 003cdee commit e5120d9
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit e5120d9

Please sign in to comment.