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 2020/07/01 16:10:32 UTC
[groovy] branch master updated: GROOVY-9611: Reflexive access to
class attributes broken in Groovy 3
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 5e3b4fd GROOVY-9611: Reflexive access to class attributes broken in Groovy 3
5e3b4fd is described below
commit 5e3b4fd7c5223f4e223d1d23e25e83a41b10fc36
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Jul 2 00:51:44 2020 +1000
GROOVY-9611: Reflexive access to class attributes broken in Groovy 3
---
src/test/groovy/bugs/Groovy9611.groovy | 41 ++++++++++++++++++++++
.../apache/groovy/parser/antlr4/AstBuilder.java | 2 +-
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/src/test/groovy/bugs/Groovy9611.groovy b/src/test/groovy/bugs/Groovy9611.groovy
new file mode 100644
index 0000000..ba20083
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9611.groovy
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy9611 {
+ @Test
+ void testAccessFieldWithinAICUsingReflection() {
+ assertScript '''
+ import java.lang.reflect.Field
+ class C {
+ int method() {
+ for (Field f : getClass().fields)
+ if (f.name == 'i') return f.get(this)
+ return -1
+ }
+ }
+ def c = new C() { public int i = 42 }
+ assert c.method() == 42
+ '''
+ }
+}
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 6b69578..d138716 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -3240,7 +3240,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
// and remove the final modifier from classNode to allow the sub class
superClass.setModifiers(superClass.getModifiers() & ~Opcodes.ACC_FINAL);
} else { // anonymous inner class
- anonymousInnerClass = new InnerClassNode(outerClass, innerClassName, 0, superClass);
+ anonymousInnerClass = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, superClass);
}
anonymousInnerClass.setUsingGenerics(false);