This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch GROOVY-11764 in repository https://gitbox.apache.org/repos/asf/groovy.git
commit d1485430e3b4d667484eae730ac03ec758a1651b 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 | 7 ++- src/test/groovy/bugs/Groovy11764.groovy | 50 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java index 6786d3cd7f..fb107c8bd1 100644 --- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java +++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java @@ -154,6 +154,7 @@ import static org.codehaus.groovy.ast.ClassHelper.isStringType; 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.inSamePackage; import static org.codehaus.groovy.ast.tools.GeneralUtils.maybeFallsThrough; import static org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX; import static org.codehaus.groovy.ast.tools.ParameterUtils.isVargs; @@ -1246,8 +1247,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) { diff --git a/src/test/groovy/bugs/Groovy11764.groovy b/src/test/groovy/bugs/Groovy11764.groovy new file mode 100644 index 0000000000..d6e0cf52d6 --- /dev/null +++ b/src/test/groovy/bugs/Groovy11764.groovy @@ -0,0 +1,50 @@ +/* + * 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.jupiter.api.Test + +import static groovy.test.GroovyAssert.assertScript + +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' + } + ''' + assertScript shell, ''' + class C extends p.B { + void test() { + assert super.value == 42 + } + } + + new C().test() + ''' + } +}
