diff --git a/Readme.md b/Readme.md index 3a739b0..55ff2d6 100644 --- a/Readme.md +++ b/Readme.md @@ -1,13 +1,12 @@ -# Reproducer for native-image issue with bouncycastle provider +# Reproducer for native-image issue with fields in classes with substituted methods -``` +See https://github.com/quarkusio/quarkus/issues/37862 + +```shell cd /tmp -git clone --branch bouncycastle-services-not-included https://github.com/zakkak/issue-reproducers bouncycastle-services-not-included -cd bouncycastle-services-not-included +git clone --branch 2024-01-10-subst-analysis-issue https://github.com/zakkak/issue-reproducers reproducer +cd reproducer mvn package -java -agentlib:native-image-agent=config-output-dir=META-INF/native-image -jar target/graal-issue-bouncycastle-1.0-SNAPSHOT.jar -native-image --initialize-at-build-time \ - --no-fallback -H:+ReportExceptionStackTraces \ - -jar target/graal-issue-bouncycastle-1.0-SNAPSHOT.jar -./graal-issue-bouncycastle-1.0-SNAPSHOT -``` +java -jar ./target/reproducer-1.0-SNAPSHOT.jar +native-image -cp target/classes/ Main --no-fallback --initialize-at-build-time=. +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 87728f5..aba2292 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.example - graal-issue-bouncycastle + reproducer 1.0-SNAPSHOT @@ -58,15 +58,10 @@ - - org.bouncycastle - bcprov-jdk15on - 1.65 - org.graalvm.nativeimage svm - 21.3.1 + 23.1.0 diff --git a/src/main/java/BouncyCastleFeature.java b/src/main/java/BouncyCastleFeature.java deleted file mode 100644 index 7dfc2c4..0000000 --- a/src/main/java/BouncyCastleFeature.java +++ /dev/null @@ -1,44 +0,0 @@ -import com.oracle.svm.core.annotate.*; - -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.hosted.RuntimeClassInitialization; - -import java.security.Security; - -@AutomaticFeature -public class BouncyCastleFeature implements Feature { - - @Override - public void afterRegistration(AfterRegistrationAccess access) { - System.out.println("After Registration Hello!!!!"); - - // RuntimeClassInitialization.initializeAtBuildTime("org.bouncycastle"); - // RuntimeClassInitialization.initializeAtRunTime("org.bouncycastle.crypto.CryptoServicesRegistrar"); - // RuntimeClassInitialization.initializeAtRunTime("org.bouncycastle.jcajce.provider.drbg.DRBG$Default"); - // RuntimeClassInitialization.initializeAtRunTime("org.bouncycastle.jcajce.provider.drbg.DRBG$NonceAndIV"); - - // Security.addProvider(new BouncyCastleProvider()); - } - - @Override - public void beforeAnalysis(BeforeAnalysisAccess access) { - System.out.println("BeforeAnalysis Hello!!!!"); - - RuntimeClassInitialization.initializeAtBuildTime("org.bouncycastle"); - RuntimeClassInitialization.initializeAtRunTime("org.bouncycastle.crypto.CryptoServicesRegistrar"); - RuntimeClassInitialization.initializeAtRunTime("org.bouncycastle.jcajce.provider.drbg.DRBG$Default"); - RuntimeClassInitialization.initializeAtRunTime("org.bouncycastle.jcajce.provider.drbg.DRBG$NonceAndIV"); - - // Security.addProvider(new BouncyCastleProvider()); - } - - @Override - public void afterAnalysis(AfterAnalysisAccess access) { - System.out.println("AfterAnalysis Hello!!!!"); - - // Too late... providers need to be registered before the analysis - - // Security.addProvider(new BouncyCastleProvider()); - } -} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 7c44777..b5974fb 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,34 +1,24 @@ -import org.bouncycastle.jce.provider.BouncyCastleProvider; - -import javax.crypto.Cipher; -import javax.crypto.NoSuchPaddingException; - -// import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Security; +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; public class Main { - static { - System.out.println("Hello!!!!"); - - // Too late... providers need to be registered before the analysis, but - // static initialization takes plave after it. - - Security.addProvider(new BouncyCastleProvider()); + public static void main(String[] args) { + Substituted substituted = Substituted.INSTANCE; + System.out.println(substituted.getMessage()); } +} - public static void main(String[] args) { +@TargetClass(Substituted.class) +final class Target_Substituted { + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias) + @Alias + public static Target_Substituted INSTANCE = new Target_Substituted(); - try { - // KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC"); - // keyPairGenerator.generateKeyPair(); - // System.out.println("Success"); - Cipher rsaInstance = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); - System.out.println(rsaInstance.getAlgorithm()); - } catch (NoSuchAlgorithmException | NoSuchPaddingException | NoSuchProviderException e) { - e.printStackTrace(); - } + @Substitute + public String getMessage() { + return new String("Substituted"); } -} +} \ No newline at end of file