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 2020/04/26 16:35:28 UTC

[groovy] branch GROOVY-9501 created (now 3f54561)

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

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


      at 3f54561  GROOVY-9501: enable access to static, non-final, subclassed-outer fields

This branch includes the following new commits:

     new 3f54561  GROOVY-9501: enable access to static, non-final, subclassed-outer fields

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: GROOVY-9501: enable access to static, non-final, subclassed-outer fields

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3f5456138f15a46c53c7e8b0a1a613cc27d6ab23
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Apr 26 11:25:46 2020 -0500

    GROOVY-9501: enable access to static, non-final, subclassed-outer fields
---
 .../groovy/classgen/AsmClassGenerator.java         |  2 +-
 src/test/gls/innerClass/InnerClassTest.groovy      | 72 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index b6225a0..d62c732 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -1039,7 +1039,7 @@ public class AsmClassGenerator extends ClassGenerator {
                     if (field == null && outer != null) {
                         do {
                             FieldNode outerClassField = outer.getDeclaredField(name);
-                            if (outerClassField != null && outerClassField.isStatic() && outerClassField.isFinal()) {
+                            if (outerClassField != null && outerClassField.isStatic()) {
                                 if (outerClassField.isPrivate() && classNode.getOuterClass() != outer) {
                                     throw new GroovyBugError("Trying to access private field [" + outerClassField.getDeclaringClass() + "#" + outerClassField.getName() + "] from inner class");
                                 }
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 6dc5e50..0044a40 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -395,6 +395,78 @@ final class InnerClassTest {
         '''
     }
 
+    @Test // GROOVY-9501
+    void testUsageOfOuterField7() {
+        assertScript '''
+            class Main extends Outer {
+                static main(args) {
+                    newInstance().newThread()
+                    assert Outer.Inner.error == null
+                }
+            }
+
+            abstract class Outer {
+                private static volatile boolean flag
+
+                void newThread() {
+                    Thread thread = new Inner()
+                    thread.start()
+                    thread.join()
+                }
+
+                private final class Inner extends Thread {
+                    @Override
+                    void run() {
+                        try {
+                            if (!flag) {
+                                // do work
+                            }
+                        } catch (e) {
+                            error = e
+                        }
+                    }
+                    public static error
+                }
+            }
+        '''
+    }
+
+    @Test  // inner class is static instead of final
+    void testUsageOfOuterField8() {
+        assertScript '''
+            class Main extends Outer {
+                static main(args) {
+                    newInstance().newThread()
+                    assert Outer.Inner.error == null
+                }
+            }
+
+            abstract class Outer {
+                private static volatile boolean flag
+
+                void newThread() {
+                    Thread thread = new Inner()
+                    thread.start()
+                    thread.join()
+                }
+
+                private static class Inner extends Thread {
+                    @Override
+                    void run() {
+                        try {
+                            if (!flag) {
+                                // do work
+                            }
+                        } catch (e) {
+                            error = e
+                        }
+                    }
+                    public static error
+                }
+            }
+        '''
+    }
+
     @Test
     void testUsageOfOuterFieldOverridden() {
         assertScript '''