You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2024/04/24 19:09:44 UTC

(groovy) branch GROOVY_3_0_X updated: GROOVY-11360: STC: fix for NPE

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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new b87d2dc983 GROOVY-11360: STC: fix for NPE
b87d2dc983 is described below

commit b87d2dc983caf033e0405818fdf43082e753b511
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Apr 24 14:10:37 2024 -0500

    GROOVY-11360: STC: fix for NPE
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  4 +++-
 .../groovy/transform/stc/ClosuresSTCTest.groovy    | 24 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 9da79a987a..39a106ac0e 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1640,7 +1640,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                     pexp.putNodeMetaData(DYNAMIC_RESOLUTION, Boolean.TRUE);
                     pexp.removeNodeMetaData(DECLARATION_INFERRED_TYPE);
                     pexp.removeNodeMetaData(INFERRED_TYPE);
-                    visitor.visitMethod(mopMethod);
+                    if (visitor != null) {
+                        visitor.visitMethod(mopMethod);
+                    }
                     return true;
                 }
             }
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 93a9f69102..b7e33b4fd2 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -716,6 +716,30 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-11360
+    void testLexicalScopeVersusGetDynamicProperty() {
+        assertScript '''
+            class C {
+                private static final value = "C"
+
+                def m(D d) {
+                    d.with {
+                        return value
+                    }
+                }
+            }
+
+            class D {
+                def get(String name) {
+                    if (name == "value") "D"
+                }
+            }
+
+            String result = new C().m(new D())
+            assert result == 'C'
+        '''
+    }
+
     // GROOVY-9089
     void testOwnerVersusDelegateFromNestedClosure() {
         String declarations = '''