From 145bf1d53d10de5e348a1000d117a496648dd783 Mon Sep 17 00:00:00 2001 From: Daniel Sun Date: Fri, 27 Dec 2024 22:10:41 +0900 Subject: [PATCH] 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 7082be61dff..8524901aff4 100644 --- a/src/main/java/groovy/lang/Closure.java +++ b/src/main/java/groovy/lang/Closure.java @@ -364,12 +364,14 @@ private Object getProperty(final Object receiver, final String property) { 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 @@ private void setProperty(final Object receiver, final String property, final Obj 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;