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/26 05:18:01 UTC

[groovy] branch danielsun/tweak-cache-20210626 updated: Access more methods if "spy" found

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

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


The following commit(s) were added to refs/heads/danielsun/tweak-cache-20210626 by this push:
     new 7a046af  Access more methods if "spy" found
7a046af is described below

commit 7a046af94e9230b694dc839e0a0fc46b56803ed9
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 26 13:16:34 2021 +0800

    Access more methods if "spy" found
---
 src/main/java/groovy/lang/MetaClassImpl.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 7624e41..029deac 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -1207,7 +1207,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 throw mme;
             }
 
-            if (null == lookup) {
+            final boolean spyFound = null != lookup;
+            if (!spyFound) {
                 try {
                     lookup = MethodHandles.lookup().in(receiverClass);
                 } catch (IllegalArgumentException e) {
@@ -1217,6 +1218,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
             MethodHandles.Lookup tmpLookup = lookup;
             MethodHandle thisMethodHandle = findMethod(receiverClass, methodName, castArgumentsToClassArray(originalArguments), thisMethod -> {
                 try {
+                    if (spyFound) return tmpLookup.unreflectSpecial(thisMethod, receiverClass);
+
                     return tmpLookup.unreflect(thisMethod);
                 } catch (IllegalAccessException e) {
                     return null;