You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/08/08 00:27:19 UTC

[groovy] branch master updated: GROOVY-10188: Different treatment of property expressions in closures from 2.4 to 2.5

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

paulk 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 e534e47  GROOVY-10188: Different treatment of property expressions in closures from 2.4 to 2.5
e534e47 is described below

commit e534e47b3f07825336ab3658c065c10a9f20e497
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Aug 8 10:27:03 2021 +1000

    GROOVY-10188: Different treatment of property expressions in closures from 2.4 to 2.5
---
 src/main/java/org/codehaus/groovy/control/ResolveVisitor.java |  1 +
 src/test/groovy/lang/PropertyMissingTest.groovy               | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 24ac563..fab333d 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -951,6 +951,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             }
             Tuple2<StringBuilder, Boolean> classNameInfo = makeClassName(doInitialClassTest, name, property);
             name = classNameInfo.getV1();
+            if (name == null) return null;
             doInitialClassTest = classNameInfo.getV2();
         }
 
diff --git a/src/test/groovy/lang/PropertyMissingTest.groovy b/src/test/groovy/lang/PropertyMissingTest.groovy
index 3dcbbb0..8410c11 100644
--- a/src/test/groovy/lang/PropertyMissingTest.groovy
+++ b/src/test/groovy/lang/PropertyMissingTest.groovy
@@ -98,6 +98,17 @@ class PropertyMissingTest extends GroovyTestCase {
 
     }
 
+    void testClassDotProperty() {
+        assert shouldFail(MissingPropertyException, "Integer.xxx") ==
+                'No such property: xxx for class: java.lang.Integer'
+    }
+
+    void testClassDotPropertyInClosure() {
+        // GROOVY-10188: strange looking parameter in Closure to force a particular edge case
+        assert shouldFail(NullPointerException, "{ Integer -> Integer.xxx }()") ==
+                "Cannot get property 'xxx' on null object"
+    }
+
 }
 
 class PMTest1 {