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

emilles pushed a commit to branch GROOVY-8283
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY-8283 by this push:
     new a9a1fc4477 GROOVY-8283: propagate sender class for `getProperty` and 
`setProperty`
a9a1fc4477 is described below

commit a9a1fc44774a3e311d9c7a709e899c03affbcbaf
Author: Eric Milles <eric.mil...@thomsonreuters.com>
AuthorDate: Mon Dec 9 12:31:11 2024 -0600

    GROOVY-8283: propagate sender class for `getProperty` and `setProperty`
---
 .../java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java     | 5 +++--
 src/test/groovy/bugs/Groovy8283.groovy                              | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java 
b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
index d8d6020c70..749636e343 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
@@ -467,7 +467,8 @@ public class ScriptBytecodeAdapter {
 
     public static Object getProperty(Class senderClass, Object receiver, 
String messageName) throws Throwable {
         try {
-            if (receiver instanceof GroovyObject) {
+            if (receiver instanceof GroovyObject && 
!receiver.getClass().getMethod("getProperty", String.class).isDefault()) {
+                // TODO: instead of checking for no getProperty 
specialization, pass senderClass in ThreadLocal or something
                 var groovyObject = (GroovyObject) receiver;
                 return groovyObject.getProperty(messageName);
             } else {
@@ -499,7 +500,7 @@ public class ScriptBytecodeAdapter {
 
     public static void setProperty(Object messageArgument, Class senderClass, 
Object receiver, String messageName) throws Throwable {
         try {
-            if (receiver instanceof GroovyObject) {
+            if (receiver instanceof GroovyObject && 
!receiver.getClass().getMethod("setProperty", String.class, 
Object.class).isDefault()) {
                 var groovyObject = (GroovyObject) receiver;
                 groovyObject.setProperty(messageName, messageArgument);
             } else {
diff --git a/src/test/groovy/bugs/Groovy8283.groovy 
b/src/test/groovy/bugs/Groovy8283.groovy
index fc34722f4a..2d7f8b3dbb 100644
--- a/src/test/groovy/bugs/Groovy8283.groovy
+++ b/src/test/groovy/bugs/Groovy8283.groovy
@@ -223,6 +223,12 @@ final class Groovy8283 {
             new E().test3()
             new E().test4()
             new E().test5()
+
+            def e = new E()
+            e.foo = null // not the field from this perspective
+            assert e.setter
+            assert e.fooA == null
+            assert e.fooB != null
         '''
     }
 }

Reply via email to