You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/05/07 22:54:32 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-9501: enable access to
static, non-final, subclassed-outer fields
This is an automated email from the ASF dual-hosted git repository.
sunlan 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 b6dddc5 GROOVY-9501: enable access to static, non-final, subclassed-outer fields
b6dddc5 is described below
commit b6dddc52bccbbe8dd80c32d31e77296dede4814f
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
(cherry picked from commit c0a4b3d429327a691e6dfc9161b5e6cfe6132471)
---
.../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 5f5d905..a240869 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -1042,7 +1042,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 9f20b7e..8053754 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -393,6 +393,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 '''