From df10660b0c9b63f24710d8fce87dbdc970ad09a3 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Fri, 12 Aug 2022 10:19:18 +0300 Subject: [PATCH] Use own lookupMethod to avoid dependency on internal GraalVM API --- core/deployment/pom.xml | 4 ++++ .../steps/NativeImageFeatureStep.java | 17 ++++++++++++++++- pom.xml | 1 - 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/deployment/pom.xml b/core/deployment/pom.xml index 18a27d767cca7..c378732240ba6 100644 --- a/core/deployment/pom.xml +++ b/core/deployment/pom.xml @@ -194,6 +194,10 @@ ${project.version} + + --add-exports + java.base/jdk.internal.module=ALL-UNNAMED + diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java index 87c5a555557d1..88dfead5a4444 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java @@ -53,6 +53,7 @@ import io.quarkus.runtime.ResourceHelper; import io.quarkus.runtime.graal.ResourcesFeature; import io.quarkus.runtime.graal.WeakReflection; +import jdk.internal.module.Modules; public class NativeImageFeatureStep { @@ -82,7 +83,7 @@ public class NativeImageFeatureStep { String.class); private static final MethodDescriptor LOOKUP_METHOD = ofMethod( - "com.oracle.svm.util.ReflectionUtil", + NativeImageFeatureStep.class, "lookupMethod", Method.class, Class.class, String.class, Class[].class); private static final MethodDescriptor FOR_NAME = ofMethod( Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class); @@ -688,4 +689,18 @@ private ReflectionInfo(boolean constructors, boolean methods, boolean fields, bo } } + private static Method lookupMethod(Class declaringClass, String methodName, Class... parameterTypes) + throws NoSuchMethodException { + Method result = declaringClass.getDeclaredMethod(methodName, parameterTypes); + Module declaringModule = declaringClass.getModule(); + String packageName = declaringClass.getPackageName(); + + if (declaringModule.isOpen(packageName)) { + Modules.addOpensToAllUnnamed(declaringModule, packageName); + } + + result.setAccessible(true); + return result; + } + } diff --git a/pom.xml b/pom.xml index 157816ad932ce..f54fecbbb0af1 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,6 @@ 11 11 - 11 true ${env.GRAALVM_HOME}