|
29 | 29 | import java.lang.reflect.Executable; |
30 | 30 | import java.lang.reflect.Field; |
31 | 31 | import java.lang.reflect.Method; |
| 32 | +import java.lang.reflect.Proxy; |
| 33 | +import java.util.Arrays; |
32 | 34 | import java.util.Map; |
33 | 35 | import java.util.Set; |
34 | 36 | import java.util.StringJoiner; |
@@ -110,10 +112,28 @@ public static void forBulkQuery(Class<?> declaringClass, String methodName) { |
110 | 112 | report(exception); |
111 | 113 | } |
112 | 114 |
|
| 115 | + public static void forProxy(Class<?>... interfaces) { |
| 116 | + MissingReflectionRegistrationError exception = new MissingReflectionRegistrationError(errorMessage("access the proxy class inheriting", |
| 117 | + Arrays.toString(Arrays.stream(interfaces).map(Class::getTypeName).toArray()), |
| 118 | + "The order of interfaces used to create proxies matters.", "dynamic-proxy"), |
| 119 | + Proxy.class, null, null, interfaces); |
| 120 | + report(exception); |
| 121 | + /* |
| 122 | + * If report doesn't throw, we throw the exception anyway since this is a Native |
| 123 | + * Image-specific error that is unrecoverable in any case. |
| 124 | + */ |
| 125 | + throw exception; |
| 126 | + } |
| 127 | + |
113 | 128 | private static String errorMessage(String failedAction, String elementDescriptor) { |
| 129 | + return errorMessage(failedAction, elementDescriptor, null, "reflection"); |
| 130 | + } |
| 131 | + |
| 132 | + private static String errorMessage(String failedAction, String elementDescriptor, String note, String helpLink) { |
114 | 133 | return "The program tried to reflectively " + failedAction + " " + elementDescriptor + |
115 | | - " without it being registered for runtime reflection. Add it to the reflection metadata to solve this problem. " + |
116 | | - "See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help."; |
| 134 | + " without it being registered for runtime reflection. Add " + elementDescriptor + " to the " + helpLink + " metadata to solve this problem. " + |
| 135 | + (note != null ? "Note: " + note + " " : "") + |
| 136 | + "See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#" + helpLink + " for help."; |
117 | 137 | } |
118 | 138 |
|
119 | 139 | private static final int CONTEXT_LINES = 4; |
@@ -213,6 +233,7 @@ private static void printLine(StringBuilder sb, Object object) { |
213 | 233 | "newInstance"), |
214 | 234 | Method.class.getTypeName(), Set.of("invoke"), |
215 | 235 | Constructor.class.getTypeName(), Set.of("newInstance"), |
| 236 | + Proxy.class.getTypeName(), Set.of("getProxyClass", "newProxyInstance"), |
216 | 237 | "java.lang.reflect.ReflectAccess", Set.of("newInstance"), |
217 | 238 | "jdk.internal.access.JavaLangAccess", Set.of("getDeclaredPublicMethods"), |
218 | 239 | "sun.misc.Unsafe", Set.of("allocateInstance"), |
|
0 commit comments