Lines 12-17
Link Here
|
12 |
|
12 |
|
13 |
import java.util.Map; |
13 |
import java.util.Map; |
14 |
|
14 |
|
|
|
15 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
15 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
16 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
16 |
|
17 |
|
17 |
import junit.framework.*; |
18 |
import junit.framework.*; |
Lines 19-25
Link Here
|
19 |
public class AmbiguousMethodTest extends AbstractComparableTest { |
20 |
public class AmbiguousMethodTest extends AbstractComparableTest { |
20 |
|
21 |
|
21 |
static { |
22 |
static { |
22 |
// TESTS_NAMES = new String [] { "test087" }; |
23 |
// TESTS_NAMES = new String [] { "test010a" }; |
23 |
} |
24 |
} |
24 |
public AmbiguousMethodTest(String name) { |
25 |
public AmbiguousMethodTest(String name) { |
25 |
super(name); |
26 |
super(name); |
Lines 278-300
Link Here
|
278 |
} |
279 |
} |
279 |
public void test006() { |
280 |
public void test006() { |
280 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
281 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
281 |
this.runNegativeTest( |
282 |
String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? |
282 |
new String[] { |
283 |
"----------\n" + |
283 |
"X.java", |
284 |
"1. ERROR in X.java (at line 3)\n" + |
284 |
"public class X<T> {\n" + |
285 |
" new Y<Object>().foo(\"X\");\n" + |
285 |
" void test() {\n" + |
286 |
" ^^^\n" + |
286 |
" new Y<Object>().foo(\"X\");\n" + |
287 |
"The method foo(Object) is ambiguous for the type Y<Object>\n" + |
287 |
" new Y<Object>().foo2(\"X\");\n" + |
288 |
"----------\n" + |
288 |
" }\n" + |
289 |
"2. ERROR in X.java (at line 4)\n" + |
289 |
" <U1> U1 foo(U1 t) {return null;}\n" + |
290 |
" new Y<Object>().foo2(\"X\");\n" + |
290 |
" <U2> U2 foo2(U2 t) {return null;}\n" + |
291 |
" ^^^^\n" + |
291 |
"}\n" + |
292 |
"The method foo2(Object) is ambiguous for the type Y<Object>\n" + |
292 |
"class Y<T2> extends X<T2> {\n" + |
293 |
"----------\n" + |
293 |
" void foo(T2 t) {}\n" + |
294 |
"3. WARNING in X.java (at line 10)\n" + |
294 |
" <U3> void foo2(T2 t) {}\n" + |
295 |
" void foo(T2 t) {}\n" + |
295 |
"}\n" |
296 |
" ^^^^^^^^^\n" + |
296 |
}, |
297 |
"Name clash: The method foo(T2) of type Y<T2> has the same erasure as foo(U1) of type X<T> but does not override it\n" + |
297 |
"----------\n" + |
298 |
"----------\n" + |
|
|
299 |
"4. WARNING in X.java (at line 11)\n" + |
300 |
" <U3> void foo2(T2 t) {}\n" + |
301 |
" ^^^^^^^^^^\n" + |
302 |
"Name clash: The method foo2(T2) of type Y<T2> has the same erasure as foo2(U2) of type X<T> but does not override it\n" + |
303 |
"----------\n": |
304 |
"----------\n" + |
298 |
"1. ERROR in X.java (at line 3)\n" + |
305 |
"1. ERROR in X.java (at line 3)\n" + |
299 |
" new Y<Object>().foo(\"X\");\n" + |
306 |
" new Y<Object>().foo(\"X\");\n" + |
300 |
" ^^^\n" + |
307 |
" ^^^\n" + |
Lines 314-320
Link Here
|
314 |
" <U3> void foo2(T2 t) {}\n" + |
321 |
" <U3> void foo2(T2 t) {}\n" + |
315 |
" ^^^^^^^^^^\n" + |
322 |
" ^^^^^^^^^^\n" + |
316 |
"Name clash: The method foo2(T2) of type Y<T2> has the same erasure as foo2(U2) of type X<T> but does not override it\n" + |
323 |
"Name clash: The method foo2(T2) of type Y<T2> has the same erasure as foo2(U2) of type X<T> but does not override it\n" + |
317 |
"----------\n" |
324 |
"----------\n"; |
|
|
325 |
this.runNegativeTest( |
326 |
new String[] { |
327 |
"X.java", |
328 |
"public class X<T> {\n" + |
329 |
" void test() {\n" + |
330 |
" new Y<Object>().foo(\"X\");\n" + |
331 |
" new Y<Object>().foo2(\"X\");\n" + |
332 |
" }\n" + |
333 |
" <U1> U1 foo(U1 t) {return null;}\n" + |
334 |
" <U2> U2 foo2(U2 t) {return null;}\n" + |
335 |
"}\n" + |
336 |
"class Y<T2> extends X<T2> {\n" + |
337 |
" void foo(T2 t) {}\n" + |
338 |
" <U3> void foo2(T2 t) {}\n" + |
339 |
"}\n" |
340 |
}, |
341 |
expectedCompilerLog |
318 |
); |
342 |
); |
319 |
/* javac 7 |
343 |
/* javac 7 |
320 |
X.java:3: reference to foo is ambiguous, both method <U1>foo(U1) in X and method |
344 |
X.java:3: reference to foo is ambiguous, both method <U1>foo(U1) in X and method |
Lines 541-546
Link Here
|
541 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 |
565 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 |
542 |
public void test011a() { |
566 |
public void test011a() { |
543 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
567 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
|
|
568 |
String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? |
569 |
"----------\n" + |
570 |
"1. WARNING in Combined.java (at line 2)\n" + |
571 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
572 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
573 |
"Method pickOne(T) has the same erasure pickOne(Comparable<T>) as another method in type Combined<A,B>\n" + |
574 |
"----------\n" + |
575 |
"2. WARNING in Combined.java (at line 3)\n" + |
576 |
" <T> T pickOne(Comparable<T> value) throws ExTwo { return null;}\n" + |
577 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
578 |
"Method pickOne(Comparable<T>) has the same erasure pickOne(Comparable<T>) as another method in type Combined<A,B>\n" + |
579 |
"----------\n": |
580 |
"----------\n" + |
581 |
"1. ERROR in Combined.java (at line 2)\n" + |
582 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
583 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
584 |
"Method pickOne(T) has the same erasure pickOne(Comparable<T>) as another method in type Combined<A,B>\n" + |
585 |
"----------\n" + |
586 |
"2. ERROR in Combined.java (at line 3)\n" + |
587 |
" <T> T pickOne(Comparable<T> value) throws ExTwo { return null;}\n" + |
588 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
589 |
"Method pickOne(Comparable<T>) has the same erasure pickOne(Comparable<T>) as another method in type Combined<A,B>\n" + |
590 |
"----------\n"; |
544 |
this.runNegativeTest( |
591 |
this.runNegativeTest( |
545 |
new String[] { |
592 |
new String[] { |
546 |
"Combined.java", |
593 |
"Combined.java", |
Lines 555-571
Link Here
|
555 |
"class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + |
602 |
"class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + |
556 |
"class ExTwo extends Exception {static final long serialVersionUID = 2;}" |
603 |
"class ExTwo extends Exception {static final long serialVersionUID = 2;}" |
557 |
}, |
604 |
}, |
558 |
"----------\n" + |
605 |
expectedCompilerLog |
559 |
"1. ERROR in Combined.java (at line 2)\n" + |
|
|
560 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
561 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
562 |
"Method pickOne(T) has the same erasure pickOne(Comparable<T>) as another method in type Combined<A,B>\n" + |
563 |
"----------\n" + |
564 |
"2. ERROR in Combined.java (at line 3)\n" + |
565 |
" <T> T pickOne(Comparable<T> value) throws ExTwo { return null;}\n" + |
566 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
567 |
"Method pickOne(Comparable<T>) has the same erasure pickOne(Comparable<T>) as another method in type Combined<A,B>\n" + |
568 |
"----------\n" |
569 |
); |
606 |
); |
570 |
/* javac 7 |
607 |
/* javac 7 |
571 |
X.java:3: name clash: <T#1>pickOne(Comparable<T#1>) and <T#2>pickOne(T#2) have the same erasure |
608 |
X.java:3: name clash: <T#1>pickOne(Comparable<T#1>) and <T#2>pickOne(T#2) have the same erasure |
Lines 580-596
Link Here
|
580 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 |
617 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 |
581 |
public void test011b() { |
618 |
public void test011b() { |
582 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
619 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
583 |
this.runNegativeTest( |
620 |
String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? |
584 |
new String[] { |
621 |
"----------\n" + |
585 |
"Test1.java", |
622 |
"1. WARNING in Test1.java (at line 2)\n" + |
586 |
"public class Test1<AA, BB> {\n" + |
623 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
587 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
624 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
588 |
" <T> T pickOne(Comparable<T> value) throws ExTwo { return null;}\n" + |
625 |
"Method pickOne(T) has the same erasure pickOne(Comparable<T>) as another method in type Test1<AA,BB>\n" + |
589 |
" void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + |
626 |
"----------\n" + |
590 |
"}\n" + |
627 |
"2. WARNING in Test1.java (at line 3)\n" + |
591 |
"class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + |
628 |
" <T> T pickOne(Comparable<T> value) throws ExTwo { return null;}\n" + |
592 |
"class ExTwo extends Exception {static final long serialVersionUID = 2;}" |
629 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
593 |
}, |
630 |
"Method pickOne(Comparable<T>) has the same erasure pickOne(Comparable<T>) as another method in type Test1<AA,BB>\n" + |
|
|
631 |
"----------\n" + |
632 |
"3. WARNING in Test1.java (at line 4)\n" + |
633 |
" void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + |
634 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
635 |
"Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of type Test1<Integer,Integer>\n" + |
636 |
"----------\n" + |
637 |
"4. WARNING in Test1.java (at line 4)\n" + |
638 |
" void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + |
639 |
" ^^^^^^^^^^\n" + |
640 |
"Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n" + |
641 |
"----------\n": |
594 |
"----------\n" + |
642 |
"----------\n" + |
595 |
"1. ERROR in Test1.java (at line 2)\n" + |
643 |
"1. ERROR in Test1.java (at line 2)\n" + |
596 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
644 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
Lines 611-617
Link Here
|
611 |
" void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + |
659 |
" void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + |
612 |
" ^^^^^^^^^^\n" + |
660 |
" ^^^^^^^^^^\n" + |
613 |
"Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n" + |
661 |
"Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n" + |
614 |
"----------\n" |
662 |
"----------\n"; |
|
|
663 |
this.runNegativeTest( |
664 |
new String[] { |
665 |
"Test1.java", |
666 |
"public class Test1<AA, BB> {\n" + |
667 |
" <T extends Comparable<T>> void pickOne(T value) throws ExOne {}\n" + |
668 |
" <T> T pickOne(Comparable<T> value) throws ExTwo { return null;}\n" + |
669 |
" void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + |
670 |
"}\n" + |
671 |
"class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + |
672 |
"class ExTwo extends Exception {static final long serialVersionUID = 2;}" |
673 |
}, |
674 |
expectedCompilerLog |
615 |
); |
675 |
); |
616 |
/* javac 7 |
676 |
/* javac 7 |
617 |
X.java:3: name clash: <T#1>pickOne(Comparable<T#1>) and <T#2>pickOne(T#2) have the same erasure |
677 |
X.java:3: name clash: <T#1>pickOne(Comparable<T#1>) and <T#2>pickOne(T#2) have the same erasure |
Lines 1570-1597
Link Here
|
1570 |
// variant: having both methods in the same class should not change anything |
1630 |
// variant: having both methods in the same class should not change anything |
1571 |
public void test021() { |
1631 |
public void test021() { |
1572 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
1632 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
1573 |
this.runNegativeTest( |
1633 |
String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? |
1574 |
new String[] { |
1634 |
"----------\n" + |
1575 |
"Y.java", |
1635 |
"1. WARNING in Y.java (at line 3)\n" + |
1576 |
"class X<T extends Object> {\n" + |
1636 |
" public class Y<V extends String> extends X<V> {\n" + |
1577 |
"}\n" + |
1637 |
" ^^^^^^\n" + |
1578 |
"public class Y<V extends String> extends X<V> {\n" + |
1638 |
"The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + |
1579 |
" public static <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1639 |
"----------\n" + |
1580 |
" System.out.print(true);\n" + |
1640 |
"2. WARNING in Y.java (at line 4)\n" + |
1581 |
" return new Y<W>();\n" + |
1641 |
" public static <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1582 |
" }\n" + |
1642 |
" ^^^^^^\n" + |
1583 |
" public static <U extends Object> X<U> make(Class<U> clazz) {\n" + |
1643 |
"The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + |
1584 |
" System.out.print(false);\n" + |
1644 |
"----------\n" + |
1585 |
" return new X<U>();\n" + |
1645 |
"3. WARNING in Y.java (at line 4)\n" + |
1586 |
" }\n" + |
1646 |
" public static <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1587 |
" public static void main(String[] args) throws Exception {\n" + |
1647 |
" ^^^^^^^^^^^^^^^^^^^^\n" + |
1588 |
" Y.make(getClazz());\n" + |
1648 |
"Method make(Class<W>) has the same erasure make(Class<T>) as another method in type Y<V>\n" + |
1589 |
" }\n" + |
1649 |
"----------\n" + |
1590 |
" public static Class getClazz() {\n" + |
1650 |
"4. WARNING in Y.java (at line 8)\n" + |
1591 |
" return String.class;\n" + |
1651 |
" public static <U extends Object> X<U> make(Class<U> clazz) {\n" + |
1592 |
" }\n" + |
1652 |
" ^^^^^^^^^^^^^^^^^^^^\n" + |
1593 |
"}" |
1653 |
"Method make(Class<U>) has the same erasure make(Class<T>) as another method in type Y<V>\n" + |
1594 |
}, |
1654 |
"----------\n" + |
|
|
1655 |
"5. WARNING in Y.java (at line 13)\n" + |
1656 |
" Y.make(getClazz());\n" + |
1657 |
" ^^^^^^^^^^^^^^^^^^\n" + |
1658 |
"Type safety: Unchecked invocation make(Class) of the generic method make(Class<W>) of type Y\n" + |
1659 |
"----------\n" + |
1660 |
"6. WARNING in Y.java (at line 13)\n" + |
1661 |
" Y.make(getClazz());\n" + |
1662 |
" ^^^^^^^^^^\n" + |
1663 |
"Type safety: The expression of type Class needs unchecked conversion to conform to Class<String>\n" + |
1664 |
"----------\n" + |
1665 |
"7. WARNING in Y.java (at line 15)\n" + |
1666 |
" public static Class getClazz() {\n" + |
1667 |
" ^^^^^\n" + |
1668 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
1669 |
"----------\n": |
1595 |
"----------\n" + |
1670 |
"----------\n" + |
1596 |
"1. WARNING in Y.java (at line 3)\n" + |
1671 |
"1. WARNING in Y.java (at line 3)\n" + |
1597 |
" public class Y<V extends String> extends X<V> {\n" + |
1672 |
" public class Y<V extends String> extends X<V> {\n" + |
Lines 1627-1633
Link Here
|
1627 |
" public static Class getClazz() {\n" + |
1702 |
" public static Class getClazz() {\n" + |
1628 |
" ^^^^^\n" + |
1703 |
" ^^^^^\n" + |
1629 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
1704 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
1630 |
"----------\n" |
1705 |
"----------\n"; |
|
|
1706 |
this.runNegativeTest( |
1707 |
new String[] { |
1708 |
"Y.java", |
1709 |
"class X<T extends Object> {\n" + |
1710 |
"}\n" + |
1711 |
"public class Y<V extends String> extends X<V> {\n" + |
1712 |
" public static <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1713 |
" System.out.print(true);\n" + |
1714 |
" return new Y<W>();\n" + |
1715 |
" }\n" + |
1716 |
" public static <U extends Object> X<U> make(Class<U> clazz) {\n" + |
1717 |
" System.out.print(false);\n" + |
1718 |
" return new X<U>();\n" + |
1719 |
" }\n" + |
1720 |
" public static void main(String[] args) throws Exception {\n" + |
1721 |
" Y.make(getClazz());\n" + |
1722 |
" }\n" + |
1723 |
" public static Class getClazz() {\n" + |
1724 |
" return String.class;\n" + |
1725 |
" }\n" + |
1726 |
"}" |
1727 |
}, |
1728 |
expectedCompilerLog |
1631 |
); |
1729 |
); |
1632 |
/* javac 7 |
1730 |
/* javac 7 |
1633 |
X.java:8: name clash: <U>make(Class<U>) and <W>make(Class<W>) have the same erasure |
1731 |
X.java:8: name clash: <U>make(Class<U>) and <W>make(Class<W>) have the same erasure |
Lines 1659-1687
Link Here
|
1659 |
// variant: using instances triggers raw methods, which are ambiguous |
1757 |
// variant: using instances triggers raw methods, which are ambiguous |
1660 |
public void test022() { |
1758 |
public void test022() { |
1661 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
1759 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
1662 |
this.runNegativeTest( |
1760 |
String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? |
1663 |
new String[] { |
1761 |
"----------\n" + |
1664 |
"X.java", |
1762 |
"1. WARNING in X.java (at line 3)\n" + |
1665 |
"public class X<T extends Object> {\n" + |
1763 |
" class Y<V extends String> extends X<V> {\n" + |
1666 |
"}\n" + |
1764 |
" ^^^^^^\n" + |
1667 |
"class Y<V extends String> extends X<V> {\n" + |
1765 |
"The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + |
1668 |
" public <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1766 |
"----------\n" + |
1669 |
" return new Y<W>();\n" + |
1767 |
"2. WARNING in X.java (at line 4)\n" + |
1670 |
" }\n" + |
1768 |
" public <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1671 |
" public <U extends Object> X<U> make(Class<U> clazz) {\n" + |
1769 |
" ^^^^^^\n" + |
1672 |
" return new X<U>();\n" + |
1770 |
"The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + |
1673 |
" }\n" + |
1771 |
"----------\n" + |
1674 |
" public static void main(String[] args) throws Exception {\n" + |
1772 |
"3. WARNING in X.java (at line 4)\n" + |
1675 |
" Y y = new Y();\n" + |
1773 |
" public <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1676 |
" y.make(String.class);\n" + |
1774 |
" ^^^^^^^^^^^^^^^^^^^^\n" + |
1677 |
" y.make(getClazz());\n" + |
1775 |
"Method make(Class<W>) has the same erasure make(Class<T>) as another method in type Y<V>\n" + |
1678 |
" y.make(getClazz().newInstance().getClass());\n" + |
1776 |
"----------\n" + |
1679 |
" }\n" + |
1777 |
"4. WARNING in X.java (at line 7)\n" + |
1680 |
" public static Class getClazz() {\n" + |
1778 |
" public <U extends Object> X<U> make(Class<U> clazz) {\n" + |
1681 |
" return String.class;\n" + |
1779 |
" ^^^^^^^^^^^^^^^^^^^^\n" + |
1682 |
" }\n" + |
1780 |
"Method make(Class<U>) has the same erasure make(Class<T>) as another method in type Y<V>\n" + |
1683 |
"}" |
1781 |
"----------\n" + |
1684 |
}, |
1782 |
"5. WARNING in X.java (at line 11)\n" + |
|
|
1783 |
" Y y = new Y();\n" + |
1784 |
" ^\n" + |
1785 |
"Y is a raw type. References to generic type Y<V> should be parameterized\n" + |
1786 |
"----------\n" + |
1787 |
"6. WARNING in X.java (at line 11)\n" + |
1788 |
" Y y = new Y();\n" + |
1789 |
" ^\n" + |
1790 |
"Y is a raw type. References to generic type Y<V> should be parameterized\n" + |
1791 |
"----------\n" + |
1792 |
"7. ERROR in X.java (at line 12)\n" + |
1793 |
" y.make(String.class);\n" + |
1794 |
" ^^^^\n" + |
1795 |
"The method make(Class) is ambiguous for the type Y\n" + |
1796 |
"----------\n" + |
1797 |
"8. ERROR in X.java (at line 13)\n" + |
1798 |
" y.make(getClazz());\n" + |
1799 |
" ^^^^\n" + |
1800 |
"The method make(Class) is ambiguous for the type Y\n" + |
1801 |
"----------\n" + |
1802 |
"9. ERROR in X.java (at line 14)\n" + |
1803 |
" y.make(getClazz().newInstance().getClass());\n" + |
1804 |
" ^^^^\n" + |
1805 |
"The method make(Class) is ambiguous for the type Y\n" + |
1806 |
"----------\n" + |
1807 |
"10. WARNING in X.java (at line 16)\n" + |
1808 |
" public static Class getClazz() {\n" + |
1809 |
" ^^^^^\n" + |
1810 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
1811 |
"----------\n": |
1685 |
"----------\n" + |
1812 |
"----------\n" + |
1686 |
"1. WARNING in X.java (at line 3)\n" + |
1813 |
"1. WARNING in X.java (at line 3)\n" + |
1687 |
" class Y<V extends String> extends X<V> {\n" + |
1814 |
" class Y<V extends String> extends X<V> {\n" + |
Lines 1732-1738
Link Here
|
1732 |
" public static Class getClazz() {\n" + |
1859 |
" public static Class getClazz() {\n" + |
1733 |
" ^^^^^\n" + |
1860 |
" ^^^^^\n" + |
1734 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
1861 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
1735 |
"----------\n" |
1862 |
"----------\n"; |
|
|
1863 |
this.runNegativeTest( |
1864 |
new String[] { |
1865 |
"X.java", |
1866 |
"public class X<T extends Object> {\n" + |
1867 |
"}\n" + |
1868 |
"class Y<V extends String> extends X<V> {\n" + |
1869 |
" public <W extends String> Y<W> make(Class<W> clazz) {\n" + |
1870 |
" return new Y<W>();\n" + |
1871 |
" }\n" + |
1872 |
" public <U extends Object> X<U> make(Class<U> clazz) {\n" + |
1873 |
" return new X<U>();\n" + |
1874 |
" }\n" + |
1875 |
" public static void main(String[] args) throws Exception {\n" + |
1876 |
" Y y = new Y();\n" + |
1877 |
" y.make(String.class);\n" + |
1878 |
" y.make(getClazz());\n" + |
1879 |
" y.make(getClazz().newInstance().getClass());\n" + |
1880 |
" }\n" + |
1881 |
" public static Class getClazz() {\n" + |
1882 |
" return String.class;\n" + |
1883 |
" }\n" + |
1884 |
"}" |
1885 |
}, |
1886 |
expectedCompilerLog |
1736 |
); |
1887 |
); |
1737 |
/* javac 7 |
1888 |
/* javac 7 |
1738 |
X.java:7: name clash: <U>make(Class<U>) and <W>make(Class<W>) have the same erasure |
1889 |
X.java:7: name clash: <U>make(Class<U>) and <W>make(Class<W>) have the same erasure |
Lines 3274-3279
Link Here
|
3274 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=268837 |
3425 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=268837 |
3275 |
// See that this test case exhibits the bug 345947 |
3426 |
// See that this test case exhibits the bug 345947 |
3276 |
public void test076() { |
3427 |
public void test076() { |
|
|
3428 |
String output = (this.complianceLevel == ClassFileConstants.JDK1_6)? |
3429 |
"----------\n" + |
3430 |
"1. WARNING in X.java (at line 8)\n" + |
3431 |
" <U> J<String> b();\n" + |
3432 |
" ^^^\n" + |
3433 |
"Name clash: The method b() of type J<E> has the same erasure as b() of type I<E> but does not override it\n" + |
3434 |
"----------\n" + |
3435 |
"2. ERROR in X.java (at line 15)\n" + |
3436 |
" J<Integer> b = ints.a();\n" + |
3437 |
" ^^^^^^^^\n" + |
3438 |
"Type mismatch: cannot convert from J<String> to J<Integer>\n" + |
3439 |
"----------\n" + |
3440 |
"3. ERROR in X.java (at line 16)\n" + |
3441 |
" J<Object> c = ints.a();\n" + |
3442 |
" ^^^^^^^^\n" + |
3443 |
"Type mismatch: cannot convert from J<String> to J<Object>\n" + |
3444 |
"----------\n" + |
3445 |
"4. WARNING in X.java (at line 17)\n" + |
3446 |
" J d = ints.a();\n" + |
3447 |
" ^\n" + |
3448 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3449 |
"----------\n" + |
3450 |
"5. ERROR in X.java (at line 19)\n" + |
3451 |
" I<Integer> f = ints.a();\n" + |
3452 |
" ^^^^^^^^\n" + |
3453 |
"Type mismatch: cannot convert from J<String> to I<Integer>\n" + |
3454 |
"----------\n" + |
3455 |
"6. ERROR in X.java (at line 20)\n" + |
3456 |
" I<Object> g = ints.a();\n" + |
3457 |
" ^^^^^^^^\n" + |
3458 |
"Type mismatch: cannot convert from J<String> to I<Object>\n" + |
3459 |
"----------\n" + |
3460 |
"7. WARNING in X.java (at line 21)\n" + |
3461 |
" I h = ints.a();\n" + |
3462 |
" ^\n" + |
3463 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3464 |
"----------\n" + |
3465 |
"8. ERROR in X.java (at line 24)\n" + |
3466 |
" ints.b();\n" + |
3467 |
" ^\n" + |
3468 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3469 |
"----------\n" + |
3470 |
"9. ERROR in X.java (at line 25)\n" + |
3471 |
" J<String> a = ints.b();\n" + |
3472 |
" ^\n" + |
3473 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3474 |
"----------\n" + |
3475 |
"10. ERROR in X.java (at line 26)\n" + |
3476 |
" J<Integer> b = ints.b();\n" + |
3477 |
" ^\n" + |
3478 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3479 |
"----------\n" + |
3480 |
"11. ERROR in X.java (at line 27)\n" + |
3481 |
" J<Object> c = ints.b();\n" + |
3482 |
" ^\n" + |
3483 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3484 |
"----------\n" + |
3485 |
"12. WARNING in X.java (at line 28)\n" + |
3486 |
" J d = ints.b();\n" + |
3487 |
" ^\n" + |
3488 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3489 |
"----------\n" + |
3490 |
"13. ERROR in X.java (at line 28)\n" + |
3491 |
" J d = ints.b();\n" + |
3492 |
" ^\n" + |
3493 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3494 |
"----------\n" + |
3495 |
"14. ERROR in X.java (at line 29)\n" + |
3496 |
" I<String> e = ints.b();\n" + |
3497 |
" ^\n" + |
3498 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3499 |
"----------\n" + |
3500 |
"15. ERROR in X.java (at line 30)\n" + |
3501 |
" I<Integer> f = ints.b();\n" + |
3502 |
" ^\n" + |
3503 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3504 |
"----------\n" + |
3505 |
"16. ERROR in X.java (at line 31)\n" + |
3506 |
" I<Object> g = ints.b();\n" + |
3507 |
" ^\n" + |
3508 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3509 |
"----------\n" + |
3510 |
"17. WARNING in X.java (at line 32)\n" + |
3511 |
" I h = ints.b();\n" + |
3512 |
" ^\n" + |
3513 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3514 |
"----------\n" + |
3515 |
"18. ERROR in X.java (at line 32)\n" + |
3516 |
" I h = ints.b();\n" + |
3517 |
" ^\n" + |
3518 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3519 |
"----------\n" + |
3520 |
"19. WARNING in X.java (at line 39)\n" + |
3521 |
" J d = ints.c();\n" + |
3522 |
" ^\n" + |
3523 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3524 |
"----------\n" + |
3525 |
"20. WARNING in X.java (at line 43)\n" + |
3526 |
" I h = ints.c();\n" + |
3527 |
" ^\n" + |
3528 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3529 |
"----------\n": |
3530 |
"----------\n" + |
3531 |
"1. ERROR in X.java (at line 8)\n" + |
3532 |
" <U> J<String> b();\n" + |
3533 |
" ^^^\n" + |
3534 |
"Name clash: The method b() of type J<E> has the same erasure as b() of type I<E> but does not override it\n" + |
3535 |
"----------\n" + |
3536 |
"2. ERROR in X.java (at line 15)\n" + |
3537 |
" J<Integer> b = ints.a();\n" + |
3538 |
" ^^^^^^^^\n" + |
3539 |
"Type mismatch: cannot convert from J<String> to J<Integer>\n" + |
3540 |
"----------\n" + |
3541 |
"3. ERROR in X.java (at line 16)\n" + |
3542 |
" J<Object> c = ints.a();\n" + |
3543 |
" ^^^^^^^^\n" + |
3544 |
"Type mismatch: cannot convert from J<String> to J<Object>\n" + |
3545 |
"----------\n" + |
3546 |
"4. WARNING in X.java (at line 17)\n" + |
3547 |
" J d = ints.a();\n" + |
3548 |
" ^\n" + |
3549 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3550 |
"----------\n" + |
3551 |
"5. ERROR in X.java (at line 19)\n" + |
3552 |
" I<Integer> f = ints.a();\n" + |
3553 |
" ^^^^^^^^\n" + |
3554 |
"Type mismatch: cannot convert from J<String> to I<Integer>\n" + |
3555 |
"----------\n" + |
3556 |
"6. ERROR in X.java (at line 20)\n" + |
3557 |
" I<Object> g = ints.a();\n" + |
3558 |
" ^^^^^^^^\n" + |
3559 |
"Type mismatch: cannot convert from J<String> to I<Object>\n" + |
3560 |
"----------\n" + |
3561 |
"7. WARNING in X.java (at line 21)\n" + |
3562 |
" I h = ints.a();\n" + |
3563 |
" ^\n" + |
3564 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3565 |
"----------\n" + |
3566 |
"8. ERROR in X.java (at line 24)\n" + |
3567 |
" ints.b();\n" + |
3568 |
" ^\n" + |
3569 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3570 |
"----------\n" + |
3571 |
"9. ERROR in X.java (at line 25)\n" + |
3572 |
" J<String> a = ints.b();\n" + |
3573 |
" ^\n" + |
3574 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3575 |
"----------\n" + |
3576 |
"10. ERROR in X.java (at line 26)\n" + |
3577 |
" J<Integer> b = ints.b();\n" + |
3578 |
" ^\n" + |
3579 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3580 |
"----------\n" + |
3581 |
"11. ERROR in X.java (at line 27)\n" + |
3582 |
" J<Object> c = ints.b();\n" + |
3583 |
" ^\n" + |
3584 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3585 |
"----------\n" + |
3586 |
"12. WARNING in X.java (at line 28)\n" + |
3587 |
" J d = ints.b();\n" + |
3588 |
" ^\n" + |
3589 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3590 |
"----------\n" + |
3591 |
"13. ERROR in X.java (at line 28)\n" + |
3592 |
" J d = ints.b();\n" + |
3593 |
" ^\n" + |
3594 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3595 |
"----------\n" + |
3596 |
"14. ERROR in X.java (at line 29)\n" + |
3597 |
" I<String> e = ints.b();\n" + |
3598 |
" ^\n" + |
3599 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3600 |
"----------\n" + |
3601 |
"15. ERROR in X.java (at line 30)\n" + |
3602 |
" I<Integer> f = ints.b();\n" + |
3603 |
" ^\n" + |
3604 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3605 |
"----------\n" + |
3606 |
"16. ERROR in X.java (at line 31)\n" + |
3607 |
" I<Object> g = ints.b();\n" + |
3608 |
" ^\n" + |
3609 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3610 |
"----------\n" + |
3611 |
"17. WARNING in X.java (at line 32)\n" + |
3612 |
" I h = ints.b();\n" + |
3613 |
" ^\n" + |
3614 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3615 |
"----------\n" + |
3616 |
"18. ERROR in X.java (at line 32)\n" + |
3617 |
" I h = ints.b();\n" + |
3618 |
" ^\n" + |
3619 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3620 |
"----------\n" + |
3621 |
"19. WARNING in X.java (at line 39)\n" + |
3622 |
" J d = ints.c();\n" + |
3623 |
" ^\n" + |
3624 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3625 |
"----------\n" + |
3626 |
"20. WARNING in X.java (at line 43)\n" + |
3627 |
" I h = ints.c();\n" + |
3628 |
" ^\n" + |
3629 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3630 |
"----------\n"; |
3277 |
this.runNegativeTest( |
3631 |
this.runNegativeTest( |
3278 |
new String[] { |
3632 |
new String[] { |
3279 |
"X.java", |
3633 |
"X.java", |
Lines 3323-3429
Link Here
|
3323 |
" }\n" + |
3677 |
" }\n" + |
3324 |
"}" |
3678 |
"}" |
3325 |
}, |
3679 |
}, |
3326 |
"----------\n" + |
3680 |
output |
3327 |
"1. ERROR in X.java (at line 8)\n" + |
|
|
3328 |
" <U> J<String> b();\n" + |
3329 |
" ^^^\n" + |
3330 |
"Name clash: The method b() of type J<E> has the same erasure as b() of type I<E> but does not override it\n" + |
3331 |
"----------\n" + |
3332 |
"2. ERROR in X.java (at line 15)\n" + |
3333 |
" J<Integer> b = ints.a();\n" + |
3334 |
" ^^^^^^^^\n" + |
3335 |
"Type mismatch: cannot convert from J<String> to J<Integer>\n" + |
3336 |
"----------\n" + |
3337 |
"3. ERROR in X.java (at line 16)\n" + |
3338 |
" J<Object> c = ints.a();\n" + |
3339 |
" ^^^^^^^^\n" + |
3340 |
"Type mismatch: cannot convert from J<String> to J<Object>\n" + |
3341 |
"----------\n" + |
3342 |
"4. WARNING in X.java (at line 17)\n" + |
3343 |
" J d = ints.a();\n" + |
3344 |
" ^\n" + |
3345 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3346 |
"----------\n" + |
3347 |
"5. ERROR in X.java (at line 19)\n" + |
3348 |
" I<Integer> f = ints.a();\n" + |
3349 |
" ^^^^^^^^\n" + |
3350 |
"Type mismatch: cannot convert from J<String> to I<Integer>\n" + |
3351 |
"----------\n" + |
3352 |
"6. ERROR in X.java (at line 20)\n" + |
3353 |
" I<Object> g = ints.a();\n" + |
3354 |
" ^^^^^^^^\n" + |
3355 |
"Type mismatch: cannot convert from J<String> to I<Object>\n" + |
3356 |
"----------\n" + |
3357 |
"7. WARNING in X.java (at line 21)\n" + |
3358 |
" I h = ints.a();\n" + |
3359 |
" ^\n" + |
3360 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3361 |
"----------\n" + |
3362 |
"8. ERROR in X.java (at line 24)\n" + |
3363 |
" ints.b();\n" + |
3364 |
" ^\n" + |
3365 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3366 |
"----------\n" + |
3367 |
"9. ERROR in X.java (at line 25)\n" + |
3368 |
" J<String> a = ints.b();\n" + |
3369 |
" ^\n" + |
3370 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3371 |
"----------\n" + |
3372 |
"10. ERROR in X.java (at line 26)\n" + |
3373 |
" J<Integer> b = ints.b();\n" + |
3374 |
" ^\n" + |
3375 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3376 |
"----------\n" + |
3377 |
"11. ERROR in X.java (at line 27)\n" + |
3378 |
" J<Object> c = ints.b();\n" + |
3379 |
" ^\n" + |
3380 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3381 |
"----------\n" + |
3382 |
"12. WARNING in X.java (at line 28)\n" + |
3383 |
" J d = ints.b();\n" + |
3384 |
" ^\n" + |
3385 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3386 |
"----------\n" + |
3387 |
"13. ERROR in X.java (at line 28)\n" + |
3388 |
" J d = ints.b();\n" + |
3389 |
" ^\n" + |
3390 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3391 |
"----------\n" + |
3392 |
"14. ERROR in X.java (at line 29)\n" + |
3393 |
" I<String> e = ints.b();\n" + |
3394 |
" ^\n" + |
3395 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3396 |
"----------\n" + |
3397 |
"15. ERROR in X.java (at line 30)\n" + |
3398 |
" I<Integer> f = ints.b();\n" + |
3399 |
" ^\n" + |
3400 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3401 |
"----------\n" + |
3402 |
"16. ERROR in X.java (at line 31)\n" + |
3403 |
" I<Object> g = ints.b();\n" + |
3404 |
" ^\n" + |
3405 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3406 |
"----------\n" + |
3407 |
"17. WARNING in X.java (at line 32)\n" + |
3408 |
" I h = ints.b();\n" + |
3409 |
" ^\n" + |
3410 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3411 |
"----------\n" + |
3412 |
"18. ERROR in X.java (at line 32)\n" + |
3413 |
" I h = ints.b();\n" + |
3414 |
" ^\n" + |
3415 |
"The method b() is ambiguous for the type J<Integer>\n" + |
3416 |
"----------\n" + |
3417 |
"19. WARNING in X.java (at line 39)\n" + |
3418 |
" J d = ints.c();\n" + |
3419 |
" ^\n" + |
3420 |
"J is a raw type. References to generic type J<E> should be parameterized\n" + |
3421 |
"----------\n" + |
3422 |
"20. WARNING in X.java (at line 43)\n" + |
3423 |
" I h = ints.c();\n" + |
3424 |
" ^\n" + |
3425 |
"I is a raw type. References to generic type I<E> should be parameterized\n" + |
3426 |
"----------\n" |
3427 |
); |
3681 |
); |
3428 |
} |
3682 |
} |
3429 |
|
3683 |
|