package io.quarkus.liquibase.runtime.graal;

import java.security.SecureRandom;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

@TargetClass(className = "liquibase.util.StringUtil")
final class SubstituteStringUtil {

    @Alias
    @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)
    private static SecureRandom rnd;

    @Substitute
    public static String randomIdentifer(int len) {
        SecureRandom rnd = new SecureRandom();
        final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++)
            sb.append(AB.charAt(rnd.nextInt(AB.length())));
        return sb.toString();
    }
}

@@ -157,75 +157,23 @@
 ate.
-RecomputeFieldValue;%0Aimport com.oracle.svm.core.annotate.Substitute
+InjectAccessors
 ;%0Aim
@@ -330,169 +330,247 @@
    @
-RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)%0A    private static SecureRandom rnd;%0A%0A    @Substitute%0A    public static String randomIdentifer(int len
+InjectAccessors(SecureRandomAccessors.class)%0A    private static SecureRandom rnd;%0A%0A    public static final class SecureRandomAccessors %7B%0A%0A        private static volatile SecureRandom volatileRandom;%0A%0A        public static SecureRandom get(
 ) %7B%0A
@@ -577,16 +577,20 @@
         
+    
 SecureRa
@@ -598,269 +598,629 @@
 dom 
-rnd = new SecureRandom();%0A        final String AB = %22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22;%0A%0A        StringBuilder sb = new StringBuilder(len);%0A        for (int i = 0; i %3C len; i++)%0A            sb.append(AB.charAt(rnd.nextInt(AB.length())));%0A        return sb.toString();
+localVolatileRandom = volatileRandom;%0A            if (localVolatileRandom == null) %7B%0A                synchronized (SecureRandomAccessors.class) %7B%0A                    localVolatileRandom = volatileRandom;%0A                    if (localVolatileRandom == null) %7B%0A                        volatileRandom = localVolatileRandom = new SecureRandom();%0A                    %7D%0A                %7D%0A            %7D%0A            return localVolatileRandom;%0A        %7D%0A%0A        public static void set(SecureRandom rnd) %7B%0A            throw new IllegalStateException(%22The setter for liquibase.util.StringUtil#rnd shouldn't be called.%22);%0A        %7D
 %0A   

Use @FieldAccessors to access liquibase.util.StringUtil#rnd