/******************************************************************************* * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann - Contribution for * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract * bug 399567 - [1.8] Different error message from the reference compiler * bug 401796 - [1.8][compiler] don't treat default methods as overriding an independent inherited abstract method * bug 395681 - [compiler] Improve simulation of javac6 behavior from bug 317719 after fixing bug 388795 * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) * Bug 423505 - [1.8] Implement "18.5.4 More Specific Method Inference" *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; import java.util.Map; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import junit.framework.*; @SuppressWarnings({ "unchecked", "rawtypes" }) public class AmbiguousMethodTest extends AbstractComparableTest { static { // TESTS_NAMES = new String [] { "test010a" }; } public AmbiguousMethodTest(String name) { super(name); } public static Test suite() { return buildComparableTestSuite(testClass()); } public static Class testClass() { return AmbiguousMethodTest.class; } protected Map getCompilerOptions() { Map compilerOptions = super.getCompilerOptions(); compilerOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); return compilerOptions; } public void test000() { this.runConformTest( new String[] { "Test.java", "public class Test { public static void main(String[] args) { new B().foo(new C()); } }\n" + "class A { void foo(A a) {} }\n" + "class B extends A { void foo(B b) { System.out.println(1); } }\n" + "class C extends B {}" }, "1" ); } public void test000a() { this.runConformTest( new String[] { "Test.java", "public class Test { public static void main(String[] args) { new Subtype().foo(1, \"works\"); } }\n" + "class Supertype { void foo(U1 u, T1 t) {} }\n" + "class Subtype extends Supertype { void foo(U3 u, T2 t) { System.out.println(t); } }" }, "works" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 public void test001() { this.runConformTest( new String[] { "C.java", "public class C { public static void main(String[] args) { new B().m(\"works\"); } }\n" + "class B extends A { @Override > void m(T t) { System.out.println(t); } }\n" + "abstract class A { abstract > void m(T t); }" }, "works" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 public void test002() { if (this.complianceLevel < ClassFileConstants.JDK1_7) { this.runConformTest( new String[] { "X.java", "public class X {\n" + " static interface I1 { void method(E1 o); }\n" + " static interface I2 { void method(E2 o); }\n" + " static interface I3 extends I1, I2 {}\n" + " static class Class1 implements I3 {\n" + " public void method(String o) { System.out.println(o); }\n" + " }\n" + " public static void main(String[] args) {\n" + " I3 i = new Class1();\n" + " i.method(\"works\");\n" + " }\n" + "}" }, "works"); } else { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " static interface I1 { void method(E1 o); }\n" + " static interface I2 { void method(E2 o); }\n" + " static interface I3 extends I1, I2 {}\n" + " static class Class1 implements I3 {\n" + " public void method(String o) { System.out.println(o); }\n" + " }\n" + " public static void main(String[] args) {\n" + " I3 i = new Class1();\n" + " i.method(\"works\");\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 4)\n" + " static interface I3 extends I1, I2 {}\n" + " ^^\n" + "Name clash: The method method(E2) of type X.I2 has the same erasure as method(E1) of type X.I1 but does not override it\n" + "----------\n"); } } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 public void test002a() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " static interface I1 { void method(E o); }\n" + " static interface I2 { void method(E o); }\n" + " static interface I3 extends I1, I2 {}\n" + " static class Class1 implements I3 {\n" + " public void method(String o) { System.out.println(o); }\n" + " }\n" + " public static void main(String[] args) {\n" + " I3 i = new Class1();\n" + " i.method(\"works\");\n" + " }\n" + "}" }, "works" ); } public void test003() { this.runNegativeTest( new String[] { "X.java", "public class X { void foo() { new BB().test(); } }\n" + "class AA { void test() {} }\n" + "class BB extends AA { void test() {} }\n" + "class CC {}\n", }, "----------\n" + "1. ERROR in X.java (at line 1)\n" + " public class X { void foo() { new BB().test(); } }\n" + " ^^^^\n" + "The method test() is ambiguous for the type BB\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " class BB extends AA { void test() {} }\n" + " ^^^^^^\n" + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + "----------\n" ); } public void test003a() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void singleMatch() { System.out.print(new BB().test(new N(), new Integer(1))); }\n" + " void betterMatch() { System.out.print(new CC().test(new N(), new Integer(1))); }\n" + " void worseMatch() { System.out.print(new DD().test(new N(), new Integer(1))); }\n" + " public static void main(String[] s) {\n" + " new X().singleMatch();\n" + " new X().betterMatch();\n" + " new X().worseMatch();\n" + " }\n" + "}\n" + "class AA { int test(T t, Number num) { return 1; } }\n" + "class BB extends AA { @Override int test(N n, Number num) { return 2; } }\n" + "class CC extends AA { int test(N n, U u) { return 3; } }\n" + "class DD extends AA { int test(M m, U u) { return 4; } }\n" + "class M {}\n" + "class N extends M {}", }, "231" ); } public void test003b() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void ambiguous() { new BB().test(new N()); }\n" + " void exactMatch() { new CC().test(new N()); }\n" + "}\n" + "class AA { void test(T t) {} }\n" + "class BB extends AA { void test(N n) {} }\n" + "class CC extends AA { @Override void test(N n) {} }\n" + "class M {}\n" + "class N extends M {}", }, "----------\n" + "1. ERROR in X.java (at line 2)\r\n" + " void ambiguous() { new BB().test(new N()); }\r\n" + " ^^^^\n" + "The method test(N) is ambiguous for the type BB\n" + "----------\n" ); } public void test003c() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void ambiguous() { new BB().test(new N(), new Integer(1)); }\n" + "}\n" + "class AA { void test(T t, Integer i) {} }\n" + "class BB extends AA { void test(N n, U u) {} }\n" + "class M {}\n" + "class N extends M {}", }, "----------\n" + "1. ERROR in X.java (at line 2)\n" + " void ambiguous() { new BB().test(new N(), new Integer(1)); }\n" + " ^^^^\n" + "The method test(N, Integer) is ambiguous for the type BB\n" + "----------\n" ); } public void test004() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void test(M m) {\n" + " m.id(new Integer(111));\n" + " }\n" + "}\n" + "class C { public void id(T t) {} }\n" + "class M extends C { public void id(Integer i) {} }\n" }, "----------\n" + "1. ERROR in X.java (at line 3)\n" + " m.id(new Integer(111));\n" + " ^^\n" + "The method id(Integer) is ambiguous for the type M\n" + "----------\n" // reference to id is ambiguous, both method id(A) in C and method id(B) in M match ); } public void test004a() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void test(M m) {\n" + " m.id(new Integer(111));\n" + " }\n" + "}\n" + "class C { public void id(T t) {} }\n" + "class M extends C { public void id(Integer i) {} }\n" }, "" ); } public void test005() { // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. WARNING in X.java (at line 2)\n" + " void foo() { }\n" + " ^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" + "2. WARNING in X.java (at line 3)\n" + " N foo() { return null; }\n" + " ^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" + "3. ERROR in X.java (at line 5)\n" + " new X().foo();\n" + " ^^^\n" + "The method foo() is ambiguous for the type X\n" + "----------\n": "----------\n" + "1. ERROR in X.java (at line 2)\n" + " void foo() { }\n" + " ^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " N foo() { return null; }\n" + " ^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n"; this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void foo() { }\n" + " N foo() { return null; }\n" + " void test () {\n" + " new X().foo();\n" + " }\n" + "}\n" + "class A {}\n" + "class B {}\n" }, expectedCompilerLog); /* javac 7 X.java:3: name clash: foo() and foo() have the same erasure N foo() { return null; } ^ where N,S are type-variables: N extends B declared in method foo() S extends A declared in method foo() 1 error */ } public void test006() { // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. ERROR in X.java (at line 3)\n" + " new Y().foo(\"X\");\n" + " ^^^\n" + "The method foo(Object) is ambiguous for the type Y\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " new Y().foo2(\"X\");\n" + " ^^^^\n" + "The method foo2(Object) is ambiguous for the type Y\n" + "----------\n" + "3. WARNING in X.java (at line 10)\n" + " void foo(T2 t) {}\n" + " ^^^^^^^^^\n" + "Name clash: The method foo(T2) of type Y has the same erasure as foo(U1) of type X but does not override it\n" + "----------\n" + "4. WARNING in X.java (at line 11)\n" + " void foo2(T2 t) {}\n" + " ^^^^^^^^^^\n" + "Name clash: The method foo2(T2) of type Y has the same erasure as foo2(U2) of type X but does not override it\n" + "----------\n": "----------\n" + "1. ERROR in X.java (at line 3)\n" + " new Y().foo(\"X\");\n" + " ^^^\n" + "The method foo(Object) is ambiguous for the type Y\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " new Y().foo2(\"X\");\n" + " ^^^^\n" + "The method foo2(Object) is ambiguous for the type Y\n" + "----------\n" + "3. ERROR in X.java (at line 10)\n" + " void foo(T2 t) {}\n" + " ^^^^^^^^^\n" + "Name clash: The method foo(T2) of type Y has the same erasure as foo(U1) of type X but does not override it\n" + "----------\n" + "4. ERROR in X.java (at line 11)\n" + " void foo2(T2 t) {}\n" + " ^^^^^^^^^^\n" + "Name clash: The method foo2(T2) of type Y has the same erasure as foo2(U2) of type X but does not override it\n" + "----------\n"; this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void test() {\n" + " new Y().foo(\"X\");\n" + " new Y().foo2(\"X\");\n" + " }\n" + " U1 foo(U1 t) {return null;}\n" + " U2 foo2(U2 t) {return null;}\n" + "}\n" + "class Y extends X {\n" + " void foo(T2 t) {}\n" + " void foo2(T2 t) {}\n" + "}\n" }, expectedCompilerLog ); /* javac 7 X.java:3: reference to foo is ambiguous, both method foo(U1) in X and method foo(T2) in Y match new Y().foo("X"); ^ where U1,T2 are type-variables: U1 extends Object declared in method foo(U1) T2 extends Object declared in class Y X.java:4: reference to foo2 is ambiguous, both method foo2(U2) in X and meth od foo2(T2) in Y match new Y().foo2("X"); ^ where U2,U3,T2 are type-variables: U2 extends Object declared in method foo2(U2) U3 extends Object declared in method foo2(T2) T2 extends Object declared in class Y X.java:10: name clash: foo(T2) in Y and foo(U1) in X have the same erasure, yet neither overrides the other void foo(T2 t) {} ^ where T2,U1 are type-variables: T2 extends Object declared in class Y U1 extends Object declared in method foo(U1) X.java:11: name clash: foo2(T2) in Y and foo2(U2) in X have the same era sure, yet neither overrides the other void foo2(T2 t) {} ^ where U3,T2,U2 are type-variables: U3 extends Object declared in method foo2(T2) T2 extends Object declared in class Y U2 extends Object declared in method foo2(U2) 4 errors */ } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=129056 public void test007() { this.runNegativeTest( new String[] { "B.java", "public class B {\n" + " public static void main(String[] args) {\n" + " new M().foo(new Integer(1), 2);\n" + " new N().foo(new Integer(1), 2);\n" + " }\n" + "}" + "interface I { void foo(Number arg1, Number arg2); }\n" + "class M {\n" + " public void foo(int arg1, int arg2) {}\n" + " public void foo(Number arg1, Number arg2) {}\n" + "}\n" + "class N implements I {\n" + " public void foo(int arg1, int arg2) {}\n" + " public void foo(Number arg1, Number arg2) {}\n" + "}\n" }, "----------\n" + "1. ERROR in B.java (at line 3)\r\n" + " new M().foo(new Integer(1), 2);\r\n" + " ^^^\n" + "The method foo(int, int) is ambiguous for the type M\n" + "----------\n" + "2. ERROR in B.java (at line 4)\r\n" + " new N().foo(new Integer(1), 2);\r\n" + " ^^^\n" + "The method foo(int, int) is ambiguous for the type N\n" + "----------\n" // reference to foo is ambiguous, both method foo(int,int) in M and method foo(java.lang.Number,java.lang.Number) in M match // reference to foo is ambiguous, both method foo(int,int) in N and method foo(java.lang.Number,java.lang.Number) in N match ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 - case 1 public void test008() { this.runConformTest( new String[] { "AA.java", "public class AA {\n" + " public static void main(String[] a) { System.out.print(new C().test(new T())); }\n" + "}" + "class S {}\n" + "class T extends S {}\n" + "class B { int test(U u) {return -1;} }\n" + "class C extends B { @Override int test(S s) {return 1;} }" }, "1" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 - case 1 public void test008a() { this.runNegativeTest( new String[] { "A.java", "public class A { void check() { new C().test(new T()); } }\n" + "class S {}\n" + "class T extends S {}\n" + "class B { int test(S s) {return 1;} }\n" + "class C extends B { int test(U u) {return -1;} }" }, "----------\n" + "1. ERROR in A.java (at line 1)\n" + " public class A { void check() { new C().test(new T()); } }\n" + " ^^^^\n" + "The method test(T) is ambiguous for the type C\n" + "----------\n" + "2. ERROR in A.java (at line 5)\n" + " class C extends B { int test(U u) {return -1;} }\n" + " ^^^^^^^^^\n" + "Name clash: The method test(U) of type C has the same erasure as test(S) of type B but does not override it\n" + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 - case 2 // see also Bug 399567 - [1.8] Different error message from the reference compiler public void test009() { String[] testFiles = new String[] { "T.java", "import java.util.*;\n" + "public class T {\n" + " void test() {\n" + " OrderedSet os = null;\n" + " os.add(\"hello\");\n" + " OrderedSet os2 = null;\n" + " os2.add(1);\n" + " }\n" + "}\n" + "interface OrderedSet extends List, Set { boolean add(E o); }\n" }; if (this.complianceLevel < ClassFileConstants.JDK1_8) this.runConformTest(testFiles, ""); else this.runNegativeTest( testFiles, "----------\n" + "1. WARNING in T.java (at line 5)\n" + " os.add(\"hello\");\n" + " ^^\n" + "Null pointer access: The variable os can only be null at this location\n" + "----------\n" + "2. WARNING in T.java (at line 7)\n" + " os2.add(1);\n" + " ^^^\n" + "Null pointer access: The variable os2 can only be null at this location\n" + "----------\n" + "3. ERROR in T.java (at line 10)\n" + " interface OrderedSet extends List, Set { boolean add(E o); }\n" + " ^^^^^^^^^^\n" + "Duplicate default methods named spliterator with the parameters () and () are inherited from the types Set and List\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 variant to make it pass on JRE8 public void test009a() { if (this.complianceLevel < ClassFileConstants.JDK1_8) return; this.runConformTest( new String[] { "T.java", "import java.util.*;\n" + "public class T {\n" + " void test() {\n" + " OrderedSet os = null;\n" + " os.add(\"hello\");\n" + " OrderedSet os2 = null;\n" + " os2.add(1);\n" + " }\n" + "}\n" + "interface OrderedSet extends List, Set {\n" + " boolean add(E o);\n" + " default Spliterator spliterator() { return null; }\n" + "}\n" }, "" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 public void test010a() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " interface Listener {}\n" + " interface ErrorListener {}\n" + " static Object createParser(L1 l) { return null; }\n" + " static Object createParser(L2 l) { return null; }\n" + " public static void main(String[] s) {\n" + " class A implements Listener, ErrorListener {}\n" + " createParser(new A());\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 8)\n" + " createParser(new A());\n" + " ^^^^^^^^^^^^\n" + "The method createParser(A) is ambiguous for the type X\n" + "----------\n" ); // javac 7 randomly picks which ever method is second } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 public void test010b() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " interface Listener {}\n" + " interface ErrorListener {}\n" + " static int createParser(L1 l) { return 1; }\n" + " static int createParser(L2 l) { return 2; }\n" + " public static void main(String[] s) {\n" + " class A implements Listener, ErrorListener {}\n" + " System.out.print(createParser(new A()));\n" + " }\n" + "}" }, "2" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 public void test010c() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " interface Listener {}\n" + " interface ErrorListener {}\n" + " static int createParser(Listener l) { return 1; }\n" + " static int createParser(L l) { return 2; }\n" + " public static void main(String[] s) {\n" + " class A implements Listener, ErrorListener {}\n" + " System.out.print(createParser(new A()));\n" + " }\n" + "}" }, "2" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 public void test011() { this.runNegativeTest( new String[] { "X.java", "public class X extends Y {\n" + " void foo(A n, T t) throws ExOne {}\n" + " void test(X x) throws ExTwo { x.foo(new Integer(1), new Integer(2)); }\n" + " void test2(X x) throws ExTwo { x.foo(new Integer(1), new Integer(2)); }\n" + "}\n" + "class Y {\n" + " void foo(C x, C n) throws ExTwo {}\n" + "}\n" + "class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + "class ExTwo extends Exception {static final long serialVersionUID = 2;}" }, "----------\n" + "1. WARNING in X.java (at line 4)\n" + " void test2(X x) throws ExTwo { x.foo(new Integer(1), new Integer(2)); }\n" + " ^\n" + "X is a raw type. References to generic type X should be parameterized\n" + "----------\n" + "2. WARNING in X.java (at line 4)\n" + " void test2(X x) throws ExTwo { x.foo(new Integer(1), new Integer(2)); }\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: The method foo(Number, Number) belongs to the raw type Y. References to generic type Y should be parameterized\n" + "----------\n" // test2 - warning: [unchecked] unchecked call to foo(C,C) as a member of the raw type Y ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 public void test011a() { // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. WARNING in Combined.java (at line 2)\n" + " > void pickOne(T value) throws ExOne {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(T) is the same as another method in type Combined\n" + "----------\n" + "2. WARNING in Combined.java (at line 3)\n" + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(Comparable) is the same as another method in type Combined\n" + "----------\n": "----------\n" + "1. ERROR in Combined.java (at line 2)\n" + " > void pickOne(T value) throws ExOne {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(T) is the same as another method in type Combined\n" + "----------\n" + "2. ERROR in Combined.java (at line 3)\n" + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(Comparable) is the same as another method in type Combined\n" + "----------\n"; this.runNegativeTest( new String[] { "Combined.java", "public class Combined {\n" + " > void pickOne(T value) throws ExOne {}\n" + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + " void pickOne(Combined c) throws ExOne { c.pickOne(\"test\"); }\n" + " void pickTwo(Number n, T t) throws ExOne {}\n" + " void pickTwo(A x, Number n) throws ExTwo {}\n" + " void pickTwo(Combined c) throws ExTwo { c.pickTwo(new Integer(1), 2); }\n" + "}\n" + "class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + "class ExTwo extends Exception {static final long serialVersionUID = 2;}" }, expectedCompilerLog ); /* javac 7 X.java:3: name clash: pickOne(Comparable) and pickOne(T#2) have the same erasure T pickOne(Comparable value) throws ExTwo { return null;} ^ where T#1,T#2 are type-variables: T#1 extends Object declared in method pickOne(Comparable) T#2 extends Comparable declared in method pickOne(T#2) 1 error */ } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 public void test011b() { // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. WARNING in Test1.java (at line 2)\n" + " > void pickOne(T value) throws ExOne {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(T) is the same as another method in type Test1\n" + "----------\n" + "2. WARNING in Test1.java (at line 3)\n" + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(Comparable) is the same as another method in type Test1\n" + "----------\n" + "3. WARNING in Test1.java (at line 4)\n" + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of type Test1\n" + "----------\n" + "4. WARNING in Test1.java (at line 4)\n" + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + " ^^^^^^^^^^\n" + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + "----------\n": "----------\n" + "1. ERROR in Test1.java (at line 2)\n" + " > void pickOne(T value) throws ExOne {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(T) is the same as another method in type Test1\n" + "----------\n" + "2. ERROR in Test1.java (at line 3)\n" + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method pickOne(Comparable) is the same as another method in type Test1\n" + "----------\n" + "3. WARNING in Test1.java (at line 4)\n" + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of type Test1\n" + "----------\n" + "4. WARNING in Test1.java (at line 4)\n" + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + " ^^^^^^^^^^\n" + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + "----------\n"; this.runNegativeTest( new String[] { "Test1.java", "public class Test1 {\n" + " > void pickOne(T value) throws ExOne {}\n" + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + "}\n" + "class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + "class ExTwo extends Exception {static final long serialVersionUID = 2;}" }, expectedCompilerLog ); /* javac 7 X.java:3: name clash: pickOne(Comparable) and pickOne(T#2) have the same erasure T pickOne(Comparable value) throws ExTwo { return null;} ^ where T#1,T#2 are type-variables: T#1 extends Object declared in method pickOne(Comparable) T#2 extends Comparable declared in method pickOne(T#2) X.java:4: warning: [unchecked] unchecked method invocation: method pickOne in class Test1 is applied to given types void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) "test"); } ^ required: T found: Comparable where T is a type-variable: T extends Comparable declared in method pickOne(T) 1 error 1 warning */ } public void test012() { this.runConformTest( new String[] { "XX.java", "public class XX {\n" + " public static void main(String[] s) { System.out.println(new B().id(new Integer(1))); }\n" + "}\n" + "class A { public int id(T t) {return 2;} }\n" + "class B extends A { public int id(Integer i) {return 1;} }" }, "1" ); } public void test012a() { this.runNegativeTest( new String[] { "XX.java", "public class XX {\n" + " public static void main(String[] s) { System.out.println(new B().id(new Integer(1))); }\n" + "}\n" + "class A { public int id(T t) {return 2;} }\n" + "class B extends A { public int id(Integer i) {return 1;} }" }, "----------\n" + "1. ERROR in XX.java (at line 2)\r\n" + " public static void main(String[] s) { System.out.println(new B().id(new Integer(1))); }\r\n" + " ^^\n" + "The method id(Integer) is ambiguous for the type B\n" + "----------\n" // reference to id is ambiguous, both method id(T) in A and method id(java.lang.Integer) in B match ); } public void test013() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void m(E e) { System.out.print(1); }\n" + " void m(E e) { System.out.print(2); }\n" + " public static void main(String[] args) {\n" + " new X().m(new A());\n" + " new X().m(new B());\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" }, "12" ); } public void test014() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void a(G x) { System.out.print(1); }\n" + " void b(F x) { System.out.print(2); }\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " G g = null;\n" + " new X().a(h);\n" + " new X().a(g);\n" + " new X().b(h);\n" + " new X().b(g);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "1122" ); } public void test014a() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void a(G x) { System.out.print(1); }\n" + " void b(F x) { System.out.print(2); }\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " G g = null;\n" + " new X().a(h);\n" + " new X().a(g);\n" + " new X().b(h);\n" + " new X().b(g);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "1122" ); } public void test014b() { this.runConformTest( new String[] { "X0.java", "public class X0 {\n" + " void two(G x) { System.out.print(1); }\n" + " void two(F x) { System.out.print(2); }\n" + " void three(G x) { System.out.print(3); }\n" + " void three(F x) { System.out.print(4); }\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " new X0().two(h);\n" + " new X0().three(h);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "13" ); } public void test014c() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void a(G x) {}\n" + " void a(F x) {}\n" + " void b(G x) {}\n" + " void b(F x) {}\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " new X().a(h);\n" + " new X().b(h);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "----------\n" + "1. WARNING in X.java (at line 2)\r\n" + " void a(G x) {}\r\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "2. WARNING in X.java (at line 5)\r\n" + " void b(F x) {}\r\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "3. ERROR in X.java (at line 8)\r\n" + " new X().a(h);\r\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" // reference to a is ambiguous, both method a(G) in X and method a(F) in X match ); } public void test014d() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void one(G x) {}\n" + " void one(F x) {}\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " new X().one(h);\n" + // no match " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "----------\n" + "1. ERROR in X.java (at line 6)\r\n" + " new X().one(h);\r\n" + " ^^^\n" + "The method one(G) in the type X is not applicable for the arguments (H)\n" + "----------\n" ); } public void test014e() { this.runConformTest( new String[] { "X1.java", "public class X1 {\n" + " void two(G x) { System.out.print(1); }\n" + " void two(F x) { System.out.print(2); }\n" + " void three(G x) { System.out.print(3); }\n" + " void three(F x) { System.out.print(4); }\n" + " void four(G x) { System.out.print(5); }\n" + " void four(F x) { System.out.print(6); }\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " new X1().two(h);\n" + " new X1().three(h);\n" + " new X1().four(h);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "145" ); } public void test014f() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void three(G x) {}\n" + " void three(F x) {}\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " new X().three(h);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "----------\n" + "1. ERROR in X.java (at line 6)\r\n" + " new X().three(h);\r\n" + " ^^^^^\n" + "The method three(G) is ambiguous for the type X\n" + "----------\n" ); } public void test014g() { this.runConformTest( new String[] { "X3.java", "public class X3 {\n" + " void one(G x) { System.out.print(1); }\n" + " void one(F x) { System.out.print(2); }\n" + " void two(G x) { System.out.print(3); }\n" + " void two(F x) { System.out.print(4); }\n" + " void four(G x) { System.out.print(5); }\n" + " void four(F x) { System.out.print(6); }\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " new X3().one(h);\n" + " new X3().two(h);\n" + " new X3().four(h);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "135" ); } public void test014h() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void x(G x) { System.out.print(true); }\n" + " void x(F x) { System.out.print(false); }\n" + " void x2(G x) { System.out.print(true); }\n" + " void x2(F x) { System.out.print(false); }\n" + " void a(G x) {}\n" + " void a(F x) {}\n" + " void a2(G x) {}\n" + " void a2(F x) {}\n" + " void a3(G x) {}\n" + " > void a3(T x) {}\n" + " void a4(G x) {}\n" + " > void a4(S x) {}\n" + " void a5(T x) {}\n" + " void a5(F x) {}\n" + " void a6(T x) {}\n" + " > void a6(S x) {}\n" + " void b(G x) { System.out.print(true); }\n" + " void b(F x) { System.out.print(false); }\n" + " void b2(G x) { System.out.print(true); }\n" + " void b2(T x) { System.out.print(false); }\n" + " void b3(G x) { System.out.print(true); }\n" + " void b3(F x) { System.out.print(false); }\n" + " > void b4(T x) { System.out.print(true); }\n" + " void b4(F x) { System.out.print(false); }\n" + " > void b5(S x) { System.out.print(true); }\n" + " void b5(F x) { System.out.print(false); }\n" + " void c(G x) { System.out.print(true); }\n" + " void c(F x) { System.out.print(false); }\n" + " public static void main(String[] args) {\n" + " H h = null;\n" + " H hraw = null;\n" + " new X().x(h);\n" + " new X().x(hraw);\n" + " new X().x2(h);\n" + " new X().x2(hraw);\n" + " new X().b(h);\n" + " new X().b(hraw);\n" + " new X().b2(h);\n" + " new X().b2(hraw);\n" + " new X().b3(h);\n" + " new X().b3(hraw);\n" + " new X().b4(h);\n" + " new X().b4(hraw);\n" + " new X().b5(h);\n" + " new X().b5(hraw);\n" + " new X().c(h);\n" + " new X().c(hraw);\n" + " }\n" + "}\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B {}\n" + "class F {} \n" + "class G extends F {}\n" + "class H extends G {}" }, "truetruetruetruetruetruetruetruetruetruetruetruetruetruetruetrue" ); this.runNegativeTest( new String[] { "Y.java", "public class Y extends X {\n" + " public static void ambiguousCases() {\n" + " H h = null;\n" + " H hraw = null;\n" + " new X().a(h);\n" + " new X().a(hraw);\n" + " new X().a2(h);\n" + " new X().a2(hraw);\n" + " new X().a3(h);\n" + " new X().a3(hraw);\n" + " new X().a4(h);\n" + " new X().a4(hraw);\n" + " new X().a5(h);\n" + " new X().a5(hraw);\n" + " new X().a6(h);\n" + " new X().a6(hraw);\n" + " }\n" + "}\n" }, (this.complianceLevel < ClassFileConstants.JDK1_8 ? "----------\n" + "1. WARNING in Y.java (at line 4)\n" + " H hraw = null;\n" + " ^\n" + "H is a raw type. References to generic type H should be parameterized\n" + "----------\n" + "2. ERROR in Y.java (at line 5)\n" + " new X().a(h);\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" + "3. ERROR in Y.java (at line 6)\n" + " new X().a(hraw);\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" + "4. ERROR in Y.java (at line 7)\n" + " new X().a2(h);\n" + " ^^\n" + "The method a2(G) is ambiguous for the type X\n" + "----------\n" + "5. ERROR in Y.java (at line 8)\n" + " new X().a2(hraw);\n" + " ^^\n" + "The method a2(G) is ambiguous for the type X\n" + "----------\n" + "6. ERROR in Y.java (at line 9)\n" + " new X().a3(h);\n" + " ^^\n" + "The method a3(G) is ambiguous for the type X\n" + "----------\n" + "7. ERROR in Y.java (at line 10)\n" + " new X().a3(hraw);\n" + " ^^\n" + "The method a3(G) is ambiguous for the type X\n" + "----------\n" + "8. ERROR in Y.java (at line 11)\n" + " new X().a4(h);\n" + " ^^\n" + "The method a4(G) is ambiguous for the type X\n" + "----------\n" + "9. ERROR in Y.java (at line 12)\n" + " new X().a4(hraw);\n" + " ^^\n" + "The method a4(G) is ambiguous for the type X\n" + "----------\n" + "10. ERROR in Y.java (at line 13)\n" + " new X().a5(h);\n" + " ^^\n" + "The method a5(H) is ambiguous for the type X\n" + "----------\n" + "11. ERROR in Y.java (at line 14)\n" + " new X().a5(hraw);\n" + " ^^\n" + "The method a5(H) is ambiguous for the type X\n" + "----------\n" + "12. ERROR in Y.java (at line 15)\n" + " new X().a6(h);\n" + " ^^\n" + "The method a6(H) is ambiguous for the type X\n" + "----------\n" + "13. ERROR in Y.java (at line 16)\n" + " new X().a6(hraw);\n" + " ^^\n" + "The method a6(H) is ambiguous for the type X\n" + "----------\n" : // in 1.8 fewer of the calls are ambiguous "----------\n" + "1. WARNING in Y.java (at line 4)\n" + " H hraw = null;\n" + " ^\n" + "H is a raw type. References to generic type H should be parameterized\n" + "----------\n" + "2. ERROR in Y.java (at line 5)\n" + " new X().a(h);\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" + "3. ERROR in Y.java (at line 6)\n" + " new X().a(hraw);\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" + "4. ERROR in Y.java (at line 7)\n" + " new X().a2(h);\n" + " ^^\n" + "The method a2(G) is ambiguous for the type X\n" + "----------\n" + "5. ERROR in Y.java (at line 8)\n" + " new X().a2(hraw);\n" + " ^^\n" + "The method a2(G) is ambiguous for the type X\n" + "----------\n" + "6. ERROR in Y.java (at line 13)\n" + " new X().a5(h);\n" + " ^^\n" + "The method a5(H) is ambiguous for the type X\n" + "----------\n" + "7. ERROR in Y.java (at line 14)\n" + " new X().a5(hraw);\n" + " ^^\n" + "The method a5(H) is ambiguous for the type X\n" + "----------\n"), null, false ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=262209 public void test014i() { this.runNegativeTest( new String[] { "X.java", "interface I {}\n" + "interface J extends I {}\n" + "\n" + "class X {\n" + " void a(G x) {}\n" + " > void a(S x) {}\n" + "\n" + " void b(G x) {}\n" + " void b(F x) {}\n" + "\n" + " void c(G x) {}\n" + " void c(F x) {}\n" + "\n" + " void d(G x) {}\n" + " void d(F x) {}\n" + "\n" + " void e(G x) {}\n" + " void e(F x) {}\n" + "\n" + " void f(G x) {}\n" + " void f(S x) {}\n" + "\n" + " void g(G x) {}\n" + " > void g(S x) {}\n" + "\n" + " void a2(T x) {}\n" + " > void a2(S x) {}\n" + "\n" + " void b2(T x) {}\n" + " void b2(F x) {}\n" + "\n" + " void c2(T x) {}\n" + " void c2(F x) {}\n" + "\n" + " void d2(T x) {}\n" + " void d2(F x) {}\n" + "\n" + " void e2(T x) {}\n" + " void e2(F x) {}\n" + "\n" + " void f2(T x) {}\n" + " void f2(S x) {}\n" + "\n" + " void g2(T x) {}\n" + " > void g2(S x) {}\n" + "\n" + " void test() {\n" + " X x = new X();\n" + " H h = null;\n" + " H hraw = null;\n" + "\n" + " x.a(h);\n" + " x.a(hraw);\n" + "\n" + " x.b(h);\n" + " x.b(hraw);\n" + "\n" + " x.c(h);\n" + " x.c(hraw);\n" + "\n" + " x.d(h);\n" + " x.d(hraw);\n" + "\n" + " x.e(h);\n" + " x.e(hraw);\n" + "\n" + " x.f(h);\n" + " x.f(hraw);\n" + "\n" + " x.g(h);\n" + " x.g(hraw);\n" + "\n" + " x.a2(h);\n" + " x.a2(hraw);\n" + "\n" + " x.b2(h); \n" + " x.b2(hraw);\n" + "\n" + " x.c2(h);\n" + " x.c2(hraw);\n" + "\n" + " x.d2(h);\n" + " x.d2(hraw);\n" + "\n" + " x.e2(h);\n" + " x.e2(hraw);\n" + "\n" + " x.f2(h);\n" + " x.f2(hraw);\n" + "\n" + " x.g2(h); \n" + " x.g2(hraw);\n" + " }\n" + "}\n" + "\n" + "class A {}\n" + "class B extends A {}\n" + "class C extends B implements I {}\n" + "class F {} \n" + "class G extends F implements J {}\n" + "class H extends G {}\n" }, "----------\n" + "1. WARNING in X.java (at line 5)\n" + " void a(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "2. WARNING in X.java (at line 8)\n" + " void b(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "3. WARNING in X.java (at line 9)\n" + " void b(F x) {}\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "4. WARNING in X.java (at line 11)\n" + " void c(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "5. WARNING in X.java (at line 14)\n" + " void d(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "6. WARNING in X.java (at line 17)\n" + " void e(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "7. WARNING in X.java (at line 20)\n" + " void f(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "8. WARNING in X.java (at line 21)\n" + " void f(S x) {}\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "9. WARNING in X.java (at line 23)\n" + " void g(G x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "10. WARNING in X.java (at line 24)\n" + " > void g(S x) {}\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "11. WARNING in X.java (at line 26)\n" + " void a2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "12. WARNING in X.java (at line 29)\n" + " void b2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "13. WARNING in X.java (at line 30)\n" + " void b2(F x) {}\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "14. WARNING in X.java (at line 32)\n" + " void c2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "15. WARNING in X.java (at line 35)\n" + " void d2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "16. WARNING in X.java (at line 38)\n" + " void e2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "17. WARNING in X.java (at line 41)\n" + " void f2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "18. WARNING in X.java (at line 42)\n" + " void f2(S x) {}\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "19. WARNING in X.java (at line 42)\n" + " void f2(S x) {}\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "20. WARNING in X.java (at line 44)\n" + " void g2(T x) {}\n" + " ^\n" + "G is a raw type. References to generic type G should be parameterized\n" + "----------\n" + "21. WARNING in X.java (at line 45)\n" + " > void g2(S x) {}\n" + " ^\n" + "F is a raw type. References to generic type F should be parameterized\n" + "----------\n" + "22. WARNING in X.java (at line 50)\n" + " H hraw = null;\n" + " ^\n" + "H is a raw type. References to generic type H should be parameterized\n" + "----------\n" + (this.complianceLevel < ClassFileConstants.JDK1_8 ? "23. ERROR in X.java (at line 52)\n" + " x.a(h);\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" + "24. ERROR in X.java (at line 53)\n" + " x.a(hraw);\n" + " ^\n" + "The method a(G) is ambiguous for the type X\n" + "----------\n" + "25. ERROR in X.java (at line 58)\n" + " x.c(h);\n" + " ^\n" + "The method c(G) is ambiguous for the type X\n" + "----------\n" + "26. ERROR in X.java (at line 59)\n" + " x.c(hraw);\n" + " ^\n" + "The method c(G) is ambiguous for the type X\n" + "----------\n" + "27. ERROR in X.java (at line 61)\n" + " x.d(h);\n" + " ^\n" + "The method d(G) is ambiguous for the type X\n" + "----------\n" + "28. ERROR in X.java (at line 62)\n" + " x.d(hraw);\n" + " ^\n" + "The method d(G) is ambiguous for the type X\n" + "----------\n" + "29. ERROR in X.java (at line 64)\n" + " x.e(h);\n" + " ^\n" + "The method e(G) is ambiguous for the type X\n" + "----------\n" + "30. ERROR in X.java (at line 65)\n" + " x.e(hraw);\n" + " ^\n" + "The method e(G) is ambiguous for the type X\n" + "----------\n" + "31. ERROR in X.java (at line 71)\n" + " x.g(hraw);\n" + " ^\n" + "The method g(G) is ambiguous for the type X\n" + "----------\n" + "32. ERROR in X.java (at line 73)\n" + " x.a2(h);\n" + " ^^\n" + "The method a2(H) is ambiguous for the type X\n" + "----------\n" + "33. ERROR in X.java (at line 74)\n" + " x.a2(hraw);\n" + " ^^\n" + "The method a2(H) is ambiguous for the type X\n" + "----------\n" + "34. ERROR in X.java (at line 79)\n" + " x.c2(h);\n" + " ^^\n" + "The method c2(H) is ambiguous for the type X\n" + "----------\n" + "35. ERROR in X.java (at line 80)\n" + " x.c2(hraw);\n" + " ^^\n" + "The method c2(H) is ambiguous for the type X\n" + "----------\n" + "36. ERROR in X.java (at line 82)\n" + " x.d2(h);\n" + " ^^\n" + "The method d2(H) is ambiguous for the type X\n" + "----------\n" + "37. ERROR in X.java (at line 83)\n" + " x.d2(hraw);\n" + " ^^\n" + "The method d2(H) is ambiguous for the type X\n" + "----------\n" + "38. ERROR in X.java (at line 85)\n" + " x.e2(h);\n" + " ^^\n" + "The method e2(H) is ambiguous for the type X\n" + "----------\n" + "39. ERROR in X.java (at line 86)\n" + " x.e2(hraw);\n" + " ^^\n" + "The method e2(H) is ambiguous for the type X\n" + "----------\n" + "40. ERROR in X.java (at line 92)\n" + " x.g2(hraw);\n" + " ^^\n" + "The method g2(H) is ambiguous for the type X\n" + "----------\n" + "41. WARNING in X.java (at line 98)\n" : // fewer ambiguities in 1.8 "23. ERROR in X.java (at line 61)\n" + " x.d(h);\n" + " ^\n" + "The method d(G) is ambiguous for the type X\n" + "----------\n" + "24. ERROR in X.java (at line 62)\n" + " x.d(hraw);\n" + " ^\n" + "The method d(G) is ambiguous for the type X\n" + "----------\n" + "25. ERROR in X.java (at line 64)\n" + " x.e(h);\n" + " ^\n" + "The method e(G) is ambiguous for the type X\n" + "----------\n" + "26. ERROR in X.java (at line 65)\n" + " x.e(hraw);\n" + " ^\n" + "The method e(G) is ambiguous for the type X\n" + "----------\n" + "27. ERROR in X.java (at line 82)\n" + " x.d2(h);\n" + " ^^\n" + "The method d2(H) is ambiguous for the type X\n" + "----------\n" + "28. ERROR in X.java (at line 83)\n" + " x.d2(hraw);\n" + " ^^\n" + "The method d2(H) is ambiguous for the type X\n" + "----------\n" + "29. ERROR in X.java (at line 85)\n" + " x.e2(h);\n" + " ^^\n" + "The method e2(H) is ambiguous for the type X\n" + "----------\n" + "30. ERROR in X.java (at line 86)\n" + " x.e2(hraw);\n" + " ^^\n" + "The method e2(H) is ambiguous for the type X\n" + "----------\n" + "31. WARNING in X.java (at line 98)\n" ) + " class C extends B implements I {}\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 public void test015() { this.runConformTest( new String[] { "E.java", "public class E {\n" + " public static void main(String[] s) {\n" + " IJ ij = new K();\n" + " try { ij.m(); } catch(E11 e) {}\n" + " }\n" + "}\n" + "interface I { void m() throws E1; }\n" + "interface J { void m() throws E11; }\n" + "interface IJ extends I, J {}\n" + "class K implements IJ { public void m() {} }\n" + "class E1 extends Exception { static final long serialVersionUID = 1; }\n" + "class E11 extends E1 { static final long serialVersionUID = 2; }\n" + "class E2 extends Exception { static final long serialVersionUID = 3; }" }, "" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 public void _test016() { this.runConformTest( new String[] { "E.java", "public class E {\n" + " public static void main(String[] s) {\n" + " IJ ij = new K();\n" + " try { ij.m(); } catch(E11 e) {}\n" + " }\n" + "}\n" + "interface I { void m() throws E1; }\n" + "interface J { void m() throws E2, E11; }\n" + "interface IJ extends I, J {}\n" + "class K implements IJ { public void m() {} }\n" + "class E1 extends Exception { static final long serialVersionUID = 1; }\n" + "class E11 extends E1 { static final long serialVersionUID = 2; }\n" + "class E2 extends Exception { static final long serialVersionUID = 3; }" }, "" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 public void _test016a() { this.runNegativeTest( new String[] { "E.java", "public class E {\n" + " public static void main(String[] s) {\n" + " IJ ij = new K();\n" + " ij.m();\n" + " try { ij.m(); } catch(E2 e) {}\n" + " }\n" + "}\n" + "interface I { void m() throws E1; }\n" + "interface J { void m() throws E2, E11; }\n" + "interface IJ extends I, J {}\n" + "class K implements IJ { public void m() {} }\n" + "class E1 extends Exception { static final long serialVersionUID = 1; }\n" + "class E11 extends E1 { static final long serialVersionUID = 2; }\n" + "class E2 extends Exception { static final long serialVersionUID = 3; }" }, "----------\n" + "1. ERROR in E.java (at line 4)\r\n" + " ij.m();\r\n" + " ^^^^^^\n" + "Unhandled exception type E11\n" + "----------\n" + "2. ERROR in E.java (at line 5)\r\n" + " try { ij.m(); } catch(E2 e) {}\r\n" + " ^^^^^^\n" + "Unhandled exception type E11\n" + "----------\n" + "3. ERROR in E.java (at line 5)\r\n" + " try { ij.m(); } catch(E2 e) {}\r\n" + " ^^\n" + "Unreachable catch block for E2. This exception is never thrown from the try statement body\n" + "----------\n" // 4: unreported exception E11; must be caught or declared to be thrown // 5: exception E2 is never thrown in body of corresponding try statement // 5: unreported exception E11; must be caught or declared to be thrown ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=149893 public void test017() { this.runConformTest( new String[] { "AbstractFilter.java", "import java.util.*;\n" + "public class AbstractFilter implements IFilter {\n" + " public final boolean selekt(E obj) { return true; }\n" + " public final List filter(List elements) {\n" + " if ((elements == null) || (elements.size() == 0)) return elements;\n" + " List okElements = new ArrayList(elements.size());\n" + " for (E obj : elements) {\n" + " if (selekt(obj)) okElements.add(obj);\n" + " }\n" + " return okElements;" + " }\n" + "}\n" + "interface IFilter {\n" + " boolean selekt(E obj);\n" + " List filter(List elements);\n" + "}" }, "" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 public void test018() { if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; this.runConformTest( new String[] { "Y.java", "class X {\n" + " public static X make(Class clazz) {\n" + " System.out.print(false);\n" + " return new X();\n" + " }\n" + "}\n" + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + " System.out.print(true);\n" + " return new Y();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + " Y.make(String.class);\n" + " }\n" + "}" }, "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 // in fact, Y make(Class clazz) is the most // specific method according to JLS 15.12.2.5 public void test019() { if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; this.runConformTest( new String[] { "Y.java", "class X {\n" + " public static X make(Class clazz) {\n" + " System.out.print(false);\n" + " return new X();\n" + " }\n" + "}\n" + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + " System.out.print(true);\n" + " return new Y();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + " Y.make(getClazz());\n" + " }\n" + " public static Class getClazz() {\n" + " return String.class;\n" + " }\n" + "}" }, "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 public void test020() { if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; this.runConformTest( new String[] { "Y.java", "class X {\n" + " public static X make(Class clazz) {\n" + " System.out.print(true);\n" + " return new X();\n" + " }\n" + "}\n" + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + " System.out.print(false);\n" + " return new Y();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + " Y.make(getClazz().newInstance().getClass());\n" + " }\n" + " public static Class getClazz() {\n" + " return String.class;\n" + " }\n" + "}" }, "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 // variant: having both methods in the same class should not change anything public void test021() { // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. WARNING in Y.java (at line 3)\n" + " public class Y extends X {\n" + " ^^^^^^\n" + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "2. WARNING in Y.java (at line 4)\n" + " public static Y make(Class clazz) {\n" + " ^^^^^^\n" + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "3. WARNING in Y.java (at line 4)\n" + " public static Y make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "4. WARNING in Y.java (at line 8)\n" + " public static X make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "5. WARNING in Y.java (at line 13)\n" + " Y.make(getClazz());\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Type safety: Unchecked invocation make(Class) of the generic method make(Class) of type Y\n" + "----------\n" + "6. WARNING in Y.java (at line 13)\n" + " Y.make(getClazz());\n" + " ^^^^^^^^^^\n" + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + "----------\n" + "7. WARNING in Y.java (at line 15)\n" + " public static Class getClazz() {\n" + " ^^^^^\n" + "Class is a raw type. References to generic type Class should be parameterized\n" + "----------\n": "----------\n" + "1. WARNING in Y.java (at line 3)\n" + " public class Y extends X {\n" + " ^^^^^^\n" + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "2. WARNING in Y.java (at line 4)\n" + " public static Y make(Class clazz) {\n" + " ^^^^^^\n" + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "3. ERROR in Y.java (at line 4)\n" + " public static Y make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "4. ERROR in Y.java (at line 8)\n" + " public static X make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "5. WARNING in Y.java (at line 13)\n" + " Y.make(getClazz());\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Type safety: Unchecked invocation make(Class) of the generic method make(Class) of type Y\n" + "----------\n" + "6. WARNING in Y.java (at line 13)\n" + " Y.make(getClazz());\n" + " ^^^^^^^^^^\n" + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + "----------\n" + "7. WARNING in Y.java (at line 15)\n" + " public static Class getClazz() {\n" + " ^^^^^\n" + "Class is a raw type. References to generic type Class should be parameterized\n" + "----------\n"; this.runNegativeTest( new String[] { "Y.java", "class X {\n" + "}\n" + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + " System.out.print(true);\n" + " return new Y();\n" + " }\n" + " public static X make(Class clazz) {\n" + " System.out.print(false);\n" + " return new X();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + " Y.make(getClazz());\n" + " }\n" + " public static Class getClazz() {\n" + " return String.class;\n" + " }\n" + "}" }, expectedCompilerLog ); /* javac 7 X.java:8: name clash: make(Class) and make(Class) have the same erasure public static X make(Class clazz) { ^ where U,W are type-variables: U extends Object declared in method make(Class) W extends String declared in method make(Class) X.java:13: warning: [unchecked] unchecked conversion Y.make(getClazz()); ^ required: Class found: Class where W#1,W#2 are type-variables: W#1 extends String declared in method make(Class) W#2 extends String declared in method make(Class) X.java:13: warning: [unchecked] unchecked method invocation: method make in class Y is applied to given types Y.make(getClazz()); ^ required: Class found: Class where W is a type-variable: W extends String declared in method make(Class) 1 error 2 warnings */ } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 // variant: using instances triggers raw methods, which are ambiguous public void test022() { // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. WARNING in X.java (at line 3)\n" + " class Y extends X {\n" + " ^^^^^^\n" + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "2. WARNING in X.java (at line 4)\n" + " public Y make(Class clazz) {\n" + " ^^^^^^\n" + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "3. WARNING in X.java (at line 4)\n" + " public Y make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "4. WARNING in X.java (at line 7)\n" + " public X make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "5. WARNING in X.java (at line 11)\n" + " Y y = new Y();\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" + "6. WARNING in X.java (at line 11)\n" + " Y y = new Y();\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" + "7. ERROR in X.java (at line 12)\n" + " y.make(String.class);\n" + " ^^^^\n" + "The method make(Class) is ambiguous for the type Y\n" + "----------\n" + "8. ERROR in X.java (at line 13)\n" + " y.make(getClazz());\n" + " ^^^^\n" + "The method make(Class) is ambiguous for the type Y\n" + "----------\n" + "9. ERROR in X.java (at line 14)\n" + " y.make(getClazz().newInstance().getClass());\n" + " ^^^^\n" + "The method make(Class) is ambiguous for the type Y\n" + "----------\n" + "10. WARNING in X.java (at line 16)\n" + " public static Class getClazz() {\n" + " ^^^^^\n" + "Class is a raw type. References to generic type Class should be parameterized\n" + "----------\n": "----------\n" + "1. WARNING in X.java (at line 3)\n" + " class Y extends X {\n" + " ^^^^^^\n" + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "2. WARNING in X.java (at line 4)\n" + " public Y make(Class clazz) {\n" + " ^^^^^^\n" + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + "----------\n" + "3. ERROR in X.java (at line 4)\n" + " public Y make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "4. ERROR in X.java (at line 7)\n" + " public X make(Class clazz) {\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Erasure of method make(Class) is the same as another method in type Y\n" + "----------\n" + "5. WARNING in X.java (at line 11)\n" + " Y y = new Y();\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" + "6. WARNING in X.java (at line 11)\n" + " Y y = new Y();\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" + "7. WARNING in X.java (at line 12)\n" + " y.make(String.class);\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: The method make(Class) belongs to the raw type Y. References to generic type Y should be parameterized\n" + "----------\n" + "8. WARNING in X.java (at line 13)\n" + " y.make(getClazz());\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Type safety: The method make(Class) belongs to the raw type Y. References to generic type Y should be parameterized\n" + "----------\n" + "9. WARNING in X.java (at line 14)\n" + " y.make(getClazz().newInstance().getClass());\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: The method make(Class) belongs to the raw type Y. References to generic type Y should be parameterized\n" + "----------\n" + "10. WARNING in X.java (at line 16)\n" + " public static Class getClazz() {\n" + " ^^^^^\n" + "Class is a raw type. References to generic type Class should be parameterized\n" + "----------\n"; this.runNegativeTest( new String[] { "X.java", "public class X {\n" + "}\n" + "class Y extends X {\n" + " public Y make(Class clazz) {\n" + " return new Y();\n" + " }\n" + " public X make(Class clazz) {\n" + " return new X();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + " Y y = new Y();\n" + " y.make(String.class);\n" + " y.make(getClazz());\n" + " y.make(getClazz().newInstance().getClass());\n" + " }\n" + " public static Class getClazz() {\n" + " return String.class;\n" + " }\n" + "}" }, expectedCompilerLog ); /* javac 7 X.java:7: name clash: make(Class) and make(Class) have the same erasure public X make(Class clazz) { ^ where U,W are type-variables: U extends Object declared in method make(Class) W extends String declared in method make(Class) X.java:12: warning: [unchecked] unchecked call to make(Class) as a member of the raw type Y y.make(String.class); ^ where W is a type-variable: W extends String declared in method make(Class) X.java:13: warning: [unchecked] unchecked call to make(Class) as a member of the raw type Y y.make(getClazz()); ^ where W is a type-variable: W extends String declared in method make(Class) X.java:14: warning: [unchecked] unchecked call to make(Class) as a member of the raw type Y y.make(getClazz().newInstance().getClass()); ^ where W is a type-variable: W extends String declared in method make(Class) 1 error 3 warnings */ } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159711 public void test023() { this.runConformTest( new String[] { "X.java", "import java.util.*;\n" + "public class X {\n" + " public static void staticFoo(Collection p) {\n" + " System.out.print(1);\n" + " }\n" + " public static > void staticFoo(T p) {\n" + " System.out.print(2);\n" + " }\n" + " public void foo(Collection p) {\n" + " System.out.print(1);\n" + " }\n" + " public > void foo(T p) {\n" + " System.out.print(2);\n" + " }\n" + " public void foo2(Collection p) {\n" + " System.out.print(1);\n" + " }\n" + " public void foo2(List p) {\n" + " System.out.print(2);\n" + " }\n" + " public static void main(String[] args) {\n" + " staticFoo(new ArrayList(Arrays.asList(\"\")));\n" + " new X().foo(new ArrayList(Arrays.asList(\"\")));\n" + " new X().foo2(new ArrayList(Arrays.asList(\"\")));\n" + " }\n" + "}" }, "222"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159711 // self contained variant public void test024() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " public static void foo(L1 p) {\n" + " System.out.println(1);\n" + " }\n" + " public static > void foo(T p) {\n" + " System.out.println(2);\n" + " }\n" + " public static void main(String[] args) {\n" + " foo(new L3());\n" + " }\n" + "}", "L1.java", "public interface L1 {\n" + "}", "L2.java", "public interface L2 extends L1 {\n" + "}", "L3.java", "public class L3 implements L2 {\n" + " public L3() {\n" + " }\n" + "}", }, "2"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162026 public void test025() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " J m = new Y();\n" + " void foo() {\n" + " m.foo(1.0f);\n" + " }\n" + "}", "I.java", "public interface I {\n" + " T foo(final Number p);\n" + "}", "J.java", "public interface J extends I {\n" + " Float foo(final Number p);\n" + "}", "Y.java", "public class Y implements J {\n" + " public Float foo(final Number p){\n" + " return null;\n" + " }\n" + "}", }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162026 // variant public void test026() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void foo() {\n" + " (new Y()).foo(1.0f);\n" + " }\n" + "}", "I.java", "public interface I {\n" + " T foo(final Number p);\n" + "}", "J.java", "public interface J extends I {\n" + " Float foo(final Number p);\n" + "}", "Y.java", "public class Y implements J {\n" + " public Float foo(final Number p){\n" + " return null;" + " }\n" + "}", }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162026 // variant public void test027() { this.runNegativeTest( new String[] { "J.java", "public interface J {\n" + " T foo(final Number p);\n" + " Float foo(final Number p);\n" + "}", }, "----------\n" + "1. ERROR in J.java (at line 2)\n" + " T foo(final Number p);\n" + " ^^^^^^^^^^^^^^^^^^^\n" + "Duplicate method foo(Number) in type J\n" + "----------\n" + "2. ERROR in J.java (at line 3)\n" + " Float foo(final Number p);\n" + " ^^^^^^^^^^^^^^^^^^^\n" + "Duplicate method foo(Number) in type J\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 public void test028() { this.runConformTest( new String[] { /* test files */ "X.java", "interface Irrelevant {}\n" + "interface I {\n" + " Object foo(Number n);\n" + "}\n" + "interface J extends Irrelevant, I {\n" + " String foo(Number n);\n" + "}\n" + "interface K {\n" + " Object foo(Number n);\n" + "}\n" + "public abstract class X implements J, K {\n" + " void foo() {\n" + " foo(0.0f);\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - simplified public void test029() { this.runConformTest( new String[] { /* test files */ "X.java", "interface J {\n" + " String foo(Number n);\n" + "}\n" + "interface K {\n" + " Object foo(Number n);\n" + "}\n" + "public abstract class X implements J, K {\n" + " void foo() {\n" + " foo(0.0f);\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - same return type public void test030() { this.runConformTest( new String[] { "X.java", "interface J {\n" + " Object foo(Number n);\n" + "}\n" + "interface K {\n" + " Object foo(Number n);\n" + "}\n" + "public abstract class X implements J, K {\n" + " void foo() {\n" + " foo(0.0f);\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant public void test031() { this.runConformTest( new String[] { /* test files */ "X.java", "interface Irrelevant {}\n" + "interface I {\n" + " Object foo(Number n);\n" + "}\n" + "interface J extends Irrelevant, I {\n" + " String foo(Number n);\n" + "}\n" + "interface K {\n" + " Object foo(Number n);\n" + "}\n" + "public abstract class X implements Irrelevant, I, J, K {\n" + " void foo() {\n" + " foo(0.0f);\n" + " }\n" + "}" }); } // tests 32-34 were moved to MethodVerifyTest 134-140 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - the inheriting class implements foo public void test035() { this.runConformTest( new String[] { "X.java", "interface I {\n" + " Object foo(Number n);\n" + "}\n" + "abstract class J {\n" + " abstract String foo(Number n);\n" + "}\n" + "public class X extends J implements I {\n" + " void bar() {\n" + " foo(0.0f);\n" + // calls X#foo(Number) " }\n" + " public String foo(Number n) {\n" + " return null;\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - extending instead of implementing public void test037() { this.runConformTest( // test directory preparation new String[] { /* test files */ "X.java", "interface I {\n" + " Object foo(Number n);\n" + "}\n" + "abstract class J {\n" + " abstract String foo(Number n);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " foo(0.0f);\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - no promotion of parameter from float to Number public void test038() { this.runConformTest( new String[] { /* test files */ "X.java", "interface I {\n" + " Object foo(float f);\n" + "}\n" + "abstract class J {\n" + " public abstract String foo(float f);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " foo(0.0f);\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - an explicit cast solves the issue public void test039() { this.runConformTest( new String[] { "X.java", "interface I {\n" + " Object foo(float f);\n" + "}\n" + "abstract class J {\n" + " public abstract String foo(float f);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " String s = ((J) this).foo(0.0f);\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - an explicit cast solves the issue public void test040() { this.runConformTest( new String[] { "X.java", "interface I {\n" + " Object foo(float f);\n" + "}\n" + "abstract class J {\n" + " public abstract String foo(float f);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " Object o = ((I) this).foo(0.0f);\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - connecting return types public void test041() { this.runNegativeTest( new String[] { "X.java", "interface I {\n" + " Object foo(float f);\n" + "}\n" + "abstract class J {\n" + " public abstract String foo(float f);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " String s = ((I) this).foo(0.0f);\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 9)\n" + " String s = ((I) this).foo(0.0f);\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from Object to String\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - a further inheriting class implements String foo public void test042() { this.runConformTest( // test directory preparation new String[] { /* test files */ "X.java", "interface I {\n" + " Object foo(float f);\n" + "}\n" + "abstract class J {\n" + " public abstract String foo(float f);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " foo(0.0f);\n" + " }\n" + "}\n" + "class Z extends X {\n" + " @Override" + " public String foo(float f) {\n" + " return null;\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 // variant - a further inheriting class implements Object foo public void test043() { this.runNegativeTest( new String[] { "X.java", "interface I {\n" + " Object foo(float f);\n" + "}\n" + "abstract class J {\n" + " public abstract String foo(float f);\n" + "}\n" + "public abstract class X extends J implements I {\n" + " void bar() {\n" + " foo(0.0f);\n" + " }\n" + "}\n" + "class Z extends X {\n" + " @Override\n" + " public Object foo(float f) {\n" + // cannot override String foo " return null;\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 14)\n" + " public Object foo(float f) {\n" + " ^^^^^^\n" + "The return type is incompatible with J.foo(float)\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=163370 public void test044() { this.runConformTest( new String[] { "X.java", "interface I {}\n" + "class Y {}\n" + "public class X> implements I {\n" + " public static > X bar(X s) {\n" + " return null;\n" + " }\n" + " public static > X bar(I c) {\n" + " return null;\n" + " }\n" + " public static > X foo(X s) {\n" + " X result = bar(s);\n" + " return result;\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165620 public void test045() { this.runConformTest( new String[] { "X.java", "abstract class Y implements I {\n" + "}\n" + "interface I { \n" + "}\n" + "interface J {\n" + "}\n" + "class X {\n" + " public static > V foo(final I a)\n" + " {\n" + " return null;\n" + " }\n" + " public static > V foo(final Y a)\n" + " {\n" + " return null;\n" + " }\n" + " public static > void test(final Y a)\n" + " {\n" + " foo(a);\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=163370 // variant public void test046() { this.runConformTest( new String[] { "X.java", "abstract class Y implements I {\n" + "}\n" + "interface I { \n" + "}\n" + "interface J {\n" + "}\n" + "class X {\n" + " public static , W extends J> V foo(final I a)\n" + " {\n" + " return null;\n" + " }\n" + " public static , W extends J> V foo(final Y a)\n" + " {\n" + " return null;\n" + " }\n" + " public static , W extends J> void test(final Y a)\n" + " {\n" + " foo(a);\n" + " }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 public void test047() { this.runNegativeTest( // test directory preparation new String[] { /* test files */ "X.java", "public class X {\n" + " void foo(T t) {\n" + " }\n" + "}\n" + "interface I {\n" + " public int method();\n" + "}\n" + "interface J {\n" + " public boolean method();\n" + "}\n" }, // compiler results "----------\n" + /* expected compiler log */ "1. ERROR in X.java (at line 1)\n" + " public class X {\n" + " ^\n" + "The return types are incompatible for the inherited methods I.method(), J.method()\n" + "----------\n", // javac options JavacTestOptions.JavacHasABug.JavacBug5061359 /* javac test options */); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 // Variant: javac complains as well if we attempt to use method, but noone // complains upon bar or CONSTANT. public void test048() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " void foo(T t) {\n" + " t.method();\n" + " t.bar();\n" + " if (t.CONSTANT > 0);\n" + " }\n" + "}\n" + "interface I {\n" + " public int method();\n" + " void bar();\n" + "}\n" + "interface J {\n" + " public boolean method();\n" + " static final int CONSTANT = 0;\n" + "}\n" }, "----------\n" + "1. ERROR in X.java (at line 1)\n" + " public class X {\n" + " ^\n" + "The return types are incompatible for the inherited methods I.method(), J.method()\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " t.method();\n" + " ^^^^^^\n" + "The method method() is ambiguous for the type T\n" + "----------\n" + "3. WARNING in X.java (at line 5)\n" + " if (t.CONSTANT > 0);\n" + " ^^^^^^^^\n" + "The static field J.CONSTANT should be accessed in a static way\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 // can't implement both interfaces though public void test049() { this.runNegativeTest( new String[] { "X.java", "interface I {\n" + " public int method();\n" + "}\n" + "interface J {\n" + " public boolean method();\n" + "}\n" + "class X implements I, J {\n" + " public int method() {\n" + " return 0;\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 8)\n" + " public int method() {\n" + " ^^^\n" + "The return type is incompatible with J.method()\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 // variant: secure the legal case public void test050() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void foo(T t) {\n" + " }\n" + "}\n" + "interface I {\n" + " public int method();\n" + "}\n" + "interface J {\n" + " public int method();\n" + "}\n" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 public void test051() { this.runNegativeTest( false /* skipJavac */, this.complianceLevel < ClassFileConstants.JDK1_8 ? null : JavacTestOptions.EclipseHasABug.EclipseBug427719, new String[] { /* test files */ "X.java", "interface I {\n" + "}\n" + "class Y {\n" + " void bar(I x) {\n" + " }\n" + "}\n" + "public class X extends Y {\n" + " void foo() {\n" + " bar(new Z());\n" + " }\n" + " void bar(Z x) {\n" + " }\n" + " private static final class Z implements I {\n" + " }\n" + "}\n" }, (this.complianceLevel < ClassFileConstants.JDK1_8 ? "----------\n" + "1. ERROR in X.java (at line 9)\n" + " bar(new Z());\n" + " ^^^\n" + "The method bar(X.Z) is ambiguous for the type X\n" + "----------\n" + "2. WARNING in X.java (at line 13)\n" + " private static final class Z implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" : // in 1.8 bar(Z) is recognized as being more specific than bar(I<#RAW>) "----------\n" + "1. WARNING in X.java (at line 9)\n" + " bar(new Z());\n" + " ^^^^^^^\n" + "Access to enclosing constructor X.Z() is emulated by a synthetic accessor method\n" + "----------\n" + "2. WARNING in X.java (at line 13)\n" + " private static final class Z implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n")); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 // variant public void test052() { this.runConformTest( new String[] { "X.java", "interface I {\n" + "}\n" + "class Y {\n" + " void bar(I x) {\n" + " }\n" + "}\n" + "public class X extends Y {\n" + " void foo() {\n" + " bar(new Z());\n" + " }\n" + " void bar(Z x) {\n" + " }\n" + " private static final class Z implements I {\n" + " }\n" + "}\n" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 // variant public void test053() { this.runNegativeTest( false /* skipJavac */, this.complianceLevel < ClassFileConstants.JDK1_8 ? null : JavacTestOptions.EclipseHasABug.EclipseBug427719, new String[] { /* test files */ "X.java", "interface I {\n" + "}\n" + "class Y {\n" + " void bar(I x) {\n" + " }\n" + "}\n" + "public class X extends Y {\n" + " void foo() {\n" + " bar(new Z(){});\n" + " }\n" + " void bar(Z x) {\n" + " }\n" + " private static class Z implements I {\n" + " }\n" + "}\n" }, (this.complianceLevel < ClassFileConstants.JDK1_8 ? "----------\n" + "1. ERROR in X.java (at line 9)\n" + " bar(new Z(){});\n" + " ^^^\n" + "The method bar(X.Z) is ambiguous for the type X\n" + "----------\n" + "2. WARNING in X.java (at line 13)\n" + " private static class Z implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" : // in 1.8 bar(Z) is recognized as being more specific than bar(I<#RAW>) "----------\n" + "1. WARNING in X.java (at line 9)\n" + " bar(new Z(){});\n" + " ^^^\n" + "Access to enclosing constructor X.Z() is emulated by a synthetic accessor method\n" + "----------\n" + "2. WARNING in X.java (at line 13)\n" + " private static class Z implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n")); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 // variant public void test054() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " void bar(Z x) {\n" + " System.out.println(\"bar(Z)\");\n" + " }\n" + " void bar(I x) {\n" + " System.out.println(\"bar(I)\");\n" + " }\n" + " public static void main(String args[]) {\n" + " (new X()).bar(new Z());\n" + " }\n" + "}\n" + "interface I {}\n" + "class Z implements I {}" }, "bar(Z)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 // variant public void _test055() { this.runNegativeTest( new String[] { "X.java", "interface I {}\n" + "class X {\n" + " void bar(Z x) {\n" + " System.out.println(\"bar(Z)\");\n" + " }\n" + " void bar(I x) {\n" + " System.out.println(\"bar(I)\");\n" + " }\n" + " public static void main(String args[]) {\n" + " (new X()).bar(new Z());\n" + " }\n" + "}\n" + "class Z implements I {}" }, "ERR"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=184190 public void test056() { if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; this.runConformTest( new String[] { "X.java", "public class X {\n" + " void bar(X x) {\n" + " ZA z = ZA.foo(x);\n" + " z.toString();\n" + " }\n" + "}\n" + "class Y {\n" + " public static Y foo(X x) {\n" + " return null;\n" + " }\n" + "}\n" + "class YA extends Y {\n" + " public static YA foo(X x) {\n" + " return (YA) Y.foo(x);\n" + " }\n" + "}\n" + "class ZA extends YA {\n" + " public static ZA foo(X x) {\n" + " return (ZA) Y.foo(x);\n" + " }\n" + "}\n" + "abstract class A {\n" + "}\n" + "abstract class B extends A {\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=186382 public void test057() { this.runConformTest( new String[] { "X.java", "public class X extends Y {\n" + " @Override > T4 foo(G4 g) { return super.foo(g); }\n" + "}\n" + "class Y extends Z {\n" + " @Override > T3 foo(G3 g) { return super.foo(g); }\n" + "}\n" + "class Z {\n" + " > T2 foo(G2 g) { return null; }\n" + "}\n" + "interface I {}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=188741 public void test058() { this.runConformTest( new String[] { "X.java", "public class X extends A {\n" + " void x(G g) { System.out.print(1); }\n" + " void x(G g, G g2) { System.out.print(1); }\n" + " public static void main(String[] s) {\n" + " H h = new H();\n" + " new X().x(h);\n" + " new X().x(h, h);\n" + " }\n" + "}\n" + "class A {\n" + " void x(T t) { System.out.print(2); }\n" + " void x(T t, U u) { System.out.print(2); }\n" + "}\n" + "class F {}\n" + "class G extends F {}\n" + "class H extends G {}" }, "11"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=188741 public void test058a() { this.runConformTest( new String[] { "X.java", "public class X extends java.util.ArrayList {\n" + " private static final long serialVersionUID = 1L;\n" + " public void add(Comparable o) {}\n" + " public void test() { add(\"hello\"); }\n" + "}" }, ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=188960 public void test059() { this.runNegativeTest( new String[] { "X.java", "class X {\n" + " X() {}\n" + " X(String s) {}\n" + " X(T t) {}\n" + " void foo(String s) {}\n" + " void foo(T t) {}\n" + "}\n" + "class NoErrorSubclass extends X {}\n" + "class StringOnlySubClass extends X {\n" + " StringOnlySubClass(String s) { super(s); }\n" + " @Override void foo(String s) { super.foo(s); }\n" + "}\n" + "class Test {\n" + " Object o = new X(\"xyz\");\n" + " void test(X x) { x.foo(\"xyz\"); }\n" + "}" }, // no error is reported against duplicate constructors - but the call is reported as ambiguous "----------\n" + "1. ERROR in X.java (at line 8)\n" + " class NoErrorSubclass extends X {}\n" + " ^^^^^^^^^^^^^^^\n" + "Duplicate methods named foo with the parameters (T) and (String) are defined by the type X\n" + "----------\n" + "2. ERROR in X.java (at line 10)\n" + " StringOnlySubClass(String s) { super(s); }\n" + " ^^^^^^^^^\n" + "The constructor X(String) is ambiguous\n" + "----------\n" + "3. ERROR in X.java (at line 11)\n" + " @Override void foo(String s) { super.foo(s); }\n" + " ^^^\n" + "The method foo(String) is ambiguous for the type X\n" + "----------\n" + "4. ERROR in X.java (at line 14)\n" + " Object o = new X(\"xyz\");\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "The constructor X(String) is ambiguous\n" + "----------\n" + "5. ERROR in X.java (at line 15)\n" + " void test(X x) { x.foo(\"xyz\"); }\n" + " ^^^\n" + "The method foo(String) is ambiguous for the type X\n" + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=191029 public void test059a() { this.runNegativeTest( new String[] { "X.java", "import java.util.TreeMap;\n" + "class X {\n" + " void test(TreeMap tm) {\n" + " TreeMap copy = new TreeMap(tm);\n" + " }\n" + "}" }, "----------\n" + "1. WARNING in X.java (at line 4)\n" + " TreeMap copy = new TreeMap(tm);\n" + " ^^^^^^^\n" + "TreeMap is a raw type. References to generic type TreeMap should be parameterized\n" + "----------\n" + "2. WARNING in X.java (at line 4)\n" + " TreeMap copy = new TreeMap(tm);\n" + " ^^^^^^^^^^^^^^^\n" + "Type safety: The constructor TreeMap(SortedMap) belongs to the raw type TreeMap. References to generic type TreeMap should be parameterized\n" + "----------\n" + "3. WARNING in X.java (at line 4)\n" + " TreeMap copy = new TreeMap(tm);\n" + " ^^^^^^^\n" + "TreeMap is a raw type. References to generic type TreeMap should be parameterized\n" + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 public void test060() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " public void bar(K p) {\n" + " new Y(p);\n" + " new Y((J) p);\n" + " new Y((I) p);\n" + " }\n" + "}\n" + "class Y {\n" + " Y(I p) {}\n" + " Y(J p) {}\n" + "}\n" + "interface I {}\n" + "interface J extends I {}\n" + "interface K extends I, J {}" }, "" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 // variant public void test061() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " public void bar(K p) {\n" + " new Y(p);\n" + " new Y((J) p);\n" + " new Y((I) p);\n" + " }\n" + "}\n" + "class Y {\n" + " Y(I p) {}\n" + " Y(J p) {}\n" + "}\n" + "interface I {}\n" + "interface J {}\n" + "interface K extends I, J {}" }, "----------\n" + "1. ERROR in X.java (at line 3)\n" + " new Y(p);\n" + " ^^^^^^^^\n" + "The constructor Y(I) is ambiguous\n" + "----------\n" + "2. WARNING in X.java (at line 3)\n" + " new Y(p);\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" + "3. WARNING in X.java (at line 4)\n" + " new Y((J) p);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: The constructor Y(J) belongs to the raw type Y. References to generic type Y should be parameterized\n" + "----------\n" + "4. WARNING in X.java (at line 4)\n" + " new Y((J) p);\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" + "5. WARNING in X.java (at line 5)\n" + " new Y((I) p);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: The constructor Y(I) belongs to the raw type Y. References to generic type Y should be parameterized\n" + "----------\n" + "6. WARNING in X.java (at line 5)\n" + " new Y((I) p);\n" + " ^\n" + "Y is a raw type. References to generic type Y should be parameterized\n" + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=193265 public void test062() { this.runConformTest( new String[] { "X.java", "enum E implements I {\n" + " F;\n" + "}\n" + "interface I {}\n" + "interface Spec {\n" + " & I> void method(T1 t);\n" + "}\n" + "abstract class X implements Spec {\n" + " public & I> void method(T2 t) {}\n" + " void test() { method(E.F); }\n" + "}" }, "" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=196254 public void test063() { this.runConformTest( new String[] { "Test.java", "interface I {}\n" + "class X {\n" + " void method(X that) {}\n" + "}\n" + "class Y extends X {\n" + " @Override void method(X that) { System.out.print(1); }\n" + "}\n" + "public class Test {\n" + " public static void main(String[] args) { new Y().method((X) null); }\n" + "}" }, "1" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=198120 public void test064() { this.runConformTest( new String[] { "A.java", "interface I {\n" + " void x(I i);\n" + "}\n" + "public abstract class A implements I {\n" + " public void x(I i) {}\n" + "}\n" + "class B extends A {\n" + " void y(A a) { super.x(a); }\n" + "}" }, "" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=200547 public void test065() { this.runConformTest( new String[] { "A.java", "public abstract class A {\n" + " abstract > void m(T x);\n" + "}\n" + "class B extends A {\n" + " @Override > void m(T x) {}\n" + "}" }, "" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=214558 public void test066() { this.runNegativeTest( new String[] { "A.java", "import java.util.*;\n" + "public class A {\n" + " void foo(Collection c) {}\n" + " void foo(Collection c, Object o) {}\n" + " public static void main(String[] args) {\n" + " new B().foo(new ArrayList());\n" + " new B().foo(new ArrayList(), args[0]);\n" + " }\n" + "}\n" + "class B extends A {\n" + " void foo(ArrayList a) {}\n" + " void foo(ArrayList a, Object o) {}\n" + "}" }, "----------\n" + "1. ERROR in A.java (at line 6)\n" + " new B().foo(new ArrayList());\n" + " ^^^\n" + "The method foo(ArrayList) is ambiguous for the type B\n" + "----------\n" + "2. WARNING in A.java (at line 6)\n" + " new B().foo(new ArrayList());\n" + " ^^^^^^^^^\n" + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + "----------\n" + "3. ERROR in A.java (at line 7)\n" + " new B().foo(new ArrayList(), args[0]);\n" + " ^^^\n" + "The method foo(ArrayList, Object) is ambiguous for the type B\n" + "----------\n" + "4. WARNING in A.java (at line 7)\n" + " new B().foo(new ArrayList(), args[0]);\n" + " ^^^^^^^^^\n" + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + "----------\n" + "5. WARNING in A.java (at line 11)\n" + " void foo(ArrayList a) {}\n" + " ^^^^^^^^^\n" + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + "----------\n" + "6. WARNING in A.java (at line 12)\n" + " void foo(ArrayList a, Object o) {}\n" + " ^^^^^^^^^\n" + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=214558 - positive case public void test067() { this.runConformTest( new String[] { "A.java", "import java.util.*;\n" + "public class A {\n" + " void foo(Collection c) {}\n" + " public static void main(String[] args) {\n" + " new B().foo(new ArrayList());\n" + " }\n" + "}\n" + "class B extends A {\n" + " void foo(ArrayList a) {System.out.print(1);}\n" + "}" }, "1" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 public void test068() { this.runConformTest( new String[] { "X.java", "interface A { X foo(); }\n" + "interface B extends A { X foo(); }\n" + "interface C extends B, A {}\n" + "interface D extends A, B {}\n" + "public class X {\n" + " public void bar() {\n" + " C c = null;\n" + " X c_b = c.foo();\n" + " D d = null;\n" + " X d_b = d.foo();\n" + " }\n" + "}" }, "" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation public void test069() { this.runNegativeTest( new String[] { "X.java", "interface A { X foo(); }\n" + "interface B extends A { X foo(); }\n" + "interface C extends B, A {}\n" + "interface D extends A, B {}\n" + "public class X {\n" + " void test(C c, D d) {\n" + " X c_b = c.foo();\n" + " X d_b = d.foo();\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 2)\n" + " interface B extends A { X foo(); }\n" + " ^^^^^^^^^^^^^^\n" + "The return type is incompatible with A.foo()\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation public void test070() { this.runNegativeTest( new String[] { "X.java", "interface A { X foo(); }\n" + "interface B { X foo(); }\n" + "interface C extends B, A {}\n" + "interface D extends A, B {}\n" + "public class X {\n" + " public static void main(String[] args) {\n" + " C c = null;\n" + " X c_b = c.foo();\n" + " D d = null;\n" + " X d_b = d.foo();\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 3)\n" + " interface C extends B, A {}\n" + " ^\n" + "The return types are incompatible for the inherited methods B.foo(), A.foo()\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " interface D extends A, B {}\n" + " ^\n" + "The return types are incompatible for the inherited methods A.foo(), B.foo()\n" + "----------\n" + "3. ERROR in X.java (at line 8)\n" + " X c_b = c.foo();\n" + " ^^^\n" + "The method foo() is ambiguous for the type C\n" + "----------\n" + "4. ERROR in X.java (at line 10)\n" + " X d_b = d.foo();\n" + " ^^^\n" + "The method foo() is ambiguous for the type D\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation public void test071() { this.runConformTest( new String[] { "Y.java", "interface I {\n" + " Integer a();\n" + " Float b();\n" + "}\n" + "interface J {\n" + " Integer a();\n" + " Double c();\n" + "}\n" + "abstract class X {\n" + " public abstract Float b();\n" + " public Double c() { return null; }\n" + "}\n" + "abstract class Y extends X implements I, J {\n" + " void test() {\n" + " Integer i = a();\n" + " Float f = b();\n" + " Double d = c();\n" + " }\n" + "}" }, "" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation public void test072() { this.runConformTest( new String[] { "Y.java", "interface I {\n" + " Number a();\n" + " Number b();\n" + "}\n" + "interface J {\n" + " Integer a();\n" + " Number c();\n" + "}\n" + "abstract class X {\n" + " public abstract Float b();\n" + " public Double c() { return null; }\n" + "}\n" + "abstract class Y extends X implements I, J {\n" + " void test() {\n" + " Integer i = a();\n" + " Float f = b();\n" + " Double d = c();\n" + " }\n" + "}\n" + "abstract class Y2 extends X implements J, I {\n" + " void test() {\n" + " Integer i = a();\n" + " Float f = b();\n" + " Double d = c();\n" + " }\n" + "}" }, "" // javac reports 4 ambiguous errors, 2 each of a() & b() even tho the return types are sustitutable ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation public void test073() { this.runNegativeTest( new String[] { "Y.java", "interface I {\n" + " int a();\n" + " int b();\n" + "}\n" + "interface J {\n" + " byte a();\n" + " int c();\n" + "}\n" + "abstract class X {\n" + " public abstract byte b();\n" + " public byte c() { return 1; }\n" + "}\n" + "abstract class Y extends X implements I, J {\n" + " void test() {\n" + " byte a = a();\n" + " byte b = b();\n" + " byte c = c();\n" + " }\n" + "}\n" + "abstract class Y2 extends X implements J, I {\n" + " void test() {\n" + " byte a = a();\n" + " byte b = b();\n" + " byte c = c();\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in Y.java (at line 13)\n" + " abstract class Y extends X implements I, J {\n" + " ^\n" + "The return types are incompatible for the inherited methods J.c(), X.c()\n" + "----------\n" + "2. ERROR in Y.java (at line 13)\n" + " abstract class Y extends X implements I, J {\n" + " ^\n" + "The return types are incompatible for the inherited methods I.b(), X.b()\n" + "----------\n" + "3. ERROR in Y.java (at line 13)\n" + " abstract class Y extends X implements I, J {\n" + " ^\n" + "The return types are incompatible for the inherited methods I.a(), J.a()\n" + "----------\n" + "4. ERROR in Y.java (at line 20)\n" + " abstract class Y2 extends X implements J, I {\n" + " ^^\n" + "The return types are incompatible for the inherited methods J.c(), X.c()\n" + "----------\n" + "5. ERROR in Y.java (at line 20)\n" + " abstract class Y2 extends X implements J, I {\n" + " ^^\n" + "The return types are incompatible for the inherited methods I.b(), X.b()\n" + "----------\n" + "6. ERROR in Y.java (at line 20)\n" + " abstract class Y2 extends X implements J, I {\n" + " ^^\n" + "The return types are incompatible for the inherited methods J.a(), I.a()\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=206930 public void test074() { this.runNegativeTest( false /* skipJavac */, this.complianceLevel < ClassFileConstants.JDK1_8 ? null : JavacTestOptions.EclipseHasABug.EclipseBug427719, new String[] { "Y.java", "interface I {}\n" + "class A {\n" + " void a(I x) {}\n" + " void b(I x) {}\n" + " void b(I[] x) {}\n" + " void c(I x) {}\n" + "}\n" + "class B extends A {}\n" + "class C extends B implements I {\n" + " void a(C c) {}\n" + " void b(C c) {}\n" + " void b(C[] c) {}\n" + " void c(C c) {}\n" + "}\n" + "class D extends C {\n" + " void test() {\n" + " a(new C());\n" + " a(new D());\n" + " b(new C());\n" + // ambiguous b(I) in A and b(C) in C match " b(new D());\n" + // ambiguous b(I) in A and b(C) in C match " b(new C[0]);\n" + // ambiguous b(I[]) in A and b(C[]) in C match " b(new D[0]);\n" + // ambiguous b(I[]) in A and b(C[]) in C match " c(new C());\n" + // ambiguous c(I) in A and c(C) in C match " c(new D());\n" + // ambiguous c(I) in A and c(C) in C match " }\n" + "}\n" + "class A2 {\n" + " void a(I x) {}\n" + " void b(I x) {}\n" + " void c(I x) {}\n" + " void d(I x) {}\n" + "}\n" + "class B2 extends A2 {}\n" + "class C2 extends B2 implements I {\n" + " void a(C2 c) {}\n" + " void b(C2 c) {}\n" + " void c(C2 c) {}\n" + " void d(C2 c) {}\n" + "}\n" + "class D2 extends C2 {\n" + " void test() {\n" + " a(new C2());\n" + " a(new D2());\n" + " b(new C2());\n" + " b(new D2());\n" + " c(new C2());\n" + " c(new D2());\n" + " d(new C2());\n" + " d(new D2());\n" + " }\n" + "}\n" + "public class Y {}\n" }, (this.complianceLevel < ClassFileConstants.JDK1_8 ? "----------\n" + "1. WARNING in Y.java (at line 3)\n" + " void a(I x) {}\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "2. WARNING in Y.java (at line 9)\n" + " class C extends B implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "3. ERROR in Y.java (at line 19)\n" + " b(new C());\n" + " ^\n" + "The method b(C) is ambiguous for the type D\n" + "----------\n" + "4. ERROR in Y.java (at line 20)\n" + " b(new D());\n" + " ^\n" + "The method b(C) is ambiguous for the type D\n" + "----------\n" + "5. ERROR in Y.java (at line 21)\n" + " b(new C[0]);\n" + " ^\n" + "The method b(C[]) is ambiguous for the type D\n" + "----------\n" + "6. ERROR in Y.java (at line 22)\n" + " b(new D[0]);\n" + " ^\n" + "The method b(C[]) is ambiguous for the type D\n" + "----------\n" + "7. ERROR in Y.java (at line 23)\n" + " c(new C());\n" + " ^\n" + "The method c(C) is ambiguous for the type D\n" + "----------\n" + "8. ERROR in Y.java (at line 24)\n" + " c(new D());\n" + " ^\n" + "The method c(C) is ambiguous for the type D\n" + "----------\n" + "9. WARNING in Y.java (at line 28)\n" + " void a(I x) {}\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "10. WARNING in Y.java (at line 33)\n" + " class B2 extends A2 {}\n" + " ^^\n" + "A2 is a raw type. References to generic type A2 should be parameterized\n" + "----------\n" + "11. WARNING in Y.java (at line 34)\n" + " class C2 extends B2 implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" : // no ambiguities in 1.8 "----------\n" + "1. WARNING in Y.java (at line 3)\n" + " void a(I x) {}\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "2. WARNING in Y.java (at line 9)\n" + " class C extends B implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "3. WARNING in Y.java (at line 28)\n" + " void a(I x) {}\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "4. WARNING in Y.java (at line 33)\n" + " class B2 extends A2 {}\n" + " ^^\n" + "A2 is a raw type. References to generic type A2 should be parameterized\n" + "----------\n" + "5. WARNING in Y.java (at line 34)\n" + " class C2 extends B2 implements I {\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n") ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=266421 public void test075() { this.runNegativeTest( new String[] { "C.java", "abstract class A {\n" + " abstract int x(T val);\n" + "}\n" + "class B extends A {\n" + " @Override int x(T val) { return 0; }\n" + "}\n" + "class C extends B {\n" + " int test(Double val) { return x(val); }\n" + "}" }, "----------\n" + "1. WARNING in C.java (at line 1)\n" + " abstract class A {\n" + " ^^^^^^^^^^\n" + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + "----------\n" + "2. WARNING in C.java (at line 4)\n" + " class B extends A {\n" + " ^^^^^^^^^^\n" + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=268837 // See that this test case exhibits the bug 345947 public void test076() { String output = (this.complianceLevel == ClassFileConstants.JDK1_6)? "----------\n" + "1. WARNING in X.java (at line 8)\n" + " J b();\n" + " ^^^\n" + "Name clash: The method b() of type J has the same erasure as b() of type I but does not override it\n" + "----------\n" + "2. ERROR in X.java (at line 15)\n" + " J b = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to J\n" + "----------\n" + "3. ERROR in X.java (at line 16)\n" + " J c = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to J\n" + "----------\n" + "4. WARNING in X.java (at line 17)\n" + " J d = ints.a();\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "5. ERROR in X.java (at line 19)\n" + " I f = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to I\n" + "----------\n" + "6. ERROR in X.java (at line 20)\n" + " I g = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to I\n" + "----------\n" + "7. WARNING in X.java (at line 21)\n" + " I h = ints.a();\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "8. ERROR in X.java (at line 24)\n" + " ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "9. ERROR in X.java (at line 25)\n" + " J a = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "10. ERROR in X.java (at line 26)\n" + " J b = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "11. ERROR in X.java (at line 27)\n" + " J c = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "12. WARNING in X.java (at line 28)\n" + " J d = ints.b();\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "13. ERROR in X.java (at line 28)\n" + " J d = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "14. ERROR in X.java (at line 29)\n" + " I e = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "15. ERROR in X.java (at line 30)\n" + " I f = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "16. ERROR in X.java (at line 31)\n" + " I g = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "17. WARNING in X.java (at line 32)\n" + " I h = ints.b();\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "18. ERROR in X.java (at line 32)\n" + " I h = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "19. WARNING in X.java (at line 39)\n" + " J d = ints.c();\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "20. WARNING in X.java (at line 43)\n" + " I h = ints.c();\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n": "----------\n" + "1. ERROR in X.java (at line 8)\n" + " J b();\n" + " ^^^\n" + "Name clash: The method b() of type J has the same erasure as b() of type I but does not override it\n" + "----------\n" + "2. ERROR in X.java (at line 15)\n" + " J b = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to J\n" + "----------\n" + "3. ERROR in X.java (at line 16)\n" + " J c = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to J\n" + "----------\n" + "4. WARNING in X.java (at line 17)\n" + " J d = ints.a();\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "5. ERROR in X.java (at line 19)\n" + " I f = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to I\n" + "----------\n" + "6. ERROR in X.java (at line 20)\n" + " I g = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J to I\n" + "----------\n" + "7. WARNING in X.java (at line 21)\n" + " I h = ints.a();\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "8. ERROR in X.java (at line 24)\n" + " ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "9. ERROR in X.java (at line 25)\n" + " J a = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "10. ERROR in X.java (at line 26)\n" + " J b = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "11. ERROR in X.java (at line 27)\n" + " J c = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "12. WARNING in X.java (at line 28)\n" + " J d = ints.b();\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "13. ERROR in X.java (at line 28)\n" + " J d = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "14. ERROR in X.java (at line 29)\n" + " I e = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "15. ERROR in X.java (at line 30)\n" + " I f = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "16. ERROR in X.java (at line 31)\n" + " I g = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "17. WARNING in X.java (at line 32)\n" + " I h = ints.b();\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n" + "18. ERROR in X.java (at line 32)\n" + " I h = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J\n" + "----------\n" + "19. WARNING in X.java (at line 39)\n" + " J d = ints.c();\n" + " ^\n" + "J is a raw type. References to generic type J should be parameterized\n" + "----------\n" + "20. WARNING in X.java (at line 43)\n" + " I h = ints.c();\n" + " ^\n" + "I is a raw type. References to generic type I should be parameterized\n" + "----------\n"; this.runNegativeTest( new String[] { "X.java", "interface I {\n" + " I a();\n" + " I b();\n" + " I c();\n" + "}\n" + "interface J extends I {\n" + " J a();\n" + " J b();\n" + " J c();\n" + "}\n" + "class X {\n" + " void a(J ints) {\n" + " ints.a();\n" + " J a = ints.a();\n" + " J b = ints.a();\n" + // incompatible types " J c = ints.a();\n" + // incompatible types " J d = ints.a();\n" + " I e = ints.a();\n" + " I f = ints.a();\n" + // incompatible types " I g = ints.a();\n" + // incompatible types " I h = ints.a();\n" + " }\n" + " void b(J ints) {\n" + " ints.b();\n" + // ambiguous " J a = ints.b();\n" + // ambiguous " J b = ints.b();\n" + // ambiguous " J c = ints.b();\n" + // ambiguous " J d = ints.b();\n" + // ambiguous " I e = ints.b();\n" + // ambiguous " I f = ints.b();\n" + // ambiguous " I g = ints.b();\n" + // ambiguous " I h = ints.b();\n" + // ambiguous " }\n" + " void c(J ints) {\n" + " ints.c();\n" + " J a = ints.c();\n" + " J b = ints.c();\n" + " J c = ints.c();\n" + " J d = ints.c();\n" + " I e = ints.c();\n" + " I f = ints.c();\n" + " I g = ints.c();\n" + " I h = ints.c();\n" + " }\n" + "}" }, output ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=270194 public void test077() { this.runConformTest( new String[] { "X.java", "abstract class X implements I {\n" + " public , D extends J> A method(A arg) { return null; }\n" + " void test(Y c) { method(c); }\n" + "}\n" + "interface I {\n" + " , D extends J> A method(A arg);\n" + "}\n" + "interface J, D extends J> {}\n" + "class Y implements J, Y> {}" }, "" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=287592 public void test078() { this.runNegativeTest( new String[] { "X.java", "class X {\n" + " class Field { T value; }\n" + " void a(T value) {}\n" + " void a(Field field) {}\n" + " void b(T value) {}\n" + " void b(Field field) {}\n" + " void c(String value) {}\n" + " void c(Field field) {}\n" + " void test(X x) {\n" + " x.a(null);\n" + " x.a(null);\n" + " x.b(null);\n" + " x.b(null);\n" + " x.c(null);\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 12)\n" + " x.b(null);\n" + " ^\n" + "The method b(Number) is ambiguous for the type X\n" + "----------\n" + "2. ERROR in X.java (at line 13)\n" + " x.b(null);\n" + " ^\n" + "The method b(Integer) is ambiguous for the type X\n" + "----------\n" + "3. ERROR in X.java (at line 14)\n" + " x.c(null);\n" + " ^\n" + "The method c(String) is ambiguous for the type X\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=292350 // See that this test case exhibits the bug 345947 public void test079() { this.runNegativeTest( new String[] { "X.java", "interface I {}\n" + "class A {}\n" + "class B extends A {}\n" + "interface One {\n" + " I x() throws IllegalAccessError;\n" + " I y() throws IllegalAccessError;\n" + "}\n" + "interface Two extends One {\n" + " I x() throws IllegalAccessError;\n" + " I y() throws IllegalAccessError;\n" + "}\n" + "class X {\n" + " void x(Two t) { t.x(); }\n" + " void y(Two t) { t.y(); }\n" + "}" }, "----------\n" + "1. ERROR in X.java (at line 9)\n" + " I x() throws IllegalAccessError;\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Name clash: The method x() of type Two has the same erasure as x() of type One but does not override it\n" + "----------\n" + "2. WARNING in X.java (at line 10)\n" + " I y() throws IllegalAccessError;\n" + " ^\n" + "Type safety: The return type I for y() from the type Two needs unchecked conversion to conform to I from the type One\n" + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=293384 public void test080() { this.runConformTest( new String[] { "X.java", "public class X {\n" + " static public abstract class BaseA {};\n" + " static public abstract class BaseB extends BaseA {};\n" + " static public class Real extends BaseB {};\n" + " static BaseA ask(String prompt) {\n" + " Real impl = new Real();\n" + " return (BaseA) ask(prompt, impl);\n" + " }\n" + " static BaseA ask(String prompt, Real impl) {\n" + " return null;\n" + " }\n" + " static T ask(String prompt, T impl) {\n" + " return null;\n" + " }\n" + " static public void main(String[] args) {\n" + " System.out.println(\"SUCCESS\");\n" + " }\n" + "}\n" }, "SUCCESS"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 public void test081() { this.runConformTest( new String[] { "C.java", "class A implements I {\n" + " public void doSet(ModelType valueGetter) {\n" + " this.set((ValueType) valueGetter.getObject());\n" + " }\n" + " public void set(Object object) {\n" + " System.out.println(\"In A.set(Object)\");\n" + " }\n" + "}\n" + "class B extends A {\n" + " public void set(CharSequence string) {\n" + " System.out.println(\"In B.set(CharSequence)\");\n" + " }\n" + "}\n" + "public class C extends B {\n" + " static public void main(String[] args) {\n" + " C c = new C();\n" + " c.run();\n" + " }\n" + " public void run() {\n" + " E e = new E(String.class);\n" + " this.doSet(e);\n" + " }\n" + "}\n" + "class D {\n" + " public Object getObject() {\n" + " return null;\n" + " }\n" + "}\n" + "class E extends D {\n" + " private Class typeClass;\n" + " public E(Class typeClass) {\n" + " this.typeClass = typeClass;\n" + " }\n" + " public Type getObject() {\n" + " try {\n" + " return (Type) typeClass.newInstance();\n" + " } catch (Exception e) {\n" + " throw new RuntimeException(e);\n" + " }\n" + " }\n" + "}\n" + "interface I {\n" + " public void doSet(ModelType model);\n" + " public void set(ValueType value);\n" + "}\n" }, "In B.set(CharSequence)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 public void test082() { this.runConformTest( new String[] { "C.java", "class A extends I {\n" + " public void doSet(ModelType valueGetter) {\n" + " this.set((ValueType) valueGetter.getObject());\n" + " }\n" + " public void set(Object object) {\n" + " System.out.println(\"In A.set(Object)\");\n" + " }\n" + "}\n" + "class B extends A {\n" + " public void set(CharSequence string) {\n" + " System.out.println(\"In B.set(CharSequence)\");\n" + " }\n" + "}\n" + "public class C extends B {\n" + " static public void main(String[] args) {\n" + " C c = new C();\n" + " c.run();\n" + " }\n" + " public void run() {\n" + " E e = new E(String.class);\n" + " this.doSet(e);\n" + " }\n" + "}\n" + "class D {\n" + " public Object getObject() {\n" + " return null;\n" + " }\n" + "}\n" + "class E extends D {\n" + " private Class typeClass;\n" + " public E(Class typeClass) {\n" + " this.typeClass = typeClass;\n" + " }\n" + " public Type getObject() {\n" + " try {\n" + " return (Type) typeClass.newInstance();\n" + " } catch (Exception e) {\n" + " throw new RuntimeException(e);\n" + " }\n" + " }\n" + "}\n" + "abstract class I {\n" + " public abstract void doSet(ModelType model);\n" + " public abstract void set(ValueType value);\n" + "}\n" }, "In B.set(CharSequence)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 public void test083() { this.runConformTest( new String[] { "C.java", "class A implements I {\n" + " public void doSet(ModelType valueGetter) {\n" + " this.set((ValueType) valueGetter.getObject());\n" + " }\n" + " public void set(Object object) {\n" + " System.out.println(\"In A.set(Object)\");\n" + " }\n" + "}\n" + "class B extends A implements I {\n" + " public void set(CharSequence string) {\n" + " System.out.println(\"In B.set(CharSequence)\");\n" + " }\n" + "}\n" + "public class C extends B {\n" + " static public void main(String[] args) {\n" + " C c = new C();\n" + " c.run();\n" + " }\n" + " public void run() {\n" + " E e = new E(String.class);\n" + " this.doSet(e);\n" + " }\n" + "}\n" + "class D {\n" + " public Object getObject() {\n" + " return null;\n" + " }\n" + "}\n" + "class E extends D {\n" + " private Class typeClass;\n" + " public E(Class typeClass) {\n" + " this.typeClass = typeClass;\n" + " }\n" + " public Type getObject() {\n" + " try {\n" + " return (Type) typeClass.newInstance();\n" + " } catch (Exception e) {\n" + " throw new RuntimeException(e);\n" + " }\n" + " }\n" + "}\n" + "interface I {\n" + " public void doSet(ModelType model);\n" + " public void set(ValueType value);\n" + "}\n" }, "In B.set(CharSequence)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 public void test084() { this.runConformTest( new String[] { "C.java", "abstract class A implements I {\n" + " public void doSet(ModelType valueGetter) {\n" + " this.set((ValueType) valueGetter.getObject());\n" + " }\n" + " public void set(Object object) {\n" + " System.out.println(\"In A.set(Object)\");\n" + " }\n" + "}\n" + "class B extends A {\n" + "}\n" + "public class C extends B {\n" + " static public void main(String[] args) {\n" + " C c = new C();\n" + " c.run();\n" + " }\n" + " public void run() {\n" + " E e = new E(String.class);\n" + " this.doSet(e);\n" + " }\n" + "}\n" + "class D {\n" + " public Object getObject() {\n" + " return null;\n" + " }\n" + "}\n" + "class E extends D {\n" + " private Class typeClass;\n" + " public E(Class typeClass) {\n" + " this.typeClass = typeClass;\n" + " }\n" + " public Type getObject() {\n" + " try {\n" + " return (Type) typeClass.newInstance();\n" + " } catch (Exception e) {\n" + " throw new RuntimeException(e);\n" + " }\n" + " }\n" + "}\n" + "interface I {\n" + " public void doSet(ModelType model);\n" + " public void set(ValueType value);\n" + "}\n" }, "In A.set(Object)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 public void test085() { this.runConformTest( new String[] { "C.java", "class A implements I {\n" + " public void doSet(ModelType valueGetter) {\n" + " this.set((ValueType) valueGetter.getObject());\n" + " }\n" + " public void set(Object object) {\n" + " System.out.println(\"In A.set(Object)\");\n" + " }\n" + "}\n" + "class B extends A {\n" + "}\n" + "public class C extends B {\n" + " static public void main(String[] args) {\n" + " C c = new C();\n" + " c.run();\n" + " }\n" + " public void run() {\n" + " E e = new E(String.class);\n" + " this.doSet(e);\n" + " }\n" + "}\n" + "class D {\n" + " public Object getObject() {\n" + " return null;\n" + " }\n" + "}\n" + "class E extends D {\n" + " private Class typeClass;\n" + " public E(Class typeClass) {\n" + " this.typeClass = typeClass;\n" + " }\n" + " public Type getObject() {\n" + " try {\n" + " return (Type) typeClass.newInstance();\n" + " } catch (Exception e) {\n" + " throw new RuntimeException(e);\n" + " }\n" + " }\n" + "}\n" + "interface I {\n" + " public void doSet(ModelType model);\n" + " public void set(ValueType value);\n" + "}\n" }, "In A.set(Object)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 public void test086() { this.runConformTest( new String[] { "C.java", "class A {\n" + " public void doSet(ModelType valueGetter) {\n" + " this.set((ValueType) valueGetter.getObject());\n" + " }\n" + " public void set(Object object) {\n" + " System.out.println(\"In A.set(Object)\");\n" + " }\n" + "}\n" + "class B extends A {\n" + " public void set(CharSequence string) {\n" + " System.out.println(\"In B.set(CharSequence)\");\n" + " }\n" + "}\n" + "public class C extends B {\n" + " static public void main(String[] args) {\n" + " C c = new C();\n" + " c.run();\n" + " }\n" + " public void run() {\n" + " E e = new E(String.class);\n" + " this.doSet(e);\n" + " }\n" + "}\n" + "class D {\n" + " public Object getObject() {\n" + " return null;\n" + " }\n" + "}\n" + "class E extends D {\n" + " private Class typeClass;\n" + " public E(Class typeClass) {\n" + " this.typeClass = typeClass;\n" + " }\n" + " public Type getObject() {\n" + " try {\n" + " return (Type) typeClass.newInstance();\n" + " } catch (Exception e) {\n" + " throw new RuntimeException(e);\n" + " }\n" + " }\n" + "}\n" + "interface I {\n" + " public void doSet(ModelType model);\n" + " public void set(ValueType value);\n" + "}\n" }, "In A.set(Object)"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321485 public void test087() { this.runNegativeTest( new String[] { "X.java", "import java.util.Collection;\n" + "import java.util.List;\n" + "public class X {\n" + " public static List with(List p) { return null; } \n" + " public static Collection with(Collection p) { return null; }\n" + " static { with(null); }\n" + "} \n" }, "----------\n" + "1. ERROR in X.java (at line 6)\n" + " static { with(null); }\n" + " ^^^^\n" + "The method with(List) is ambiguous for the type X\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579 public void test088a() { this.runNegativeTest( new String[] { "X.java", "public class X {\n" + " int foo () { return 0; } \n" + " double foo() { return 0.0; }\n" + "} \n" }, "----------\n" + "1. ERROR in X.java (at line 2)\n" + " int foo () { return 0; } \n" + " ^^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " double foo() { return 0.0; }\n" + " ^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" ); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579 public void test088b() { this.runNegativeTest( new String[] { "X.java", "public interface X {\n" + " int foo (); \n" + " double foo();\n" + "} \n" }, "----------\n" + "1. ERROR in X.java (at line 2)\n" + " int foo (); \n" + " ^^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " double foo();\n" + " ^^^^^\n" + "Duplicate method foo() in type X\n" + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579 public void test089() { this.runNegativeTest( new String[] { "X.java", "import java.util.List;\n" + "public class X {\n" + " int m2(List a) {return 0;} \n" + " double m2(List b) {return 0.0;}\n" + "} \n" }, "----------\n" + "1. ERROR in X.java (at line 3)\n" + " int m2(List a) {return 0;} \n" + " ^^^^^^^^^^^^^^^^^^^\n" + "Duplicate method m2(List) in type X\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " double m2(List b) {return 0.0;}\n" + " ^^^^^^^^^^^^^^^^^^^\n" + "Duplicate method m2(List) in type X\n" + "----------\n" ); } public void testBug426521() { runNegativeTest( new String[] { "Test.java", "import java.util.List;\n" + "\n" + "class Test {\n" + " void m(List l, U v) { }\n" + "\n" + " void m(List l1, List l2) { }\n" + "\n" + " void test(List l) {\n" + " m(l, l); //JDK 6/7 give ambiguity here - EJC compiles ok\n" + " }\n" + "}\n" }, this.complianceLevel < ClassFileConstants.JDK1_8 ? "" : "----------\n" + "1. ERROR in Test.java (at line 9)\n" + " m(l, l); //JDK 6/7 give ambiguity here - EJC compiles ok\n" + " ^\n" + "The method m(List, Object) is ambiguous for the type Test\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=428845 public void testBug428845() { runNegativeTest( new String[] { "AmbiguousTest.java", "import java.io.File;\n" + "public class AmbiguousTest {\n" + " static interface IInterface {\n" + " public void method(File file);\n" + " }\n" + " static abstract class AbstractClass implements IInterface {\n" + " public void method(File file) {\n" + " System.err.println(\"file\");\n" + " }\n" + " public void method(String string) {\n" + " System.err.println(\"string\");\n" + " }\n" + " }\n" + " private static AbstractClass newAbstractClass() {\n" + " return new AbstractClass() {};\n" + " }\n" + " public static void main(String[] args) {\n" + " newAbstractClass().method(null);\n" + " }\n" + "}" }, "----------\n" + "1. ERROR in AmbiguousTest.java (at line 18)\n" + " newAbstractClass().method(null);\n" + " ^^^^^^\n" + "The method method(File) is ambiguous for the type AmbiguousTest.AbstractClass\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=458563 - invalid ambiguous method error on Java 8 that isn't seen on Java 7 (or with javac) public void testBug458563() { runConformTest( new String[] { "X.java", "interface IStoredNode extends INodeHandle, NodeHandle { }\n" + "interface NodeHandle extends INodeHandle { }\n" + "class DocumentImpl implements INodeHandle {\n" + " public Object getNodeId() {return null;}\n" + "}\n" + "interface INodeHandle {\n" + " public Object getNodeId();\n" + "}\n" + "public class X {\n" + " public void foo(IStoredNode bar) {\n" + " bar.getNodeId();\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=458563 - invalid ambiguous method error on Java 8 that isn't seen on Java 7 (or with javac) public void testBug458563a() { runConformTest( new String[] { "X.java", "interface IStoredNode extends INodeHandle, NodeHandle { }\n" + "interface NodeHandle extends INodeHandle { }\n" + "class DocumentImpl implements INodeHandle {\n" + " public Object getNodeId() {return null;}\n" + "}\n" + "interface INodeHandle {\n" + " public Object getNodeId();\n" + "}\n" + "public class X {\n" + " public void foo(IStoredNode bar) {\n" + " bar.getNodeId();\n" + " }\n" + "}" }); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=466730 - Java 8: single method with generics is ambiguous when using import static ...* and inheritance public void testBug466730() { runConformTest( new String[] { "bug/Base.java", "package bug;\n" + "public class Base {\n" + " public static Object works() {\n" + " throw new IllegalStateException();\n" + " }\n" + " public static T fails() {\n" + " throw new IllegalStateException();\n" + " }\n" + "}\n", "bug/Derived.java", "package bug;\n" + "public class Derived extends Base {}\n", "bug/StaticImportBug.java", "package bug;\n" + "import static bug.Base.*;\n" + "import static bug.Derived.*;\n" + "public class StaticImportBug {\n" + " void m() {\n" + " java.util.Objects.requireNonNull(works());\n" + " java.util.Objects.requireNonNull(fails());\n" + " }\n" + "}\n" }); } }