You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/12/13 20:59:12 UTC
[groovy] branch master updated: GROOVY-8164: MetaMethodIndex: no inherit private/static interface method
This is an automated email from the ASF dual-hosted git repository.
emilles 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 feb9987 GROOVY-8164: MetaMethodIndex: no inherit private/static interface method
feb9987 is described below
commit feb9987cc334751896c0edd6eb1bc53b32e3f397
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Dec 13 14:59:01 2021 -0600
GROOVY-8164: MetaMethodIndex: no inherit private/static interface method
JLS 8.4.8: A class does not inherit static methods from superinterfaces.
---
src/main/java/groovy/lang/MetaClassImpl.java | 8 ++--
src/test/groovy/bugs/Groovy8164.java | 61 ++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 972b3bb..9e6199c 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -364,7 +364,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
for (CachedClass c : interfaces) {
for (CachedMethod m : c.getMethods()) {
- addMetaMethodToIndex(m, mainClassMethodHeader);
+ if (c == theCachedClass || (m.isPublic() && !m.isStatic())) { // GROOVY-8164
+ addMetaMethodToIndex(m, mainClassMethodHeader);
+ }
}
}
@@ -3535,8 +3537,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
return false;
}
- private void addToAllMethodsIfPublic(MetaMethod metaMethod) {
- if (Modifier.isPublic(metaMethod.getModifiers()))
+ private void addToAllMethodsIfPublic(final MetaMethod metaMethod) {
+ if (metaMethod.isPublic())
allMethods.add(metaMethod);
}
diff --git a/src/test/groovy/bugs/Groovy8164.java b/src/test/groovy/bugs/Groovy8164.java
new file mode 100644
index 0000000..7fd4628
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8164.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+import static groovy.test.GroovyAssert.shouldFail;
+
+public final class Groovy8164 {
+
+ public interface I {
+ static String m() {
+ return "I";
+ }
+ }
+
+ public interface J {
+ static String m() {
+ return "J";
+ }
+ }
+
+ @Test
+ public void testStaticMethods1() throws Exception {
+ shouldFail(groovy.lang.MissingMethodException.class,
+ "class C implements " + I.class.getName() + ", " + J.class.getName() + " {\n" +
+ "}\n" +
+ "C.m()\n"
+ );
+ }
+
+ @Test
+ public void testStaticMethods2() throws Exception {
+ assertScript(
+ "class C implements " + I.class.getName() + ", " + J.class.getName() + " {\n" +
+ " static m() { 'C' }\n" +
+ "}\n" +
+ "class D extends C {\n" +
+ "}\n" +
+ "assert C.m() == 'C'\n" +
+ "assert D.m() == 'C'\n"
+ );
+ }
+}