This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY-11803
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-11803 by this push:
new a8d8956787 GROOVY-11803: index stray property methods for interface
with default
a8d8956787 is described below
commit a8d8956787f27a726ed496524823da0780bcd36f
Author: Eric Milles <[email protected]>
AuthorDate: Wed Nov 19 14:37:58 2025 -0600
GROOVY-11803: index stray property methods for interface with default
---
src/main/java/groovy/lang/MetaClassImpl.java | 5 +++++
src/test/groovy/groovy/InterfaceTest.groovy | 17 +++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java
b/src/main/java/groovy/lang/MetaClassImpl.java
index 317ca86f47..56850416e4 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -360,6 +360,9 @@ public class MetaClassImpl implements MetaClass,
MutableMetaClass {
if (c == theCachedClass || (m.isPublic() && !m.isStatic())) {
// GROOVY-8164
addMetaMethodToIndex(m, mainClassMethodHeader);
}
+ if (c != theCachedClass && (m.isPublic() && !m.isStatic())) {
// GROOVY-11803
+ metaMethodIndex.addMetaMethod(m,
metaMethodIndex.indexMap.computeIfAbsent(c.getTheClass(), k -> new
ConcurrentHashMap<>()));
+ }
}
}
@@ -2354,6 +2357,7 @@ public class MetaClassImpl implements MetaClass,
MutableMetaClass {
applyPropertyDescriptors(propertyDescriptors);
applyStrayPropertyMethods(superClasses, classPropertyIndex, true);
+ applyStrayPropertyMethods(superInterfaces, classPropertyIndex,
true);
applyStrayPropertyMethods(superClasses,
classPropertyIndexForSuper, false);
}
fillStaticPropertyIndex();
@@ -2504,6 +2508,7 @@ public class MetaClassImpl implements MetaClass,
MutableMetaClass {
*/
private void applyStrayPropertyMethods(CachedClass source, Map<String,
MetaProperty> target, boolean isThis) {
var header = metaMethodIndex.getHeader(source.getTheClass());
+ if (header == null) return;
for (MetaMethodIndex.Cache e : header.values()) {
String methodName = e.name;
int methodNameLength = methodName.length();
diff --git a/src/test/groovy/groovy/InterfaceTest.groovy
b/src/test/groovy/groovy/InterfaceTest.groovy
index 629c141552..ab1e7a6888 100644
--- a/src/test/groovy/groovy/InterfaceTest.groovy
+++ b/src/test/groovy/groovy/InterfaceTest.groovy
@@ -78,6 +78,23 @@ final class InterfaceTest extends CompilableTestSupport {
assert err.contains('The interface Comparable cannot be implemented
more than once with different arguments: java.lang.Comparable (via B) and
java.lang.Comparable<java.lang.Object> (via A)')
}
+ // GROOVY-11803
+ void testDefaultInterfaceMethod() {
+ assertScript '''
+ interface Foo {
+ default int barSize() { bar.size() }
+ String getBar()
+ }
+ class Baz implements Foo {
+ String getBar() {
+ 'BAR'
+ }
+ }
+
+ assert new Baz().barSize() == 3
+ '''
+ }
+
// GROOVY-10060
void testPrivateInterfaceMethod() {
assertScript '''