--- old/test/java/lang/Class/getMethods/StarInheritance.java 2015-03-29 13:30:29.342149141 +0200 +++ new/test/java/lang/Class/getMethods/StarInheritance.java 2015-03-29 13:30:29.202151598 +0200 @@ -30,6 +30,9 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; // D.m interface A1 extends B1, C1 {} @@ -55,21 +58,41 @@ interface C4 extends D4 {} interface D4 { void m(); } +// D.m +abstract class A_1 extends B_1 implements C1 {} +abstract class B_1 implements D1 {} + +// A_.m +abstract class A_2 extends B_2 implements C2 { public abstract void m(); } +abstract class B_2 implements D2 {} + +// B_.m, C.m +abstract class A_3 extends B_3 implements C3 {} +abstract class B_3 implements D3 { public abstract void m(); } + +// B_.m, D.m +abstract class A_4 extends B_4 implements C4 {} +abstract class B_4 implements D4 { public abstract void m(); } + public class StarInheritance { private static int n = 1; - private static void test(Method [] ma, ArrayList expect) { + private static void test(Method [] ma, ArrayList> expect) { + // filter out Object methods + List ml = Stream.of(ma) + .filter(m -> m.getDeclaringClass() != Object.class) + .collect(Collectors.toList()); + System.out.println("Test " + n++); - if (expect.size() != ma.length) { - System.err.println(" found methods: " + Arrays.asList(ma)); + if (expect.size() != ml.size()) { + System.err.println(" found methods: " + ml); System.err.println(" expected locations: " + expect); - throw new RuntimeException("found = " + ma.length + throw new RuntimeException("found = " + ml.size() +"; expected = " + expect.size()); } - for (int i = 0; i < ma.length; i++) { - Method m = ma[i]; + for (Method m : ml) { System.out.println(" " + m.toString()); int n; if (m.getName().equals("m") @@ -83,16 +106,28 @@ } public static void main(String [] args) { - Class [] l1 = {D1.class}; - test(A1.class.getMethods(), new ArrayList(Arrays.asList(l1))); + Class [] l1 = {D1.class}; + test(A1.class.getMethods(), new ArrayList<>(Arrays.asList(l1))); + + Class [] l2 = {A2.class}; + test(A2.class.getMethods(), new ArrayList<>(Arrays.asList(l2))); + + Class [] l3 = {B3.class, C3.class}; + test(A3.class.getMethods(), new ArrayList<>(Arrays.asList(l3))); + + Class [] l4 = {B4.class, D4.class}; + test(A4.class.getMethods(), new ArrayList<>(Arrays.asList(l4))); + + Class [] l_1 = {D1.class}; + test(A_1.class.getMethods(), new ArrayList<>(Arrays.asList(l_1))); - Class [] l2 = {A2.class}; - test(A2.class.getMethods(), new ArrayList(Arrays.asList(l2))); + Class [] l_2 = {A_2.class}; + test(A_2.class.getMethods(), new ArrayList<>(Arrays.asList(l_2))); - Class [] l3 = {B3.class, C3.class}; - test(A3.class.getMethods(), new ArrayList(Arrays.asList(l3))); + Class [] l_3 = {B_3.class, C3.class}; + test(A_3.class.getMethods(), new ArrayList<>(Arrays.asList(l_3))); - Class [] l4 = {B4.class, D4.class}; - test(A4.class.getMethods(), new ArrayList(Arrays.asList(l4))); + Class [] l_4 = {B_4.class, D4.class}; + test(A_4.class.getMethods(), new ArrayList<>(Arrays.asList(l_4))); } }