View | Details | Raw Unified | Return to bug 93377 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+410 lines)
Lines 1562-1567 Link Here
1562
		        "incorrect classpath: dummy\n",
1563
		        "incorrect classpath: dummy\n",
1563
		        false);
1564
		        false);
1564
		}
1565
		}
1566
//Extraneous auto-build error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=93377
1567
public void test030(){
1568
	// first series shows that a clean build is OK
1569
	this.runConformTest(
1570
		new String[] {
1571
			"X.java",
1572
			"public interface X<T extends X<T, K, S>, \n" + 
1573
			"                   K extends X.K<T, S>, \n" + 
1574
			"                   S extends X.S> {\n" + 
1575
			"	public interface K<KT extends X<KT, ?, KS>, \n" + 
1576
			"	                   KS extends X.S> {\n" + 
1577
			"	}\n" + 
1578
			"	public interface S {\n" + 
1579
			"	}\n" + 
1580
			"}\n",
1581
			"Y.java",
1582
			"public class Y<T extends X<T, K, S>, \n" + 
1583
			"               K extends X.K<T, S>, \n" + 
1584
			"               S extends X.S> { \n" + 
1585
			"}\n",
1586
		},
1587
        "\"" + OUTPUT_DIR +  File.separator + "Y.java\""
1588
        + " -1.5 -g -preserveAllLocals"
1589
        + " -cp \"" + OUTPUT_DIR + File.separator + "\""
1590
        + " -proceedOnError -referenceInfo"
1591
        + " -d \"" + OUTPUT_DIR + "\"",
1592
        "",
1593
        "",
1594
        true);
1595
	// second series shows that a staged build - that simulates the auto build context - is OK as well
1596
	this.runConformTest(
1597
		new String[] {
1598
			"X.java",
1599
			"public interface X<T extends X<T, K, S>, \n" + 
1600
			"                   K extends X.K<T, S>, \n" + 
1601
			"                   S extends X.S> {\n" + 
1602
			"	public interface K<KT extends X<KT, ?, KS>, \n" + 
1603
			"	                   KS extends X.S> {\n" + 
1604
			"	}\n" + 
1605
			"	public interface S {\n" + 
1606
			"	}\n" + 
1607
			"}\n",
1608
		},
1609
        "\"" + OUTPUT_DIR +  File.separator + "X.java\""
1610
        + " -1.5 -g -preserveAllLocals"
1611
        + " -proceedOnError -referenceInfo" 
1612
        + " -d \"" + OUTPUT_DIR + "\"",
1613
        "",
1614
        "",
1615
        true);
1616
	this.runConformTest(
1617
		new String[] {
1618
			"Y.java",
1619
			"public class Y<T extends X<T, K, S>, \n" + 
1620
			"               K extends X.K<T, S>, \n" + 
1621
			"               S extends X.S> { \n" + 
1622
			"}\n",
1623
		},
1624
        "\"" + OUTPUT_DIR +  File.separator + "Y.java\""
1625
        + " -1.5 -g -preserveAllLocals"
1626
        + " -cp \"" + OUTPUT_DIR + File.separator + "\""
1627
        + " -proceedOnError -referenceInfo"
1628
        + " -d \"" + OUTPUT_DIR + "\"",
1629
        "",
1630
        "",
1631
        false);
1632
}
1633
// Extraneous auto-build error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=93377
1634
// More complex test case than test30
1635
public void test032(){
1636
	// first series shows that a clean build is OK (warning messages only)
1637
	this.runConformTest(
1638
			new String[] {
1639
				"p/X.java",
1640
				"package p;\n" + 
1641
				"import java.io.Serializable;\n" + 
1642
				"public interface X<T extends X<T, U, V>, \n" + 
1643
				"				   U extends X.XX<T, V>, \n" + 
1644
				"				   V extends X.XY> {\n" + 
1645
				"	public interface XX<TT extends X<TT, ?, UU>, \n" + 
1646
				"	                    UU extends X.XY> \n" + 
1647
				"			extends	Serializable {\n" + 
1648
				"	}\n" + 
1649
				"	public interface XY extends Serializable {\n" + 
1650
				"	}\n" + 
1651
				"}\n",
1652
				"p/Y.java",
1653
				"package p;\n" + 
1654
				"import java.util.*;\n" + 
1655
				"import p.X.*;\n" + 
1656
				"public class Y<T extends X<T, U, V>, \n" + 
1657
				"               U extends X.XX<T, V>, \n" + 
1658
				"               V extends X.XY> {\n" + 
1659
				"	private final Map<U, V> m1 = new HashMap<U, V>();\n" + 
1660
				"	private final Map<U, T> m2 = new HashMap<U, T>();\n" + 
1661
				"	private final Z m3;\n" + 
1662
				"\n" + 
1663
				"	public Y(final Z p1) {\n" + 
1664
				"		this.m3 = p1;\n" + 
1665
				"	}\n" + 
1666
				"\n" + 
1667
				"	public void foo1(final U p1, final V p2, final T p3) {\n" + 
1668
				"		m1.put(p1, p2);\n" + 
1669
				"		m2.put(p1, p3);\n" + 
1670
				"		m3.foo2(p1, p2);\n" + 
1671
				"	}\n" + 
1672
				"\n" + 
1673
				"	public void foo3(final U p1) {\n" + 
1674
				"		assert m1.containsKey(p1);\n" + 
1675
				"		m1.remove(p1);\n" + 
1676
				"		m2.remove(p1);\n" + 
1677
				"		m3.foo2(p1, null);\n" + 
1678
				"	}\n" + 
1679
				"\n" + 
1680
				"	public Collection<T> foo4() {\n" + 
1681
				"		return Collections.unmodifiableCollection(m2.values());\n" + 
1682
				"	}\n" + 
1683
				"\n" + 
1684
				"	public void foo5(final Map<XX<?, ?>, XY> p1) {\n" + 
1685
				"		p1.putAll(m1);\n" + 
1686
				"	}\n" + 
1687
				"\n" + 
1688
				"	public void foo6(final Map<XX<?, ?>, XY> p1) {\n" + 
1689
				"		m1.keySet().retainAll(p1.keySet());\n" + 
1690
				"		m2.keySet().retainAll(p1.keySet());\n" + 
1691
				"	}\n" + 
1692
				"}\n",
1693
				"p/Z.java",
1694
				"package p;\n" + 
1695
				"\n" + 
1696
				"import java.util.*;\n" + 
1697
				"\n" + 
1698
				"import p.X.*;\n" + 
1699
				"\n" + 
1700
				"public class Z {\n" + 
1701
				"	private final Map<Class<? extends X>, \n" + 
1702
				"		              Y<?, ? extends XX<?, ?>, ? extends XY>> \n" + 
1703
				"		m1 = new HashMap<Class<? extends X>, \n" + 
1704
				"		                 Y<?, ? extends XX<?, ?>, ? extends XY>>();\n" + 
1705
				"\n" + 
1706
				"	private Map<X.XX<?, XY>, \n" + 
1707
				"	            X.XY> \n" + 
1708
				"		m2 = new HashMap<X.XX<?, XY>, \n" + 
1709
				"		                 X.XY>();\n" + 
1710
				"\n" + 
1711
				"	public <T extends X<T, U, V>, \n" + 
1712
				"	        U extends X.XX<T, V>, \n" + 
1713
				"	        V extends X.XY> \n" + 
1714
				"	Y<T, U, V> foo1(final Class<T> p1) {\n" + 
1715
				"		Y l1 = m1.get(p1);\n" + 
1716
				"		if (l1 == null) {\n" + 
1717
				"			l1 = new Y<T, U, V>(this);\n" + 
1718
				"			m1.put(p1, l1);\n" + 
1719
				"		}\n" + 
1720
				"		return l1;\n" + 
1721
				"	}\n" + 
1722
				"\n" + 
1723
				"	public <TT extends X.XX<?, UU>, \n" + 
1724
				"	        UU extends X.XY> \n" + 
1725
				"	void foo2(final TT p1, final UU p2) {\n" + 
1726
				"		m2.put((XX<?, XY>) p1, p2);\n" + 
1727
				"	}\n" + 
1728
				"\n" + 
1729
				"	public Map<XX<?, ?>, XY> foo3() {\n" + 
1730
				"		final Map<XX<?, ?>, \n" + 
1731
				"		          XY> l1 = new HashMap<XX<?, ?>, \n" + 
1732
				"		                               XY>();\n" + 
1733
				"		for (final Y<?, \n" + 
1734
				"				     ? extends XX<?, ?>, \n" + 
1735
				"				     ? extends XY> \n" + 
1736
				"				i : m1.values()) {\n" + 
1737
				"			i.foo5(l1);\n" + 
1738
				"		}\n" + 
1739
				"		return l1;\n" + 
1740
				"	}\n" + 
1741
				"\n" + 
1742
				"	public void foo4(final Object p1, final Map<XX<?, ?>, \n" + 
1743
				"			                                    XY> p2) {\n" + 
1744
				"		for (final Y<?, \n" + 
1745
				"				     ? extends XX<?, ?>, \n" + 
1746
				"				     ? extends XY> i : m1.values()) {\n" + 
1747
				"			i.foo6(p2);\n" + 
1748
				"		}\n" + 
1749
				"		for (final Map.Entry<XX<?, ?>, \n" + 
1750
				"				             XY> i : p2.entrySet()) {\n" + 
1751
				"			final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" + 
1752
				"		}\n" + 
1753
				"	}\n" + 
1754
				"}\n"
1755
			},
1756
	        "\"" + OUTPUT_DIR +  File.separator + "p/X.java\""
1757
	        + " \"" + OUTPUT_DIR +  File.separator + "p/Y.java\""
1758
	        + " \"" + OUTPUT_DIR +  File.separator + "p/Z.java\""
1759
	        + " -1.5 -g -preserveAllLocals"
1760
	        + " -cp \"" + OUTPUT_DIR + File.separator + "\""
1761
	        + " -proceedOnError -referenceInfo"
1762
	        + " -d \"" + OUTPUT_DIR + "\"",
1763
	        "",
1764
	        "----------\n" + 
1765
	        "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1766
	        " (at line 25)\n" + 
1767
	        "	m1.put(p1, l1);\n" + 
1768
	        "	           ^^\n" + 
1769
	        "Type safety: The expression of type Y needs unchecked conversion to conform to Y<?,? extends X.XX<?,?>,? extends X.XY>\n" + 
1770
	        "----------\n" + 
1771
	        "----------\n" + 
1772
	        "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1773
	        " (at line 27)\n" + 
1774
	        "	return l1;\n" + 
1775
	        "	       ^^\n" + 
1776
	        "Type safety: The expression of type Y needs unchecked conversion to conform to Y<T,U,V>\n" + 
1777
	        "----------\n" + 
1778
	        "----------\n" + 
1779
	        "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1780
	        " (at line 33)\n" + 
1781
	        "	m2.put((XX<?, XY>) p1, p2);\n" + 
1782
	        "	       ^^^^^^^^^^^^^^\n" + 
1783
	        "Type safety: The cast from TT to X.XX<?,X.XY> is actually checking against the erased type X<T,U,V>.XX\n" + 
1784
	        "----------\n" + 
1785
	        "----------\n" + 
1786
	        "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1787
	        " (at line 58)\n" + 
1788
	        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" + 
1789
	        "	                ^^\n" + 
1790
	        "The local variable l1 is never read\n" + 
1791
	        "----------\n" + 
1792
	        "----------\n" + 
1793
	        "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1794
	        " (at line 58)\n" + 
1795
	        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" + 
1796
	        "	                     ^^^^^^^^^^^^^^^^^^^^^^\n" + 
1797
	        "Type safety: The cast from X.XX<capture-of ?,capture-of ?> to X.XX<?,X.XY> is actually checking against the erased type X<T,U,V>.XX\n" + 
1798
	        "----------\n" + 
1799
	        "5 problems (5 warnings)",
1800
	        true);
1801
	// second series shows that a staged build - that simulates the auto build context - is OK as well
1802
	this.runConformTest(
1803
		new String[] {
1804
			"p/X.java",
1805
			"package p;\n" + 
1806
			"import java.io.Serializable;\n" + 
1807
			"public interface X<T extends X<T, U, V>, \n" + 
1808
			"				   U extends X.XX<T, V>, \n" + 
1809
			"				   V extends X.XY> {\n" + 
1810
			"	public interface XX<TT extends X<TT, ?, UU>, \n" + 
1811
			"	                    UU extends X.XY> \n" + 
1812
			"			extends	Serializable {\n" + 
1813
			"	}\n" + 
1814
			"	public interface XY extends Serializable {\n" + 
1815
			"	}\n" + 
1816
			"}\n",
1817
		},
1818
        "\"" + OUTPUT_DIR +  File.separator + "p/X.java\""
1819
        + " -1.5 -g -preserveAllLocals"
1820
        + " -proceedOnError -referenceInfo" 
1821
        + " -d \"" + OUTPUT_DIR + "\"",
1822
        "",
1823
        "",
1824
        true);
1825
	this.runConformTest(
1826
		new String[] {
1827
			"p/Y.java",
1828
			"package p;\n" + 
1829
			"import java.util.*;\n" + 
1830
			"import p.X.*;\n" + 
1831
			"public class Y<T extends X<T, U, V>, \n" + 
1832
			"               U extends X.XX<T, V>, \n" + 
1833
			"               V extends X.XY> {\n" + 
1834
			"	private final Map<U, V> m1 = new HashMap<U, V>();\n" + 
1835
			"	private final Map<U, T> m2 = new HashMap<U, T>();\n" + 
1836
			"	private final Z m3;\n" + 
1837
			"\n" + 
1838
			"	public Y(final Z p1) {\n" + 
1839
			"		this.m3 = p1;\n" + 
1840
			"	}\n" + 
1841
			"\n" + 
1842
			"	public void foo1(final U p1, final V p2, final T p3) {\n" + 
1843
			"		m1.put(p1, p2);\n" + 
1844
			"		m2.put(p1, p3);\n" + 
1845
			"		m3.foo2(p1, p2);\n" + 
1846
			"	}\n" + 
1847
			"\n" + 
1848
			"	public void foo3(final U p1) {\n" + 
1849
			"		assert m1.containsKey(p1);\n" + 
1850
			"		m1.remove(p1);\n" + 
1851
			"		m2.remove(p1);\n" + 
1852
			"		m3.foo2(p1, null);\n" + 
1853
			"	}\n" + 
1854
			"\n" + 
1855
			"	public Collection<T> foo4() {\n" + 
1856
			"		return Collections.unmodifiableCollection(m2.values());\n" + 
1857
			"	}\n" + 
1858
			"\n" + 
1859
			"	public void foo5(final Map<XX<?, ?>, XY> p1) {\n" + 
1860
			"		p1.putAll(m1);\n" + 
1861
			"	}\n" + 
1862
			"\n" + 
1863
			"	public void foo6(final Map<XX<?, ?>, XY> p1) {\n" + 
1864
			"		m1.keySet().retainAll(p1.keySet());\n" + 
1865
			"		m2.keySet().retainAll(p1.keySet());\n" + 
1866
			"	}\n" + 
1867
			"}\n",
1868
			"p/Z.java",
1869
			"package p;\n" + 
1870
			"\n" + 
1871
			"import java.util.*;\n" + 
1872
			"\n" + 
1873
			"import p.X.*;\n" + 
1874
			"\n" + 
1875
			"public class Z {\n" + 
1876
			"	private final Map<Class<? extends X>, \n" + 
1877
			"		              Y<?, ? extends XX<?, ?>, ? extends XY>> \n" + 
1878
			"		m1 = new HashMap<Class<? extends X>, \n" + 
1879
			"		                 Y<?, ? extends XX<?, ?>, ? extends XY>>();\n" + 
1880
			"\n" + 
1881
			"	private Map<X.XX<?, XY>, \n" + 
1882
			"	            X.XY> \n" + 
1883
			"		m2 = new HashMap<X.XX<?, XY>, \n" + 
1884
			"		                 X.XY>();\n" + 
1885
			"\n" + 
1886
			"	public <T extends X<T, U, V>, \n" + 
1887
			"	        U extends X.XX<T, V>, \n" + 
1888
			"	        V extends X.XY> \n" + 
1889
			"	Y<T, U, V> foo1(final Class<T> p1) {\n" + 
1890
			"		Y l1 = m1.get(p1);\n" + 
1891
			"		if (l1 == null) {\n" + 
1892
			"			l1 = new Y<T, U, V>(this);\n" + 
1893
			"			m1.put(p1, l1);\n" + 
1894
			"		}\n" + 
1895
			"		return l1;\n" + 
1896
			"	}\n" + 
1897
			"\n" + 
1898
			"	public <TT extends X.XX<?, UU>, \n" + 
1899
			"	        UU extends X.XY> \n" + 
1900
			"	void foo2(final TT p1, final UU p2) {\n" + 
1901
			"		m2.put((XX<?, XY>) p1, p2);\n" + 
1902
			"	}\n" + 
1903
			"\n" + 
1904
			"	public Map<XX<?, ?>, XY> foo3() {\n" + 
1905
			"		final Map<XX<?, ?>, \n" + 
1906
			"		          XY> l1 = new HashMap<XX<?, ?>, \n" + 
1907
			"		                               XY>();\n" + 
1908
			"		for (final Y<?, \n" + 
1909
			"				     ? extends XX<?, ?>, \n" + 
1910
			"				     ? extends XY> \n" + 
1911
			"				i : m1.values()) {\n" + 
1912
			"			i.foo5(l1);\n" + 
1913
			"		}\n" + 
1914
			"		return l1;\n" + 
1915
			"	}\n" + 
1916
			"\n" + 
1917
			"	public void foo4(final Object p1, final Map<XX<?, ?>, \n" + 
1918
			"			                                    XY> p2) {\n" + 
1919
			"		for (final Y<?, \n" + 
1920
			"				     ? extends XX<?, ?>, \n" + 
1921
			"				     ? extends XY> i : m1.values()) {\n" + 
1922
			"			i.foo6(p2);\n" + 
1923
			"		}\n" + 
1924
			"		for (final Map.Entry<XX<?, ?>, \n" + 
1925
			"				             XY> i : p2.entrySet()) {\n" + 
1926
			"			final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" + 
1927
			"		}\n" + 
1928
			"	}\n" + 
1929
			"}\n"
1930
		},
1931
        "\"" + OUTPUT_DIR +  File.separator + "p/Y.java\""
1932
        + " \"" + OUTPUT_DIR +  File.separator + "p/Z.java\""
1933
        + " -1.5 -g -preserveAllLocals"
1934
        + " -cp \"" + OUTPUT_DIR + File.separator + "\""
1935
        + " -proceedOnError -referenceInfo"
1936
        + " -d \"" + OUTPUT_DIR + "\"",
1937
        "",
1938
        "----------\n" + 
1939
        "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1940
        " (at line 25)\n" + 
1941
        "	m1.put(p1, l1);\n" + 
1942
        "	           ^^\n" + 
1943
        "Type safety: The expression of type Y needs unchecked conversion to conform to Y<?,? extends X.XX<?,?>,? extends X.XY>\n" + 
1944
        "----------\n" + 
1945
        "----------\n" + 
1946
        "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1947
        " (at line 27)\n" + 
1948
        "	return l1;\n" + 
1949
        "	       ^^\n" + 
1950
        "Type safety: The expression of type Y needs unchecked conversion to conform to Y<T,U,V>\n" + 
1951
        "----------\n" + 
1952
        "----------\n" + 
1953
        "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1954
        " (at line 33)\n" + 
1955
        "	m2.put((XX<?, XY>) p1, p2);\n" + 
1956
        "	       ^^^^^^^^^^^^^^\n" + 
1957
        "Type safety: The cast from TT to X.XX<?,X.XY> is actually checking against the erased type X<T,U,V>.XX\n" + 
1958
        "----------\n" + 
1959
        "----------\n" + 
1960
        "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1961
        " (at line 58)\n" + 
1962
        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" + 
1963
        "	                ^^\n" + 
1964
        "The local variable l1 is never read\n" + 
1965
        "----------\n" + 
1966
        "----------\n" + 
1967
        "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---\\p\\Z.java\n" + 
1968
        " (at line 58)\n" + 
1969
        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" + 
1970
        "	                     ^^^^^^^^^^^^^^^^^^^^^^\n" + 
1971
        "Type safety: The cast from X.XX<capture-of ?,capture-of ?> to X.XX<?,X.XY> is actually checking against the erased type X<T,U,V>.XX\n" + 
1972
        "----------\n" + 
1973
        "5 problems (5 warnings)",
1974
        false);
1975
}
1565
public static Class testClass() {
1976
public static Class testClass() {
1566
	return BatchCompilerTest.class;
1977
	return BatchCompilerTest.class;
1567
}
1978
}

Return to bug 93377