groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject [1/2] groovy git commit: Fix NPE if accessed property not a member of the owning class (closes #724)
Date Sat, 26 May 2018 03:43:21 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 076d31e70 -> 12c2eb6cf


Fix NPE if accessed property not a member of the owning class (closes #724)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/12c2eb6c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/12c2eb6c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/12c2eb6c

Branch: refs/heads/GROOVY_2_6_X
Commit: 12c2eb6cf0c55d9d637d7e04bc1db862a21b878c
Parents: 81351b7
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Fri May 25 13:16:18 2018 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Fri May 25 20:41:53 2018 -0700

----------------------------------------------------------------------
 .../transform/stc/StaticTypeCheckingVisitor.java | 11 +++++++----
 .../typing/TypeCheckingExtensionSpecTest.groovy  | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/12c2eb6c/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
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 874ec95..d1b3669 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -611,10 +611,13 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                     if (vexp.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER) == null)
{
                         ClassNode owner = (ClassNode) vexp.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
                         if (owner != null) {
-                            boolean lhsOfEnclosingAssignment = isLHSOfEnclosingAssignment(vexp);
-                            fieldNode = owner.getField(vexp.getName());
-                            vexp.setAccessedVariable(fieldNode);
-                            checkOrMarkPrivateAccess(vexp, fieldNode, lhsOfEnclosingAssignment);
+                            FieldNode veFieldNode = owner.getField(vexp.getName());
+                            if (veFieldNode != null) {
+                                fieldNode = veFieldNode;
+                                boolean lhsOfEnclosingAssignment = isLHSOfEnclosingAssignment(vexp);
+                                vexp.setAccessedVariable(fieldNode);
+                                checkOrMarkPrivateAccess(vexp, fieldNode, lhsOfEnclosingAssignment);
+                            }
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/12c2eb6c/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy b/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy
index e6b310e..cb1e4fa 100644
--- a/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy
+++ b/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy
@@ -587,6 +587,25 @@ new DelegateTest().delegate()
 '''
     }
 
+    void testDelegateVariableFromDifferentOwningClass() {
+        assertScript '''
+        @groovy.transform.CompileStatic
+        class A {
+            static private int MAX_LINES = 2
+            static class B {
+                @Delegate
+                private Map<String, Object> delegate = [:]
+                void m(int c) {
+                    if (c > MAX_LINES) {
+                        return
+                    }
+                }
+            }
+        }
+        null
+        '''
+    }
+
     private static class SpecSupport {
         static int getLongueur(String self) { self.length() }
         static int longueur(String self) { self.length() }


Mime
View raw message