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 2024/12/27 13:10:56 UTC

(groovy) branch master updated: Trivial refactoring: extract common variable

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 145bf1d53d Trivial refactoring: extract common variable
145bf1d53d is described below

commit 145bf1d53d10de5e348a1000d117a496648dd783
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Dec 27 22:10:41 2024 +0900

    Trivial refactoring: extract common variable
---
 src/main/java/groovy/lang/Closure.java | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/main/java/groovy/lang/Closure.java b/src/main/java/groovy/lang/Closure.java
index 7082be61df..8524901aff 100644
--- a/src/main/java/groovy/lang/Closure.java
+++ b/src/main/java/groovy/lang/Closure.java
@@ -364,12 +364,14 @@ public abstract class Closure<V> extends GroovyObjectSupport implements Cloneabl
         try {
             return InvokerHelper.getProperty(receiver, property);
         } catch (GroovyRuntimeException e1) {
-            if (null != receiver && this != receiver && this instanceof GeneratedClosure
-                    && getThisType() != receiver.getClass() && getThisType().isInstance(receiver)) { // GROOVY-11128
-                try {
-                    return ((GroovyObject) receiver).getMetaClass().getProperty(getThisType(), receiver, property, false, true);
-                } catch (GroovyRuntimeException e2) {
-                    e1.addSuppressed(e2);
+            if (null != receiver && this != receiver && this instanceof GeneratedClosure) { // GROOVY-11128
+                final Class<?> thisType = getThisType();
+                if (thisType != receiver.getClass() && thisType.isInstance(receiver)) {
+                    try {
+                        return ((GroovyObject) receiver).getMetaClass().getProperty(thisType, receiver, property, false, true);
+                    } catch (GroovyRuntimeException e2) {
+                        e1.addSuppressed(e2);
+                    }
                 }
             }
             throw e1;
@@ -395,13 +397,15 @@ public abstract class Closure<V> extends GroovyObjectSupport implements Cloneabl
         try {
             InvokerHelper.setProperty(receiver, property, newValue);
         } catch (GroovyRuntimeException e1) {
-            if (null != receiver && this != receiver && this instanceof GeneratedClosure
-                    && getThisType() != receiver.getClass() && getThisType().isInstance(receiver)) { // GROOVY-11128
-                try {
-                    ((GroovyObject) receiver).getMetaClass().setProperty(getThisType(), receiver, property, newValue, false, true);
-                    return;
-                } catch (GroovyRuntimeException e2) {
-                    e1.addSuppressed(e2);
+            if (null != receiver && this != receiver && this instanceof GeneratedClosure) { // GROOVY-11128
+                final Class<?> thisType = getThisType();
+                if (thisType != receiver.getClass() && thisType.isInstance(receiver)) {
+                    try {
+                        ((GroovyObject) receiver).getMetaClass().setProperty(thisType, receiver, property, newValue, false, true);
+                        return;
+                    } catch (GroovyRuntimeException e2) {
+                        e1.addSuppressed(e2);
+                    }
                 }
             }
             throw e1;