You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/13 11:36:04 UTC

[groovy] 01/01: GROOVY-10137: [JDK16] Illegal access to dynamic proxy

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 424812cd6a4b620cb463e4fedc172b4dfc5378e8
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jun 13 18:55:34 2021 +0800

    GROOVY-10137: [JDK16] Illegal access to dynamic proxy
---
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index 1600070..bf476e4 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -42,6 +42,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 import java.math.BigInteger;
 import java.net.URI;
 import java.util.ArrayList;
@@ -179,6 +180,12 @@ public class Java9 extends Java8 {
 
     public static MethodHandles.Lookup of(final Class<?> declaringClass) {
         try {
+            // All proxy classes are not open for reflective access in Java SE 16
+            // See also https://www.oracle.com/java/technologies/javase/16-relnotes.html
+            if (Proxy.isProxyClass(declaringClass)) {
+                return MethodHandles.lookup().in(declaringClass);
+            }
+
             final Method privateLookup = getPrivateLookup();
             if (privateLookup != null) {
                 return (MethodHandles.Lookup) privateLookup.invoke(null, declaringClass, MethodHandles.lookup());