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 34e9abed5a GROOVY-11764: do not visit super class field if it is
package-private
34e9abed5a is described below
commit 34e9abed5a93ab0ce6fcaa7f97b8e162ffc0e481
Author: Eric Milles <[email protected]>
AuthorDate: Tue Nov 25 13:29:54 2025 -0600
GROOVY-11764: do not visit super class field if it is package-private
---
.../groovy/classgen/AsmClassGenerator.java | 8 ++--
src/test/groovy/bugs/Groovy11764.groovy | 48 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 033269ab63..fcf3763f95 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -133,6 +133,7 @@ import static
org.codehaus.groovy.ast.tools.GeneralUtils.callX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.fieldX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.getSetterName;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.inSamePackage;
import static org.codehaus.groovy.ast.tools.GeneralUtils.isOrImplements;
import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX;
@@ -1109,9 +1110,10 @@ public class AsmClassGenerator extends ClassGenerator {
}
} else {
fieldNode =
classNode.getSuperClass().getDeclaredField(name);
- // GROOVY-4497: do not visit super class field if it is
private
- if (fieldNode != null && fieldNode.isPrivate()) fieldNode
= null;
-
+ // GROOVY-4497, GROOVY-11764: do not visit super class
field if it is private or package-private
+ if (fieldNode != null && (fieldNode.isPrivate() ||
!(fieldNode.isPublic() || fieldNode.isProtected() || inSamePackage(classNode,
classNode.getSuperClass())))) {
+ fieldNode = null;
+ }
if (fieldNode == null) {
visited = tryPropertyOfSuperClass(expression, name);
}
diff --git a/src/test/groovy/bugs/Groovy11764.groovy
b/src/test/groovy/bugs/Groovy11764.groovy
new file mode 100644
index 0000000000..bbd60ff1e2
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy11764.groovy
@@ -0,0 +1,48 @@
+/*
+ * 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 bugs
+
+import org.junit.Test
+
+final class Groovy11764 {
+
+ @Test
+ void testReadFieldPropertyShadowing() {
+ def shell = new GroovyShell()
+ shell.parse '''package p
+ class A {
+ Number getValue() {
+ 42
+ }
+ }
+ class B extends A {
+ @groovy.transform.PackageScope String value = 'xx'
+ }
+ '''
+ shell.evaluate '''
+ class C extends p.B {
+ void test() {
+ assert super.value == 42
+ }
+ }
+
+ new C().test()
+ '''
+ }
+}