-
Bug
-
Resolution: Fixed
-
P2
-
9
-
b151
The following program:
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class GetMethodTest {
static void test(Class<?> clazz) throws Exception {
System.out.println(clazz.getName() + ".class.getMethods(): " +
Stream
.of(clazz.getMethods())
.filter(m -> m.getDeclaringClass() != Object.class)
.collect(Collectors.toList()));
System.out.println(clazz.getName() + ".class.getMethod(\"m\"): " +
clazz.getMethod("m"));
}
public static void main(String[] args) throws Exception {
test(B.class);
}
}
interface I {
void m();
}
interface J extends I {
default void m() {}
}
abstract class A implements I {}
abstract class B extends A implements J {}
Prints:
B.class.getMethods(): [public default void J.m()]
B.class.getMethod("m"): public abstract void I.m()
I think that getMethods() gets it right. getMethod() stops searching (super)interfaces as soon as a method is found on superclass (here the superclass is A, which inherits I.m abstract method). It should consolidate this abstract method with possible default methods comming from (super)interfaces that might override this method.
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class GetMethodTest {
static void test(Class<?> clazz) throws Exception {
System.out.println(clazz.getName() + ".class.getMethods(): " +
Stream
.of(clazz.getMethods())
.filter(m -> m.getDeclaringClass() != Object.class)
.collect(Collectors.toList()));
System.out.println(clazz.getName() + ".class.getMethod(\"m\"): " +
clazz.getMethod("m"));
}
public static void main(String[] args) throws Exception {
test(B.class);
}
}
interface I {
void m();
}
interface J extends I {
default void m() {}
}
abstract class A implements I {}
abstract class B extends A implements J {}
Prints:
B.class.getMethods(): [public default void J.m()]
B.class.getMethod("m"): public abstract void I.m()
I think that getMethods() gets it right. getMethod() stops searching (super)interfaces as soon as a method is found on superclass (here the superclass is A, which inherits I.m abstract method). It should consolidate this abstract method with possible default methods comming from (super)interfaces that might override this method.
- csr of
-
CCC-8062389 Class.getMethod() is inconsistent with Class.getMethods() results
-
- Closed
-
- is blocked by
-
JDK-8061950 Class.getMethods() exhibits quadratic time complexity
-
- Resolved
-
- relates to
-
JDK-8029674 (reflect) getMethods returns default methods that are not members of the class
-
- Closed
-
-
JDK-8029459 (reflect) getMethods returns methods that are not members of the class
-
- Resolved
-
-
JDK-8171988 Backout of fix for 8062389, 8029459, 8061950
-
- Closed
-