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/08/29 07:32:49 UTC

[groovy] branch master updated: Trivial tweak: avoid redundant access permission checking

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

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 75acd5a  Trivial tweak: avoid redundant access permission checking
75acd5a is described below

commit 75acd5a61cafce332215308bdb13cd6b233cf172
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Aug 29 12:46:04 2021 +0800

    Trivial tweak: avoid redundant access permission checking
---
 .../groovy/reflection/CachedConstructor.java       |  7 +++++-
 .../codehaus/groovy/reflection/CachedMethod.java   | 25 ++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java b/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
index 0a4dd85..1546bd4 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
@@ -115,7 +115,10 @@ public class CachedConstructor extends ParameterTypes {
 
     public Constructor getCachedConstructor() {
         makeAccessibleIfNecessary();
-        AccessPermissionChecker.checkAccessPermission(cachedConstructor);
+        if (!accessAllowed) {
+            AccessPermissionChecker.checkAccessPermission(cachedConstructor);
+            accessAllowed = true;
+        }
         return cachedConstructor;
     }
 
@@ -130,4 +133,6 @@ public class CachedConstructor extends ParameterTypes {
     private boolean isConstructorOfAbstractClass() {
         return Modifier.isAbstract(cachedConstructor.getDeclaringClass().getModifiers());
     }
+
+    private boolean accessAllowed = false;
 }
diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java b/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java
index f8aae2d..838db6a 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java
@@ -103,11 +103,15 @@ public class CachedMethod extends MetaMethod implements Comparable {
     public final Object invoke(Object object, Object[] arguments) {
         makeAccessibleIfNecessary();
 
-        try {
-            AccessPermissionChecker.checkAccessPermission(cachedMethod);
-        } catch (CacheAccessControlException ex) {
-            throw new InvokerInvocationException(ex);
+        if (!accessAllowed) {
+            try {
+                AccessPermissionChecker.checkAccessPermission(cachedMethod);
+                accessAllowed = true;
+            } catch (CacheAccessControlException ex) {
+                throw new InvokerInvocationException(ex);
+            }
         }
+
         try {
             return cachedMethod.invoke(object, arguments);
         } catch (IllegalArgumentException | IllegalAccessException e) {
@@ -146,7 +150,11 @@ public class CachedMethod extends MetaMethod implements Comparable {
     public final Method setAccessible() {
         makeAccessibleIfNecessary();
 
-        AccessPermissionChecker.checkAccessPermission(cachedMethod);
+        if (!accessAllowed) {
+            AccessPermissionChecker.checkAccessPermission(cachedMethod);
+            accessAllowed = true;
+        }
+
 //        if (queuedToCompile.compareAndSet(false,true)) {
 //            if (isCompilable())
 //              CompileThread.addMethod(this);
@@ -372,7 +380,10 @@ public class CachedMethod extends MetaMethod implements Comparable {
 
     public Method getCachedMethod() {
         makeAccessibleIfNecessary();
-        AccessPermissionChecker.checkAccessPermission(cachedMethod);
+        if (!accessAllowed) {
+            AccessPermissionChecker.checkAccessPermission(cachedMethod);
+            accessAllowed = true;
+        }
         return cachedMethod;
     }
 
@@ -387,4 +398,6 @@ public class CachedMethod extends MetaMethod implements Comparable {
             makeAccessibleDone = true;
         }
     }
+
+    private boolean accessAllowed = false;
 }