/*******************************************************************************
* Copyright (c) 2000, 2007 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
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import junit.framework.Test;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public class GenericTypeTest extends AbstractComparableTest {
public GenericTypeTest(String name) {
super(name);
}
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which does not belong to the class are skipped...
static {
// TESTS_NAMES = new String[] { "test0788" };
// TESTS_NUMBERS = new int[] { 1054 };
// TESTS_RANGE = new int[] { 1097, -1 };
}
public static Test suite() {
return buildComparableTestSuite(testClass());
}
public static Class testClass() {
return GenericTypeTest.class;
}
public void test0001() {
this.runConformTest(
new String[] {
"X.java",
"public class X<Tx1 extends String, Tx2 extends Comparable> extends XS {\n" +
"\n" +
" public static void main(String[] args) {\n" +
" Integer w = new X<String,Integer>().get(new Integer(12));\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"class XS <Txs> {\n" +
" Txs get(Txs t) {\n" +
" return t;\n" +
" }\n" +
"}\n"
},
"SUCCESS");
}
public void test0002() {
this.runConformTest(
new String[] {
"X.java",
"public class X<Xp1 extends String, Xp2 extends Comparable> extends XS {\n" +
"\n" +
" public static void main(String[] args) {\n" +
" Integer w = new X<String,Integer>().get(new Integer(12));\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" Xp2 get(Xp2 t){\n" +
" System.out.print(\"{X::get}\");\n" +
" return super.get(t);\n" +
" }\n" +
"}\n" +
"\n" +
"class XS <XSp1> {\n" +
" XSp1 get(XSp1 t) {\n" +
" System.out.print(\"{XS::get}\");\n" +
" return t;\n" +
" }\n" +
"}\n"
},
"{X::get}{XS::get}SUCCESS");
}
// check cannot bind superclass to type variable
public void test0003() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <X> extends X {\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <X> extends X {\n" +
" ^\n" +
"The type parameter X is hiding the type X<X>\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <X> extends X {\n" +
" ^\n" +
"Cannot refer to the type parameter X as a supertype\n" +
"----------\n");
}
// check cannot bind superinterface to type variable
public void test0004() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <X> implements X {\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <X> implements X {\n" +
" ^\n" +
"The type parameter X is hiding the type X<X>\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <X> implements X {\n" +
" ^\n" +
"Cannot refer to the type parameter X as a supertype\n" +
"----------\n");
}
// check cannot bind type variable in static context
public void test0005() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" \n" +
" T t;\n" +
" static {\n" +
" T s;\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" T s;\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n");
}
// check static references to type variables
public void test0006() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" \n" +
" T ok1;\n" +
" static {\n" +
" T wrong1;\n" +
" }\n" +
" static void foo(T wrong2) {\n" +
" T wrong3;\n" +
" }\n" +
" class MX extends T {\n" +
" T ok2;\n" +
" }\n" +
" static class SMX extends T {\n" +
" T wrong4;\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" T wrong1;\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" static void foo(T wrong2) {\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n" +
"3. ERROR in X.java (at line 8)\n" +
" T wrong3;\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n" +
"4. ERROR in X.java (at line 10)\n" +
" class MX extends T {\n" +
" ^\n" +
"Cannot refer to the type parameter T as a supertype\n" +
"----------\n" +
"5. ERROR in X.java (at line 13)\n" +
" static class SMX extends T {\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n" +
"6. ERROR in X.java (at line 14)\n" +
" T wrong4;\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n");
}
// check static references to type variables
public void test0007() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" \n" +
" T ok1;\n" +
" static class SMX {\n" +
" T wrong4;\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" T wrong4;\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n");
}
// check static references to type variables
public void test0008() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" \n" +
" T ok;\n" +
" static T wrong;\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" static T wrong;\n" +
" ^\n" +
"Cannot make a static reference to the non-static type T\n" +
"----------\n");
}
// Object cannot be generic
public void test0009() {
this.runNegativeTest(
new String[] {
"Object.java",
"package java.lang;\n" +
"public class Object <T> {\n" +
"}\n",
},
"----------\n" +
"1. ERROR in Object.java (at line 2)\n" +
" public class Object <T> {\n" +
" ^\n" +
"The type java.lang.Object cannot be declared as a generic\n" +
"----------\n");
}
public void test0010() {
this.runNegativeTest(
new String[] {
"X.java",
"class Foo {} \n" +
"public class X<T extends Object & Comparable {\n" +
" public static void main(String[] args) {\n" +
" new X<Foo>();\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" new X<Foo>();\n" +
" ^^^\n" +
"Bound mismatch: The type Foo is not a valid substitute for the bounded parameter <T extends Object & Comparable of the type X\n" +
"----------\n");
}
public void test0011() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T extends Object & Comparable {\n" +
" public static void main(String[] args) {\n" +
" new X<Foo>();\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 3)\n" +
" new X<Foo>();\n" +
" ^^^\n" +
"Foo cannot be resolved to a type\n" +
"----------\n");
}
public void test0012() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends String> {\n" +
" T foo(T t) {\n" +
" return t;\n" +
" }\n" +
" \n" +
" public static void main(String[] args) {\n" +
" String s = new X<String>().foo(\"SUCCESS\");\n" +
" System.out.println(s);\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0013() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends String> {\n" +
" T foo(T t) {\n" +
" return t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>().baz(\"SUCCESS\");\n" +
" }\n" +
" void baz(final T t) {\n" +
" new Object() {\n" +
" void print() {\n" +
" System.out.println(foo(t));\n" +
" }\n" +
" }.print();\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0014() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends Exception> {\n" +
" T foo(T t) throws T {\n" +
" return t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<EX>().baz(new EX());\n" +
" }\n" +
" void baz(final T t) {\n" +
" new Object() {\n" +
" void print() {\n" +
" System.out.println(foo(t));\n" +
" }\n" +
" }.print();\n" +
" }\n" +
"}\n" +
"class EX extends Exception {\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
" System.out.println(foo(t));\n" +
" ^^^^^^\n" +
"Unhandled exception type T\n" +
"----------\n" +
"2. WARNING in X.java (at line 16)\n" +
" class EX extends Exception {\n" +
" ^^\n" +
"The serializable class EX does not declare a static final serialVersionUID field of type long\n" +
"----------\n");
}
public void test0015() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends Exception> {\n" +
" String foo() throws T {\n" +
" return \"SUCCESS\";\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<EX>().baz(new EX());\n" +
" }\n" +
" void baz(final T t) {\n" +
" new Object() {\n" +
" void print() {\n" +
" try {\n" +
" System.out.println(foo());\n" +
" } catch (Exception t) {\n" +
" }\n" +
" }\n" +
" }.print();\n" +
" }\n" +
"}\n" +
"class EX extends Exception {\n" +
"}\n",
},
"SUCCESS");
}
public void test0016() {
this.runConformTest(
new String[] {
"X.java",
"public class X <E extends Exception> {\n" +
" void foo(E e) throws E {\n" +
" throw e;\n" +
" }\n" +
" void bar(E e) {\n" +
" try {\n" +
" foo(e);\n" +
" } catch(Exception ex) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<Exception>().bar(new Exception());\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0017() {
this.runNegativeTest(
new String[] {
"X.java",
"import java.io.IOException;\n" +
"public class X <E extends Exception> {\n" +
" void foo(E e) throws E {\n" +
" throw e;\n" +
" }\n" +
" void bar(E e) {\n" +
" try {\n" +
" foo(e);\n" +
" } catch(Exception ex) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<IOException>().bar(new Exception());\n" +
" }\n" +
"}\n" ,
},
"----------\n" +
"1. ERROR in X.java (at line 14)\n" +
" new X<IOException>().bar(new Exception());\n" +
" ^^^\n" +
"The method bar(IOException) in the type X<IOException> is not applicable for the arguments (Exception)\n" +
"----------\n");
}
public void test0018() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T foo(T t) {\n" +
" System.out.println(t);\n" +
" return t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<XY>() {\n" +
" void run() {\n" +
" foo(new XY());\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n" +
"class XY {\n" +
" public String toString() {\n" +
" return \"SUCCESS\";\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0019() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" private T foo(T t) {\n" +
" System.out.println(t);\n" +
" return t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<XY>() {\n" +
" void run() {\n" +
" foo(new XY());\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n" +
"class XY {\n" +
" public String toString() {\n" +
" return \"SUCCESS\";\n" +
" }\n" +
"}",
},
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
" foo(new XY());\n" +
" ^^^\n" +
"The method foo(T) in the type X<T> is not applicable for the arguments (XY)\n" +
"----------\n" +
"2. WARNING in X.java (at line 15)\n" +
" public String toString() {\n" +
" ^^^^^^^^^^\n" +
"The method toString() of type XY should be tagged with @Override since it actually overrides a superclass method\n" +
"----------\n");
}
public void test0020() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" void foo(Y<T> y) {\n" +
" System.out.print(\"SUCC\");\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>().bar();\n" +
" }\n" +
" void bar() {\n" +
" new Y<T>() {\n" +
" @Override\n" +
" public void pre() {\n" +
" foo(this);\n" +
" }\n" +
" }.print(\"ESS\");\n" +
" }\n" +
"}\n" +
"class Y <P> {\n" +
" public void print(P p) {\n" +
" pre();\n" +
" System.out.println(p);\n" +
" }\n" +
" public void pre() {\n" +
" }\n" +
"}",
},
"----------\n" +
"1. ERROR in X.java (at line 14)\n" +
" }.print(\"ESS\");\n" +
" ^^^^^\n" +
"The method print(T) in the type Y<T> is not applicable for the arguments (String)\n" +
"----------\n");
}
public void test0021() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends String> {\n" +
" void foo(T t) {\n" +
" }\n" +
" void bar(String x) {\n" +
" foo(x);\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>().foo(new Object());\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends String> {\n" +
" ^^^^^^\n" +
"The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" foo(x);\n" +
" ^^^\n" +
"The method foo(T) in the type X<T> is not applicable for the arguments (String)\n" +
"----------\n" +
"3. ERROR in X.java (at line 8)\n" +
" new X<String>().foo(new Object());\n" +
" ^^^\n" +
"The method foo(String) in the type X<String> is not applicable for the arguments (Object)\n" +
"----------\n");
}
public void test0022() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends String> {\n" +
" X(T t) {\n" +
" System.out.println(t);\n" +
" }\n" +
" \n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0023() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends String> {\n" +
" X(final T t) {\n" +
" new Object() {\n" +
" void print() {\n" +
" System.out.println(t);\n" +
" }\n" +
" }.print();\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0024() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends Exception> {\n" +
" X(final T t) throws T {\n" +
" new Object() {\n" +
" void print() {\n" +
" System.out.println(t);\n" +
" }\n" +
" }.print();\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<EX>(new EX());\n" +
" }\n" +
"}\n" +
"class EX extends Exception {\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 10)\n" +
" new X<EX>(new EX());\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"Unhandled exception type EX\n" +
"----------\n" +
"2. WARNING in X.java (at line 13)\n" +
" class EX extends Exception {\n" +
" ^^\n" +
"The serializable class EX does not declare a static final serialVersionUID field of type long\n" +
"----------\n");
}
public void test0025() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends Exception> {\n" +
" String foo() throws T {\n" +
" return \"SUCCESS\";\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<EX>(new EX());\n" +
" }\n" +
" X(final T t) {\n" +
" new Object() {\n" +
" void print() {\n" +
" try {\n" +
" System.out.println(foo());\n" +
" } catch (Exception t) {\n" +
" }\n" +
" }\n" +
" }.print();\n" +
" }\n" +
"}\n" +
"class EX extends Exception {\n" +
"}\n",
},
"SUCCESS");
}
public void test0026() {
this.runConformTest(
new String[] {
"X.java",
"public class X <E extends Exception> {\n" +
" void foo(E e) throws E {\n" +
" throw e;\n" +
" }\n" +
" X(E e) {\n" +
" try {\n" +
" foo(e);\n" +
" } catch(Exception ex) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<Exception>(new Exception());\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0027() {
this.runNegativeTest(
new String[] {
"X.java",
"import java.io.IOException;\n" +
"public class X <E extends Exception> {\n" +
" void foo(E e) throws E {\n" +
" throw e;\n" +
" }\n" +
" X(E e) {\n" +
" try {\n" +
" foo(e);\n" +
" } catch(Exception ex) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<IOException>(new Exception());\n" +
" }\n" +
"}\n" ,
},
"----------\n" +
"1. ERROR in X.java (at line 14)\n" +
" new X<IOException>(new Exception());\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"The constructor X<IOException>(Exception) is undefined\n" +
"----------\n");
}
public void test0028() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" String s = new X<String>(\"SU\").t;\n" +
" System.out.print(s);\n" +
" s = new X<String>(\"failed\").t = \"CC\";\n" +
" System.out.print(s);\n" +
" s = new X<String>(\"\").t += \"ESS\";\n" +
" System.out.println(s);\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0029() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T t;\n" +
" X() {\n" +
" }\n" +
" T foo(T a, T b) {\n" +
" T s;\n" +
" s = t = a;\n" +
" s = t += b;\n" +
" return t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" System.out.println(new X<String>().foo(\"SUC\", \"CESS\"));\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 8)\n" +
" s = t += b;\n" +
" ^^^^^^\n" +
"The operator += is undefined for the argument type(s) T, T\n" +
"----------\n");
}
public void test0030() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T t;\n" +
" X() {\n" +
" }\n" +
" T foo(T a) {\n" +
" T s;\n" +
" s = t = a;\n" +
" return t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" System.out.println(new X<String>().foo(\"SUCCESS\"));\n" +
" }\n" +
"}\n" ,
},
"SUCCESS");
}
public void test0031() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new X<String>(\"INNER\") {\n" +
" void run() {\n" +
" \n" +
" new Object() {\n" +
" void run() {\n" +
" String s = t = \"SUC\";\n" +
" s = t+= \"CESS\";\n" +
" System.out.println(t);\n" +
" }\n" +
" }.run();\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n" ,
},
"SUCCESS");
}
public void test0032() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new X<String>(\"INNER\") {\n" +
" void run() {\n" +
" String s = t = \"SUC\";\n" +
" s = t+= \"CESS\";\n" +
" System.out.println(t);\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n" ,
},
"SUCCESS");
}
public void test0033() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <E, T> {\n" +
" void foo(E e){}\n" +
" void foo(T t){}\n" +
"}\n" ,
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" void foo(E e){}\n" +
" ^^^^^^^^\n" +
"Method foo(E) has the same erasure foo(Object) as another method in type X<E,T>\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" void foo(T t){}\n" +
" ^^^^^^^^\n" +
"Method foo(T) has the same erasure foo(Object) as another method in type X<E,T>\n" +
"----------\n");
}
public void test0034() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <E extends Exception, T extends Exception> {\n" +
" void foo(E e){}\n" +
" void foo(T t){}\n" +
"}\n" ,
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" void foo(E e){}\n" +
" ^^^^^^^^\n" +
"Method foo(E) has the same erasure foo(Exception) as another method in type X<E,T>\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" void foo(T t){}\n" +
" ^^^^^^^^\n" +
"Method foo(T) has the same erasure foo(Exception) as another method in type X<E,T>\n" +
"----------\n");
}
public void test0035() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <E extends Exception, T extends Thread> {\n" +
" void foo(E e, Thread t){}\n" +
" void foo(Exception e, T t){}\n" +
"}\n" ,
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" void foo(E e, Thread t){}\n" +
" ^^^^^^^^^^^^^^^^^^\n" +
"Method foo(E, Thread) has the same erasure foo(Exception, Thread) as another method in type X<E,T>\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" void foo(Exception e, T t){}\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
"Method foo(Exception, T) has the same erasure foo(Exception, Thread) as another method in type X<E,T>\n" +
"----------\n");
}
public void test0036() {
this.runConformTest(
new String[] {
"X.java",
"public class X <E extends Exception, T extends Thread> {\n" +
" void foo(E e){}\n" +
" void foo(T t){}\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" ,
},
"SUCCESS");
}
public void test0037() {
this.runConformTest(
new String[] {
"X.java",
"public class X <E extends Cloneable, T extends Thread & Cloneable> {\n" +
" void foo(E e){}\n" +
" void foo(T t){}\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" ,
},
"SUCCESS");
}
public void test0038() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <E extends Cloneable, T extends Thread & Cloneable> {\n" +
" void foo(E e){}\n" +
" void foo(T t){}\n" +
" public static void main(String[] args) {\n" +
" X<XY,XY> x = new X();\n" +
" x.foo(new XY());\n" +
" }\n" +
"}\n" +
"class XY extends Thread implements Cloneable {\n" +
"}\n" ,
}, "----------\n" +
"1. ERROR in X.java (at line 6)\n" +
" x.foo(new XY());\n" +
" ^^^\n" +
"The method foo(XY) is ambiguous for the type X<XY,XY>\n" +
"----------\n");
}
public void test0039() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <E extends Cloneable, T extends Thread> {\n" +
" void foo(L<E> l1){}\n" +
" void foo(L<T> l2){}\n" +
" void foo(L l){}\n" +
"}\n" +
"\n" +
"class L<E> {\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" void foo(L<E> l1){}\n" +
" ^^^^^^^^^^^^\n" +
"Method foo(L<E>) has the same erasure foo(L) as another method in type X\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" void foo(L<T> l2){}\n" +
" ^^^^^^^^^^^^\n" +
"Method foo(L<T>) has the same erasure foo(L) as another method in type X\n" +
"----------\n" +
"3. ERROR in X.java (at line 4)\n" +
" void foo(L l){}\n" +
" ^^^^^^^^\n" +
"Duplicate method foo(L) in type X<E,T>\n" +
"----------\n" +
"4. WARNING in X.java (at line 4)\n" +
" void foo(L l){}\n" +
" ^\n" +
"L is a raw type. References to generic type L<E> should be parameterized\n" +
"----------\n");
}
public void test0040() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends X> {\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" } \n" +
"}\n",
},
"SUCCESS");
}
public void test0041() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T, U extends T> {\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" } \n" +
"}\n",
},
"SUCCESS");
}
// **
public void test0042() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends U, U> {\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" public class X <T extends U, U> {\n" +
" ^\n" +
"Illegal forward reference to type parameter U\n" +
"----------\n");
}
public void test0043() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends L {\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"class L<E>{}\n",
},
"SUCCESS");
}
public void test0044() {
this.runConformTest(
new String[] {
"X.java",
"public class X extends L<X> {\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" } \n" +
"}\n" +
"class L<E> {}\n",
},
"SUCCESS");
}
public void test0045() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
" public Z<T> var;\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" public Z<T> var;\n" +
" ^\n" +
"Z cannot be resolved to a type\n" +
"----------\n" +
"2. ERROR in X.java (at line 2)\n" +
" public Z<T> var;\n" +
" ^\n" +
"T cannot be resolved to a type\n" +
"----------\n");
}
public void test0046() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
" public Object<T> var;\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" public Object<T> var;\n" +
" ^\n" +
"T cannot be resolved to a type\n" +
"----------\n");
}
public void test0047() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" private T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new MX<String>(\"INNER\") {\n" +
" void run() {\n" +
" \n" +
" new Object() {\n" +
" void run() {\n" +
" String s = t = \"SUC\";\n" +
" s = t+= \"CESS\";\n" +
" System.out.println(t);\n" +
" }\n" +
" }.run();\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n" +
"class MX<U> {\n" +
" MX(U u){}\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 15)\n" +
" String s = t = \"SUC\";\n" +
" ^^^^^^^^^\n" +
"Type mismatch: cannot convert from T to String\n" +
"----------\n" +
"2. ERROR in X.java (at line 15)\n" +
" String s = t = \"SUC\";\n" +
" ^^^^^\n" +
"Type mismatch: cannot convert from String to T\n" +
"----------\n" +
"3. ERROR in X.java (at line 16)\n" +
" s = t+= \"CESS\";\n" +
" ^^^^^^^^^^\n" +
"The operator += is undefined for the argument type(s) T, String\n" +
"----------\n");
}
// Access to enclosing 't' of type 'T' (not substituted from X<X> as private thus non inherited)
// **
public void test0048() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" private T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new X<X>(this) {\n" +
" void run() {\n" +
" new Object() {\n" +
" void run() {\n" +
" X x = t;\n" +
" System.out.println(x);\n" +
" }\n" +
" }.run();\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 10)\n" +
" new X<X>(this) {\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 14)\n" +
" X x = t;\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"3. ERROR in X.java (at line 14)\n" +
" X x = t;\n" +
" ^\n" +
"Type mismatch: cannot convert from T to X\n" +
"----------\n");
}
public void test0049() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" public T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new X<X>(this) {\n" +
" void run() {\n" +
" new Object() {\n" +
" void run() {\n" +
" X x = t;\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" }.run();\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0050() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends N> {\n" +
" static class N {}" +
"}\n" +
"class Y <T extends Y.N> {\n" +
" static class N {}" +
"}\n"
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" public class X <T extends N> {\n" +
" ^\n" +
"N cannot be resolved to a type\n" +
"----------\n");
}
public void test0050a() {
this.runNegativeTest(
new String[] {
"X.java",
"class Super {class M {}}\n" +
"public class X <T extends M> extends Super {}\n" +
"class Y <T extends Y.M> extends Super {}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" public class X <T extends M> extends Super {}\n" +
" ^\n" +
"M cannot be resolved to a type\n" +
"----------\n" +
"2. WARNING in X.java (at line 3)\n" +
" class Y <T extends Y.M> extends Super {}\n" +
" ^^^\n" +
"Y.M is a raw type. References to generic type Super.M should be parameterized\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98504
public void test0050b() {
this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
" class M extends Y implements I {}\n" +
"}\n" +
"class Y {\n" +
" static interface I { void foo(); }\n" +
"}\n" +
"interface I {}\n"
},
"");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98504 - variation
public void test0050c() {
this.runConformTest(
new String[] {
"Test.java",
"public class Test<T extends Test.InnerTest> implements Base {\n" +
" static class InnerTest implements Inner {}\n" +
"}\n"+
"interface Base<T> {\n" +
" interface Inner {}\n" +
"}\n"
},
"");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101387
public void test0050d() {
this.runConformTest(
new String[] {
"X.java",
"public class X<I, C extends I> {}\n" +
"class Y extends X<Y.M, Y.N> {\n" +
" static class M {}\n" +
" static class N extends M {}\n" +
"}\n"
},
"");
}
public void test0051() {
this.runConformTest(
new String[] {
"X.java",
"class Super {class M {}}\n" +
"public class X extends Super {\n" +
" class N <T extends M> {}\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0052() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> extends p.A {\n" +
" public static void main(String[] args) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
"}\n",
},
"SUCCESS");
}
public void test0053() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new X<X>(this) {\n" +
" void run() {\n" +
" new Object() {\n" +
" void run() {\n" +
" print(t);\n" +
" }\n" +
" }.run();\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0054() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"OUTER\").bar();\n" +
" }\n" +
" void bar() {\n" +
" new X<X>(this) {\n" +
" void run() {\n" +
" new Object() {\n" +
" void run() {\n" +
" print(X.this.t);\n" +
" }\n" +
" }.run();\n" +
" }\n" +
" }.run();\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 10)\n" +
" new X<X>(this) {\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 14)\n" +
" print(X.this.t);\n" +
" ^^^^^\n" +
"The method print(X) in the type A<X> is not applicable for the arguments (T)\n" +
"----------\n");
}
public void test0055() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" super(t);\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<String> xs = new X(\"SUCCESS\");\n" +
" System.out.println(xs.t);\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p; \n" +
" } \n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0056() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" super(t);\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<String> xs = new X(\"SUCCESS\");\n" +
" System.out.println((X)xs.t);\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p; \n" +
" } \n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
" System.out.println((X)xs.t);\n" +
" ^^^^^^^\n" +
"Cannot cast from String to X\n" +
"----------\n" +
"----------\n" +
"1. WARNING in p\\A.java (at line 7)\n" +
" protected void print(P p) {\n" +
" ^\n" +
"The parameter p is hiding a field from type A<P>\n" +
"----------\n");
}
public void test0057() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T> extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" super(t);\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<X xs = new X>(new X(\"SUCCESS\"));\n" +
" System.out.println(xs.t.t);\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p; \n" +
" } \n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
// JSR14-v10[2.1,2.2]: Valid multiple parameter types
public void test0058() {
this.runConformTest(
new String[] {
"test/X.java",
"package test;\n" +
"// Valid Parameterized Type Declaration\n" +
"public class X<A1, A2, A3> {\n" +
"}\n" +
"// Valid Type Syntax\n" +
"class Y {\n" +
" X<String, Number, Integer> x;\n" +
"}\n"
}
);
}
// JSR14-v10[2.1,2.2]: Invalid multiple parameter types: more declared than referenced
public void test0059() {
this.runNegativeTest(
new String[] {
"test/X.java",
"package test;\n" +
"// Valid Parameterized Type Declaration\n" +
"public class X<A1, A2, A3, A4> {\n" +
"}\n" +
"// Invalid Valid Type Syntax (not enough parameters)\n" +
"class Y {\n" +
" X<String, Number, Integer> x;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X.java (at line 7)\n" +
" X<String, Number, Integer> x;\n" +
" ^\n" +
"Incorrect number of arguments for type X<A1,A2,A3,A4>; it cannot be parameterized with arguments \n" +
"----------\n"
);
}
// JSR14-v10[2.1,2.2]: Invalid multiple parameter types: more referenced than declared
public void test0060() {
this.runNegativeTest(
new String[] {
"test/X.java",
"package test;\n" +
"// Valid Parameterized Type Declaration\n" +
"public class X<A1, A2> {\n" +
"}\n" +
"// Invalid Valid Type Syntax (too many parameters)\n" +
"class Y {\n" +
" X<String, Number, Integer> x;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X.java (at line 7)\n" +
" X<String, Number, Integer> x;\n" +
" ^\n" +
"Incorrect number of arguments for type X<A1,A2>; it cannot be parameterized with arguments \n" +
"----------\n"
);
}
// JSR14-v10[2.1,2.2]: Invalid multiple parameter types: primitive types
public void test0061() {
this.runNegativeTest(
new String[] {
"test/X.java",
"package test;\n" +
"// Valid Parameterized Type Declaration\n" +
"public class X<A1, A2, A3, A4, A5, A6, A7> {\n" +
"}\n" +
"// Invalid Valid Type Syntax (primitive cannot be parameters)\n" +
"class Y {\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^\n" +
"Syntax error on token \"int\", Dimensions expected after this token\n" +
"----------\n" +
"2. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^^^\n" +
"Syntax error on token \"short\", Dimensions expected after this token\n" +
"----------\n" +
"3. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^^\n" +
"Syntax error on token \"long\", Dimensions expected after this token\n" +
"----------\n" +
"4. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^^^\n" +
"Syntax error on token \"float\", Dimensions expected after this token\n" +
"----------\n" +
"5. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^^^^\n" +
"Syntax error on token \"double\", Dimensions expected after this token\n" +
"----------\n" +
"6. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^^^^^\n" +
"Syntax error on token \"boolean\", Dimensions expected after this token\n" +
"----------\n" +
"7. ERROR in test\\X.java (at line 7)\n" +
" X<int, short, long, float, double, boolean, char> x;\n" +
" ^^^^\n" +
"Syntax error on token \"char\", Dimensions expected after this token\n" +
"----------\n"
);
}
// JSR14-v10[2.1,2.2]: Valid multiple parameter types: primitive type arrays
public void test0062() {
this.runConformTest(
new String[] {
"test/X.java",
"package test;\n" +
"// Valid Parameterized Type Declaration\n" +
"public class X<A1, A2, A3, A4, A5, A6, A7, A8> {\n" +
"}\n" +
"// Valid Type Syntax\n" +
"class Y {\n" +
" X<int[], short[][], long[][][], float[][][][], double[][][][][], boolean[][][][][][], char[][][][][][][], Object[][][][][][][][][]> x;\n" +
"}\n"
},
""
);
}
public void test0063() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> extends p.A {\n" +
" \n" +
" X(T t) {\n" +
" super(t);\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X x = new X(args);\n" +
" X<String> xs = new X(args);\n" +
" }\n" +
"}\n",
"p/A.java",
"package p; \n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p; \n" +
" } \n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\"+p);\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 7)\n" +
" X x = new X(args);\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 7)\n" +
" X x = new X(args);\n" +
" ^^^^^^^^^^^\n" +
"Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 7)\n" +
" X x = new X(args);\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"4. ERROR in X.java (at line 8)\n" +
" X<String> xs = new X(args);\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"The constructor X<String>(String[]) is undefined\n" +
"----------\n" +
"----------\n" +
"1. WARNING in p\\A.java (at line 7)\n" +
" protected void print(P p) {\n" +
" ^\n" +
"The parameter p is hiding a field from type A<P>\n" +
"----------\n");
}
// raw type: variable map to its strict erasure
public void test0064() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T extends Exception & IX> {\n" +
" T t;\n" +
" void bar(T t) {\n" +
" t.getMessage();\n" +
" t.foo();\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X x = new X();\n" + // raw type
" x.t.getMessage();\n" + // T is strictly exception !
" x.t.foo();\n" +
" }\n" +
"}\n" +
"\n" +
"interface IX {\n" +
" void foo();\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 3)\n" +
" void bar(T t) {\n" +
" ^\n" +
"The parameter t is hiding a field from type X<T>\n" +
"----------\n" +
"2. WARNING in X.java (at line 8)\n" +
" X x = new X();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 8)\n" +
" X x = new X();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"4. ERROR in X.java (at line 10)\n" +
" x.t.foo();\n" +
" ^^^\n" +
"The method foo() is undefined for the type Exception\n" +
"----------\n");
}
// raw type: assignments
public void test0065() {
Map customOptions = getCompilerOptions();
this.runNegativeTest(
new String[] {
"X.java",
"import java.io.IOException;\n" +
"\n" +
"public class X<T extends Exception> {\n" +
"\n" +
" public static void main(String[] args) {\n" +
" X x = new X();\n" +
" X<IOException> xioe = new X(); // ok\n" +
" \n" +
" X x2 = xioe;\n" +
" X<IOException> xioe2 = x; // unsafe\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 6)\n" +
" X x = new X();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 6)\n" +
" X x = new X();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 9)\n" +
" X x2 = xioe;\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"4. WARNING in X.java (at line 10)\n" +
" X<IOException> xioe2 = x; // unsafe\n" +
" ^\n" +
"Type safety: The expression of type X needs unchecked conversion to conform to X<IOException>\n" +
"----------\n",
null,
true,
customOptions);
}
// JSR14-v10[2.1,2.2]: Invalid PT declaration (mix with reference)
public void test0066() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Valid Consecutive Parameterized Type Declaration\n" +
"public class X1<A1 extends X2 {\n" +
" A1 a1;\n" +
"}\n" +
"// Valid Parameterized Type Declaration\n" +
"class X2<A2>{\n" +
" A2 a2;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1<A1 extends X2 {\n" +
" ^^\n" +
"A2 cannot be resolved to a type\n" +
"----------\n"
);
}
// JSR14-v10[2.1,2.2]: Invalid PT declaration (mix with reference)
public void test0067() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Valid Consecutive Parameterized Type Declaration\n" +
"public class X1< A1 extends X2 < A2 > > {\n" +
" A1 a1;\n" +
"}\n" +
"// Valid Parameterized Type Declaration\n" +
"class X2<A2>{\n" +
" A2 a2;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1< A1 extends X2 < A2 > > {\n" +
" ^^\n" +
"A2 cannot be resolved to a type\n" +
"----------\n"
);
}
// JSR14-V10[2.4]: Not terminated consecutive declaration
// TODO (david) diagnosis message on error 3 sounds strange, doesn't it?
public void test0068() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Invalid Consecutive Parameterized Type Declaration\n" +
"public class X1<A1 extends X2\" to complete ReferenceType2\n" +
"----------\n"
);
}
// JSR14-v10[2.4]: Unexpected consecutive PT declaration (right-shift symbol)
// TODO (david) surround expected token with (double-)quotes
public void test0070() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Invalid Consecutive Parameterized Type Declaration\n" +
"public class X1<A1>> {\n" +
" A1 a1;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1<A1>> {\n" +
" ^^\n" +
"Syntax error on token \">>\", > expected\n" +
"----------\n"
);
}
// JSR14-v10[2.1,2.2]: Unexpected consecutive PT declaration (with spaces)
public void test0071() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Invalid Consecutive Parameterized Type Declaration\n" +
"public class X1 < A1 > > {\n" +
" A1 a1;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1 < A1 > > {\n" +
" ^\n" +
"Syntax error on token \">\", delete this token\n" +
"----------\n"
);
}
// JSR14-v10[2.4]: Unexpected consecutive PT declaration (unary right-shift symbol)
// TODO (david) surround expected token with (double-)quotes
public void test0072() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Invalid Consecutive Parameterized Type Declaration\n" +
"public class X1<A1>>> {\n" +
" A1 a1;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1<A1>>> {\n" +
" ^^^\n" +
"Syntax error on token \">>>\", > expected\n" +
"----------\n"
);
}
// JSR14-v10[2.4]: Unexpected consecutive PT declaration (right-shift symbol)
// TODO (david) surround expected token with (double-)quotes
public void test0073() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Invalid Consecutive Parameterized Type Declaration\n" +
"public class X1<A1 extends X2> {\n" +
" A1 a1;\n" +
"}\n" +
"// Valid Parameterized Type Declaration\n" +
"class X2<A2> {\n" +
" A2 a2;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1<A1 extends X2> {\n" +
" ^^^\n" +
"Syntax error on token \">>>\", >> expected\n" +
"----------\n"
);
}
// JSR14-v10[2.1,2.2]: Unexpected consecutive PT declaration (with spaces)
public void test0074() {
this.runNegativeTest(
new String[] {
"test/X1.java",
"package test;\n" +
"// Invalid Consecutive Parameterized Type Declaration\n" +
"public class X1 < A1 > > > {\n" +
" A1 a1;\n" +
"}\n"
},
"----------\n" +
"1. ERROR in test\\X1.java (at line 3)\n" +
" public class X1 < A1 > > > {\n" +
" ^^^\n" +
"Syntax error on tokens, delete these tokens\n" +
"----------\n"
);
}
// A is not an interface
public void test0075() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends Object & p.A extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" super(t);\n" +
" this.t = t;\n" +
" }\n" +
"}",
"p/A.java",
"package p;\n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p;\n" +
" }\n" +
"}"
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" public class X <T extends Object & p.A extends p.A {\n" +
" ^^^\n" +
"The type A<? super T> is not an interface; it cannot be specified as a bounded parameter\n" +
"----------\n"
);
}
// A is not an interface
public void test0076() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends Object & p.A> extends p.A {\n" +
" protected T t;\n" +
" X(T t) {\n" +
" super(t);\n" +
" this.t = t;\n" +
" }\n" +
"}",
"p/A.java",
"package p;\n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p;\n" +
" }\n" +
"}"
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends Object & p.A> extends p.A {\n" +
" ^^^\n" +
"A is a raw type. References to generic type A<P> should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <T extends Object & p.A> extends p.A {\n" +
" ^^^\n" +
"The type A is not an interface; it cannot be specified as a bounded parameter\n" +
"----------\n"
);
}
// unsafe type operation: only for constructors with signature change
public void test0077() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> extends p.A {\n" +
" X() {\n" +
" super(null);\n" +
" }\n"+
" X(T t) {\n" +
" super(t);\n" +
" }\n" +
" X(X<T> xt) {\n" +
" super(xt.t);\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X x = new X();\n" +
" X x1 = new X(args);\n" +
" X x2 = new X(x);\n" +
" X<String> xs = new X(args);\n" +
" }\n" +
"}\n",
"p/A.java",
"package p;\n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p;\n" +
" }\n" +
"}"
},
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
" super(xt.t);\n" +
" ^^^^\n" +
"xt.t cannot be resolved or is not a field\n" +
"----------\n" +
"2. WARNING in X.java (at line 12)\n" +
" X x = new X();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 12)\n" +
" X x = new X();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"4. WARNING in X.java (at line 13)\n" +
" X x1 = new X(args);\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"5. WARNING in X.java (at line 13)\n" +
" X x1 = new X(args);\n" +
" ^^^^^^^^^^^\n" +
"Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"6. WARNING in X.java (at line 13)\n" +
" X x1 = new X(args);\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"7. WARNING in X.java (at line 14)\n" +
" X x2 = new X(x);\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"8. WARNING in X.java (at line 14)\n" +
" X x2 = new X(x);\n" +
" ^^^^^^^^\n" +
"Type safety: The constructor X(X) belongs to the raw type X. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"9. WARNING in X.java (at line 14)\n" +
" X x2 = new X(x);\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"10. ERROR in X.java (at line 15)\n" +
" X<String> xs = new X(args);\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"The constructor X<String>(String[]) is undefined\n" +
"----------\n");
}
public void test0078() {
this.runNegativeTest(
new String[] {
"X.java",
"import p.A;\n" +
"public class X {\n" +
" X(A<String> a, A b) {\n" +
" }\n" +
" void foo(A<String> a) {\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X x = new X((A)null, (A)null);\n" +
" A a = new A((A)null);\n" +
" x.foo(a);\n" +
" a.print(x);\n" +
" A<String> as = new A(null);\n" +
" as.print(\"hello\");\n" +
" }\n" +
"}\n",
"p/A.java",
"package p;\n" +
"public class A<P> {\n" +
" protected P p;\n" +
" protected A(P p) {\n" +
" this.p = p;\n" +
" }\n" +
" protected void print(P p) {\n" +
" System.out.println(\"SUCCESS\"+p);\n" +
" }\n" +
" protected void print(A<P> a) {\n" +
" print(a.p);\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 8)\n" +
" X x = new X((A)null, (A)null);\n" +
" ^^^^^^^\n" +
"Type safety: The expression of type A needs unchecked conversion to conform to A<String>\n" +
"----------\n" +
"2. WARNING in X.java (at line 8)\n" +
" X x = new X((A)null, (A)null);\n" +
" ^\n" +
"A is a raw type. References to generic type A<P> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 8)\n" +
" X x = new X((A)null, (A)null);\n" +
" ^^^^^^^\n" +
"Type safety: The expression of type A needs unchecked conversion to conform to A<String>\n" +
"----------\n" +
"4. WARNING in X.java (at line 8)\n" +
" X x = new X((A)null, (A)null);\n" +
" ^\n" +
"A is a raw type. References to generic type A<P> should be parameterized\n" +
"----------\n" +
"5. WARNING in X.java (at line 9)\n" +
" A a = new A((A)null);\n" +
" ^\n" +
"A is a raw type. References to generic type A<P> should be parameterized\n" +
"----------\n" +
"6. ERROR in X.java (at line 9)\n" +
" A a = new A((A)null);\n" +
" ^^^^^^^^^^^^^^\n" +
"The constructor A(P) is not visible\n" +
"----------\n" +
"7. WARNING in X.java (at line 9)\n" +
" A a = new A((A)null);\n" +
" ^\n" +
"A is a raw type. References to generic type A<P> should be parameterized\n" +
"----------\n" +
"8. WARNING in X.java (at line 9)\n" +
" A a = new A((A)null);\n" +
" ^\n" +
"A is a raw type. References to generic type A<P> should be parameterized\n" +
"----------\n" +
"9. WARNING in X.java (at line 10)\n" +
" x.foo(a);\n" +
" ^\n" +
"Type safety: The expression of type A needs unchecked conversion to conform to A<String>\n" +
"----------\n" +
"10. ERROR in X.java (at line 11)\n" +
" a.print(x);\n" +
" ^^^^^\n" +
"The method print(P) from the type A is not visible\n" +
"----------\n" +
"11. ERROR in X.java (at line 12)\n" +
" A<String> as = new A(null);\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"The constructor A<String>(P) is not visible\n" +
"----------\n" +
"12. ERROR in X.java (at line 13)\n" +
" as.print(\"hello\");\n" +
" ^^^^^\n" +
"The method print(P) from the type A<String> is not visible\n" +
"----------\n" +
"----------\n" +
"1. WARNING in p\\A.java (at line 7)\n" +
" protected void print(P p) {\n" +
" ^\n" +
"The parameter p is hiding a field from type A<P>\n" +
"----------\n");
}
// JSR14-v10[2.4]: Valid consecutive Type Parameters Brackets
public void test0079() {
this.runConformTest(
new String[] {
"test/X.java",
"package test;\n" +
"public class X<A extends X1>> {\n" +
" A a;\n" +
" public static void main(String[] args) {\n" +
" X<X1>> x = new X>>>();\n" +
" x.a = new X1<X2>();\n" +
" x.a.a1 = new X2<X3();\n" +
" x.a.a1.a2 = new X3<String>();\n" +
" x.a.a1.a2.a3 = \"SUCCESS\";\n" +
" System.out.println(x.a.a1.a2.a3);\n" +
" }\n" +
"}\n" +
"class X1<A extends X2> {\n" +
" A a1;\n" +
"}\n" +
"class X2<A extends X3 {\n" +
" A a2;\n" +
"}\n" +
"class X3<A> {\n" +
" A a3;\n" +
"}\n"
},
"SUCCESS"
);
}
// TODO (david) remove errors: insert dimension to complete array type
public void test0080() {
this.runNegativeTest(
new String[] {
"test/X.java",
"package test;\n" +
"public class X<A extends X1> {}\n" +
"class X1<A extends X2 {}\n" +
"class X2<A extends X3> {}\n" +
" ^^^\n" +
"Syntax error, insert \">\" to complete ReferenceType1\n" +
"----------\n" +
"2. ERROR in test\\X.java (at line 3)\n" +
" class X1<A extends X2 {}\n" +
" ^^\n" +
"Syntax error, insert \">\" to complete ReferenceType1\n" +
"----------\n" +
"3. ERROR in test\\X.java (at line 4)\n" +
" class X2<A extends X3 {}\n" +
"class X1<A extends X2 {}\n" +
" ^^\n" +
"Syntax error, insert \">>\" to complete ReferenceType2\n" +
"----------\n" +
"2. ERROR in test\\X.java (at line 3)\n" +
" class X1<A extends X2\" to complete ReferenceType2\n" +
"----------\n" +
"3. ERROR in test\\X.java (at line 4)\n" +
" class X2<A extends X3\" to complete ReferenceType2\n" +
"----------\n"
);
}
// TODO (david) remove error: insert dimension to complete array type
public void test0082() {
this.runNegativeTest(
new String[] {
"test/X.java",
"package test;\n" +
"public class X<A extends X1 {}\n" +
"class X3<A> {}\n"
},
"----------\n" +
"1. ERROR in test\\X.java (at line 2)\n" +
" public class X<A extends X1>\" to complete ReferenceType3\n" +
"----------\n" +
"2. ERROR in test\\X.java (at line 3)\n" +
" class X1<A extends X2>\" to complete ReferenceType3\n" +
"----------\n"
);
}
// TODO (david) remove error: insert dimension to complete array type
public void test0083() {
this.runNegativeTest(
new String[] {
"test/X.java",
"package test;\n" +
"public class X<A extends X1> {}\n" +
"class X2<A extends X3 {}\n" +
"class X3<A> {}\n"
},
"----------\n" +
"1. ERROR in test\\X.java (at line 2)\n" +
" public class X<A extends X1>\" to complete ReferenceType3\n" +
"----------\n" +
"2. ERROR in test\\X.java (at line 2)\n" +
" public class X<A extends X1 b) {\n" +
" }\n" +
" void foo(AX<String> a) {\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X x = new X((AX)null, (AX)null);\n" +
" AX a = new AX((AX)null);\n" +
" AX a2 = new AX(null);\n" +
" x.foo(a);\n" +
" a.foo(a);\n" +
" a.bar(a);\n" +
" AX<String> as = new AX(null);\n" +
" as.print(a);\n" +
" as.bar(a);\n" +
" }\n" +
"}\n" +
"class AX <P> {\n" +
" AX(AX<P> ax){}\n" +
" AX(P p){}\n" +
" void print(P p){}\n" +
" void foo(AX rawAx){}\n" +
" void bar(AX<P> ax){}\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 7)\n" +
" X x = new X((AX)null, (AX)null);\n" +
" ^^^^^^^^\n" +
"Type safety: The expression of type AX needs unchecked conversion to conform to AX<String>\n" +
"----------\n" +
"2. WARNING in X.java (at line 7)\n" +
" X x = new X((AX)null, (AX)null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 7)\n" +
" X x = new X((AX)null, (AX)null);\n" +
" ^^^^^^^^\n" +
"Type safety: The expression of type AX needs unchecked conversion to conform to AX<String>\n" +
"----------\n" +
"4. WARNING in X.java (at line 7)\n" +
" X x = new X((AX)null, (AX)null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"5. WARNING in X.java (at line 8)\n" +
" AX a = new AX((AX)null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"6. WARNING in X.java (at line 8)\n" +
" AX a = new AX((AX)null);\n" +
" ^^^^^^^^^^^^^^^^\n" +
"Type safety: The constructor AX(AX) belongs to the raw type AX. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"7. WARNING in X.java (at line 8)\n" +
" AX a = new AX((AX)null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"8. WARNING in X.java (at line 8)\n" +
" AX a = new AX((AX)null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"9. WARNING in X.java (at line 9)\n" +
" AX a2 = new AX(null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"10. WARNING in X.java (at line 9)\n" +
" AX a2 = new AX(null);\n" +
" ^^^^^^^^^^^^\n" +
"Type safety: The constructor AX(AX) belongs to the raw type AX. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"11. WARNING in X.java (at line 9)\n" +
" AX a2 = new AX(null);\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"12. WARNING in X.java (at line 10)\n" +
" x.foo(a);\n" +
" ^\n" +
"Type safety: The expression of type AX needs unchecked conversion to conform to AX<String>\n" +
"----------\n" +
"13. WARNING in X.java (at line 12)\n" +
" a.bar(a);\n" +
" ^^^^^^^^\n" +
"Type safety: The method bar(AX) belongs to the raw type AX. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"14. ERROR in X.java (at line 13)\n" +
" AX<String> as = new AX(null);\n" +
" ^^^^^^^^^^^^^^^^^^^^\n" +
"The constructor AX<String>(AX) is ambiguous\n" +
"----------\n" +
"15. ERROR in X.java (at line 14)\n" +
" as.print(a);\n" +
" ^^^^^\n" +
"The method print(String) in the type AX<String> is not applicable for the arguments (AX)\n" +
"----------\n" +
"16. WARNING in X.java (at line 15)\n" +
" as.bar(a);\n" +
" ^\n" +
"Type safety: The expression of type AX needs unchecked conversion to conform to AX<String>\n" +
"----------\n" +
"17. WARNING in X.java (at line 22)\n" +
" void foo(AX rawAx){}\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n");
}
public void test0085() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" \n" +
" public static void main(String[] args) {\n" +
" AX ax = new AX();\n" +
" X x = (X)ax.p;\n" +
" System.out.println(x);\n" +
" }\n" +
"}\n" +
"\n" +
"class AX <P> {\n" +
" \n" +
" P p;\n" +
"}\n",
},
"null");
}
public void test0086() {
Map customOptions = getCompilerOptions();
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" \n" +
" public static void main(String[] args) {\n" +
" AX ax = new AX();\n" +
" AX ax2 = ax.p;\n" +
" ax.p = new AX<String>();\n" +
" System.out.println(ax2);\n" +
" }\n" +
"}\n" +
"\n" +
"class AX <P> {\n" +
" AX<P> p;\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 4)\n" +
" AX ax = new AX();\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 4)\n" +
" AX ax = new AX();\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 5)\n" +
" AX ax2 = ax.p;\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"4. WARNING in X.java (at line 6)\n" +
" ax.p = new AX<String>();\n" +
" ^\n" +
"Type safety: The field p from the raw type AX is assigned a value of type AX<String>. References to generic type AX
should be parameterized\n" +
"----------\n",
null,
true,
customOptions);
}
public void test0087() {
Map customOptions = getCompilerOptions();
// check no unsafe type operation problem is issued
customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" \n" +
" public static void main(String[] args) {\n" +
" AX ax = new AX();\n" +
" AX ax2 = ax.p;\n" +
" AX ax3 = new AX<String>();\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX <P> {\n" +
" AX<P> p;\n" +
"}\n",
},
"SUCCESS",
null,
true,
null,
customOptions,
null/*no custom requestor*/);
}
public void test0088() {
Map customOptions = getCompilerOptions();
// check no unsafe type operation problem is issued
customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" AX ax = new AX();\n" +
" AX ax2 = ax.p;\n" +
" AX ax3 = new AX<String>();\n" +
"}\n" +
"\n" +
"class AX <P> {\n" +
" AX<P> p;\n" +
"}\n",
},
"",
null,
true,
null,
customOptions,
null/*no custom requestor*/);
}
public void test0089() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" T q;\n" +
" public static void main(String[] args) {\n" +
" X<String[]> xss = new X();\n" +
" X<X xxs = new X>();\n" +
" xxs.q = xss;\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0090() {
Map customOptions = getCompilerOptions();
// check no unsafe type operation problem is issued
customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" T q;\n" +
" \n" +
" public static void main(String[] args) {\n" +
" X<String[]> xss = new X();\n" +
" X<X xxs = new X>();\n" +
" xxs.q = xss;\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" void foo(X[] xs) {\n" +
" xs[0] = new X<String>();\n" +
" }\n" +
"}\n",
},
"SUCCESS",
null,
true,
null,
customOptions,
null/*no custom requestor*/);
}
public void test0091() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" void foo(X<String>[] xs) {\n" +
" }\n" +
"}\n",
},
"");
}
public void test0092() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" T t;\n" +
" X(T t) {\n" +
" this.t = t;\n" +
" }\n" +
" void foo() {\n" +
" X<String> xs = new X(\"\");\n" +
" X<String> xs2 = (X) xs;\n" +
" \n" +
" ((X)xs).t = this;\n" +
" \n" +
" System.out.prinln((T) this.t);\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" new X<String>(\"SUCCESS\").foo();\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 8)\n" +
" X<String> xs2 = (X) xs;\n" +
" ^^^^^^^^^^^^^^\n" +
"Unnecessary cast from X<String> to X\n" +
"----------\n" +
"2. WARNING in X.java (at line 10)\n" +
" ((X)xs).t = this;\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 10)\n" +
" ((X)xs).t = this;\n" +
" ^\n" +
"Type safety: The field t from the raw type X is assigned a value of type X<T>. References to generic type X should be parameterized\n" +
"----------\n" +
"4. ERROR in X.java (at line 12)\n" +
" System.out.prinln((T) this.t);\n" +
" ^^^^^^\n" +
"The method prinln(T) is undefined for the type PrintStream\n" +
"----------\n");
}
// **
public void test0093() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" public static void main(String[] args) {\n" +
" AX ax = new AX();\n" +
" AX ax2 = new AX();\n" +
" ax.p = ax2.p;\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"class AX <P> {\n" +
" AX<P> p;\n" +
"}\n",
},
"SUCCESS");
}
// same as test001, but every type is now a SourceTypeBinding
public void test0094() {
this.runConformTest(
new String[] {
"X.java",
"public class X<Tx1 extends S, Tx2 extends C> extends XS {\n" +
"\n" +
" public static void main(String[] args) {\n" +
" I w = new X<S,I>().get(new I());\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"class S {}\n" +
"class I implements C<I> {}\n" +
"interface C<Tc> {}\n" +
"class XS <Txs> {\n" +
" Txs get(Txs t) {\n" +
" return t;\n" +
" }\n" +
"}\n"
},
"SUCCESS");
}
public void test0095() {
this.runConformTest(
new String[] {
"X.java",
"public class X<Tx1 extends S, Tx2 extends C> extends XS {\n" +
"\n" +
" public static void main(String[] args) {\n" +
" I w = new X<S,I>().get(new I());\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"class S {}\n" +
"class I implements C {}\n" +
"interface C<Tc> {}\n" +
"class XS <Txs> {\n" +
" Txs get(Txs t) {\n" +
" return t;\n" +
" }\n" +
"}\n"
},
"SUCCESS");
}
public void test0096() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> extends X {}\n"
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" public class X<T> extends X {}\n" +
" ^\n" +
"Cycle detected: the type X<T> cannot extend/implement itself or one of its own member types\n" +
"----------\n");
}
public void test0097() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> extends X {}\n"
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" public class X<T> extends X {}\n" +
" ^\n" +
"Cycle detected: the type X<T> cannot extend/implement itself or one of its own member types\n" +
"----------\n");
}
public void test0098() {
Map customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
this.runNegativeTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" \n" +
" public static void main(String[] args) {\n" +
" AX ax = new AX();\n" +
" AX ax2 = ax.p;\n" +
" ax.p = new AX<String>();\n" +
" ax.q = new AX<String>();\n" +
" ax.r = new AX<Object>();\n" +
" ax.s = new AX<String>();\n" +
" System.out.println(ax2);\n" +
" }\n" +
"}\n" +
"\n" +
"class AX <P> {\n" +
" AX<P> p;\n" +
" AX<Object> q;\n" +
" AX<String> r;\n" +
" BX<String> s;\n" +
"}\n" +
"\n" +
"class BX<Q> {\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 4)\n" +
" AX ax = new AX();\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 4)\n" +
" AX ax = new AX();\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"3. WARNING in X.java (at line 5)\n" +
" AX ax2 = ax.p;\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"4. ERROR in X.java (at line 6)\n" +
" ax.p = new AX<String>();\n" +
" ^\n" +
"Type safety: The field p from the raw type AX is assigned a value of type AX<String>. References to generic type AX
should be parameterized\n" +
"----------\n" +
"5. ERROR in X.java (at line 7)\n" +
" ax.q = new AX<String>();\n" +
" ^\n" +
"Type safety: The field q from the raw type AX is assigned a value of type AX<String>. References to generic type AX
should be parameterized\n" +
"----------\n" +
"6. ERROR in X.java (at line 8)\n" +
" ax.r = new AX<Object>();\n" +
" ^\n" +
"Type safety: The field r from the raw type AX is assigned a value of type AX<Object>. References to generic type AX
should be parameterized\n" +
"----------\n" +
"7. ERROR in X.java (at line 9)\n" +
" ax.s = new AX<String>();\n" +
" ^^^^^^^^^^^^^^^^\n" +
"Type mismatch: cannot convert from AX<String> to BX\n" +
"----------\n",
null,
true,
customOptions);
}
// wildcard bound cannot be base type
// TODO (david) only syntax error should be related to wilcard bound being a base type. Ripple effect is severe here.
public void test0099() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends AX {\n" +
" public static void main(String[] args) {\n" +
" AX<String> ax;\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" void foo(X<?> x) {\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
"}\n",
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" public class X <T extends AX {\n" +
" ^^^\n" +
"Syntax error on token \"int\", Dimensions expected after this token\n" +
"----------\n");
}
// type parameterized with wildcard cannot appear in allocation
public void test0100() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<? extends AX> x = new X(new AX());\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" P foo() { return null; }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 7)\n" +
" X<? extends AX> x = new X(new AX());\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" X<? extends AX> x = new X(new AX());\n" +
" ^\n" +
"Cannot instantiate the type X<? extends AX>\n" +
"----------\n" +
"3. WARNING in X.java (at line 7)\n" +
" X<? extends AX> x = new X(new AX());\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n");
}
// wilcard may not pass parameter bound check
public void test0101() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends String> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<? extends AX> x = new X>(new AX());\n" +
" x.t.foo(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" void foo(P p) { \n" +
" System.out.println(p);\n" +
" }\n" +
"}\n" +
"\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends String> {\n" +
" ^^^^^^\n" +
"The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" X<? extends AX> x = new X>(new AX());\n" +
" ^^^^^^^^^^^^\n" +
"Bound mismatch: The type ? extends AX is not a valid substitute for the bounded parameter <T extends String> of the type X\n" +
"----------\n" +
"3. WARNING in X.java (at line 7)\n" +
" X<? extends AX> x = new X>(new AX());\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"4. ERROR in X.java (at line 7)\n" +
" X<? extends AX> x = new X>(new AX());\n" +
" ^^\n" +
"Bound mismatch: The type AX<String> is not a valid substitute for the bounded parameter of the type X\n" +
"----------\n" +
"5. WARNING in X.java (at line 8)\n" +
" x.t.foo(\"SUCCESS\");\n" +
" ^^^^^^^^^^^^^^^^^^\n" +
"Type safety: The method foo(Object) belongs to the raw type AX. References to generic type AX<P> should be parameterized\n" +
"----------\n");
}
// unbound wildcard implicitly bound by matching parameter bounds
public void test0102() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends AX> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<?> x = new X>(new BX());\n" +
" x.t.foo(\"SUCC\");\n" +
" x.t.bar(\"ESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" void foo(P p) { \n" +
" System.out.print(p);\n" +
" }\n" +
"}\n" +
"\n" +
"class BX<Q> extends AX {\n" +
" void bar(Q q) { \n" +
" System.out.println(q);\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends AX> {\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 8)\n" +
" x.t.foo(\"SUCC\");\n" +
" ^^^^^^^^^^^^^^^\n" +
"Type safety: The method foo(Object) belongs to the raw type AX. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"3. ERROR in X.java (at line 9)\n" +
" x.t.bar(\"ESS\");\n" +
" ^^^\n" +
"The method bar(String) is undefined for the type capture#2-of ?\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303
public void test0103() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends AX> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<? extends BX> x = new X>(new BX());\n" +
" x.t.foo(\"SUCC\");\n" +
" x.t.bar(\"ESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" void foo(P p) { \n" +
" System.out.print(p);\n" +
" }\n" +
"}\n" +
"\n" +
"class BX<Q> extends AX {\n" +
" void bar(Q q) { \n" +
" System.out.println(q);\n" +
" }\n" +
"}\n",
},
"SUCCESS");
String expectedOutput =
" // Method descriptor #25 ([Ljava/lang/String;)V\n" +
" // Stack: 4, Locals: 2\n" +
" public static void main(java.lang.String[] args);\n" +
" 0 new X [1]\n" +
" 3 dup\n" +
" 4 new BX [26]\n" +
" 7 dup\n" +
" 8 invokespecial BX() [28]\n" +
" 11 invokespecial X(AX) [29]\n" +
" 14 astore_1 [x]\n" +
" 15 aload_1 [x]\n" +
" 16 getfield X.t : AX [16]\n" +
" 19 checkcast BX [26]\n" +
" 22 ldc <String \"SUCC\"> [31]\n" +
" 24 invokevirtual BX.foo(java.lang.Object) : void [33]\n" +
" 27 aload_1 [x]\n" +
" 28 getfield X.t : AX [16]\n" +
" 31 checkcast BX [26]\n" +
" 34 ldc <String \"ESS\"> [37]\n" +
" 36 invokevirtual BX.bar(java.lang.Object) : void [39]\n" +
" 39 return\n" +
" Line numbers:\n" +
" [pc: 0, line: 7]\n" +
" [pc: 15, line: 8]\n" +
" [pc: 27, line: 9]\n" +
" [pc: 39, line: 10]\n" +
" Local variable table:\n" +
" [pc: 0, pc: 40] local: args index: 0 type: java.lang.String[]\n" +
" [pc: 15, pc: 40] local: x index: 1 type: X\n" +
" Local variable type table:\n" +
" [pc: 15, pc: 40] local: x index: 1 type: X<? extends BX>\n";
try {
File f = new File(OUTPUT_DIR + File.separator + "X.class");
byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
int index = result.indexOf(expectedOutput);
if (index == -1 || expectedOutput.length() == 0) {
System.out.println(Util.displayString(result, 3));
}
if (index == -1) {
assertEquals("Wrong contents", expectedOutput, result);
}
} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
assertTrue(false);
} catch (IOException e) {
assertTrue(false);
}
}
// wildcard bound check
public void test0104() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends AX> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<? extends BX> x = new X>(new AX());\n" +
" x.t.foo(\"SUCC\");\n" +
" x.t.bar(\"ESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" void foo(P p) { \n" +
" System.out.print(p);\n" +
" }\n" +
"}\n" +
"\n" +
"class BX<Q> extends AX {\n" +
" void bar(Q q) { \n" +
" System.out.println(q);\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends AX> {\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"2. WARNING in X.java (at line 7)\n" +
" X<? extends BX> x = new X>(new AX());\n" +
" ^^\n" +
"BX is a raw type. References to generic type BX<Q> should be parameterized\n" +
"----------\n" +
"3. ERROR in X.java (at line 7)\n" +
" X<? extends BX> x = new X>(new AX());\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Type mismatch: cannot convert from X<AX to X\n" +
"----------\n" +
"4. WARNING in X.java (at line 8)\n" +
" x.t.foo(\"SUCC\");\n" +
" ^^^^^^^^^^^^^^^\n" +
"Type safety: The method foo(Object) belongs to the raw type AX. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"5. WARNING in X.java (at line 9)\n" +
" x.t.bar(\"ESS\");\n" +
" ^^^^^^^^^^^^^^\n" +
"Type safety: The method bar(Object) belongs to the raw type BX. References to generic type BX<Q> should be parameterized\n" +
"----------\n");
}
public void test0105() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends AX> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<? extends AX> x = new X>(new AX());\n" +
" x.t.foo(\"SUCCESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" void foo(P p) { \n" +
" System.out.println(p);\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0106() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends AX> {\n" +
" T t;\n" +
" X(T t){\n" +
" this.t = t;\n" +
" }\n" +
" public static void main(String[] args) {\n" +
" X<BX x = new X>(new BX());\n" +
" x.t.foo(\"SUCC\");\n" +
" x.t.bar(\"ESS\");\n" +
" }\n" +
"}\n" +
"\n" +
"class AX<P> {\n" +
" void foo(P p) { \n" +
" System.out.print(p);\n" +
" }\n" +
"}\n" +
"\n" +
"class BX<Q> extends AX {\n" +
" void bar(Q q) { \n" +
" System.out.println(q);\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
// unsafe assignment thru binaries
public void test0107() {
Map customOptions = getCompilerOptions();
this.runNegativeTest(
new String[] {
"X.java",
"import java.util.ArrayList;\n" +
"\n" +
"public class X {\n" +
" \n" +
" public static void main(String[] args) {\n" +
" \n" +
" Iterable<String> is = new ArrayList();\n" +
" is.iterator();\n" +
" }\n" +
"}\n" +
"\n",
},
"----------\n" +
"1. WARNING in X.java (at line 7)\n" +
" Iterable<String> is = new ArrayList();\n" +
" ^^^^^^^^^^^^^^^\n" +
"Type safety: The expression of type ArrayList needs unchecked conversion to conform to Iterable<String>\n" +
"----------\n" +
"2. WARNING in X.java (at line 7)\n" +
" Iterable<String> is = new ArrayList();\n" +
" ^^^^^^^^^\n" +
"ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" +
"----------\n",
null,
true,
customOptions);
}
// class literal: Integer.class of type Class<Integer>
public void test0108() {
// also ensure no unsafe type operation problem is issued (assignment to variable of type raw)
Map customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
" Class k;\n" +
" public static void main(String args[]) {\n" +
" new X().foo();\n" +
" }\n" +
" void foo() {\n" +
" Class c = this.getClass();\n" +
" this.k = this.getClass();\n" +
" this.k = Integer.class;\n" +
" try {\n" +
" Integer i = Integer.class.newInstance();\n" +
" } catch (Exception e) {\n" +
" }\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS",
null,
true,
null,
customOptions,
null/*no custom requestor*/);
}
// parameterized interface cannot be implemented simultaneously with distinct arguments
public void test0109() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X implements AX<String> {}\n" +
"class Y extends X implements AX<Thread> {}\n" +
"interface AX<P> {}\n" +
"\n",
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" class Y extends X implements AX<Thread> {}\n" +
" ^\n" +
"The interface AX cannot be implemented more than once with different arguments: AX<String> and AX\n" +
"----------\n");
}
public void test0110() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X implements AX {}\n" +
"class Y extends X implements AX<Thread> {}\n" +
"interface AX<P> {}\n" +
"\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X implements AX {}\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 2)\n" +
" class Y extends X implements AX<Thread> {}\n" +
" ^\n" +
"The interface AX cannot be implemented more than once with different arguments: AX and AX<Thread>\n" +
"----------\n");
}
public void test0111() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X implements AX<Object> {}\n" +
"class Y extends X implements AX {}\n" +
"interface AX<P> {}\n" +
"\n",
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" class Y extends X implements AX {}\n" +
" ^\n" +
"The interface AX cannot be implemented more than once with different arguments: AX<Object> and AX\n" +
"----------\n" +
"2. WARNING in X.java (at line 2)\n" +
" class Y extends X implements AX {}\n" +
" ^^\n" +
"AX is a raw type. References to generic type AX<P> should be parameterized\n" +
"----------\n");
}
// test member types
public void test0112() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends X.MMX>>{\n" +
" void foo(X<Thread>.MX.MMX mx) {}\n" +
" class MX <MT> {\n" +
" class MMX <MMT> {}\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"X.MX.MMX is a raw type. References to generic type X<T>.MX.MMX should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"3. ERROR in X.java (at line 2)\n" +
" void foo(X<Thread>.MX.MMX mx) {}\n" +
" ^^^^^^\n" +
"Bound mismatch: The type Thread is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"4. WARNING in X.java (at line 2)\n" +
" void foo(X<Thread>.MX.MMX mx) {}\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n");
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends X.MMX>>{\n" +
" class MX <MT extends Comparable> {\n" +
" class MMX <MMT> {}\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"X.MX.MMX is a raw type. References to generic type X<T>.MX.MMX should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"3. ERROR in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type Runnable is not a valid substitute for the bounded parameter <MT extends Comparable> of the type X.MX\n" +
"----------\n" +
"4. WARNING in X.java (at line 2)\n" +
" class MX <MT extends Comparable> {\n" +
" ^^^^^^^^^^\n" +
"Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n" +
"----------\n");
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends X.MMX>>{\n" +
" class MX <MT> {\n" +
" class MMX <MMT extends Comparable> {}\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"X.MX.MMX is a raw type. References to generic type X<T>.MX.MMX should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"3. ERROR in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type Iterable<String> is not a valid substitute for the bounded parameter of the type X.MX.MMX\n" +
"----------\n" +
"4. WARNING in X.java (at line 3)\n" +
" class MMX <MMT extends Comparable> {}\n" +
" ^^^^^^^^^^\n" +
"Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n" +
"----------\n");
}
public void test0113() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" class MX<U> {\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new X<Thread>().foo();\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" void foo() {\n" +
" new X<String>().new MX();\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0114() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" class MX<U> {\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new X<Thread>().foo(new X().new MX());\n" +
" }\n" +
" void foo(X<String>.MX mx) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0115() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" class MX<U> {\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new X<Thread>().foo(new X().new MX());\n" +
" }\n" +
" void foo(X.MX mx) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
public void test0116() {
this.runConformTest(
new String[] {
"X.java",
"public class X<T> {\n" +
" class MX<U> {\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new X<Thread>().foo(new X().new MX());\n" +
" }\n" +
" void foo(X<?>.MX mx) {\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n",
},
"SUCCESS");
}
// test member types
public void test0117() {
this.runNegativeTest(
new String[] {
"X.java",
"public class X <T extends X.MMX>>{\n" +
" public static void main(String [] args) {\n" +
" \n" +
" new X<X.MMX>>().new MX();\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" void foo(X<X.MX.MMX>.MX.MMX mx) {\n" +
" }\n" +
" \n" +
" class MX <MT> {\n" +
" class MMX <MMT> {\n" +
" }\n" +
" }\n" +
"}\n",
},
"----------\n" +
"1. WARNING in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"X.MX.MMX is a raw type. References to generic type X<T>.MX.MMX should be parameterized\n" +
"----------\n" +
"2. ERROR in X.java (at line 1)\n" +
" public class X <T extends X.MMX>>{\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"3. WARNING in X.java (at line 4)\n" +
" new X<X.MMX>>().new MX();\n" +
" ^^^^^^^^\n" +
"X.MX.MMX is a raw type. References to generic type X<T>.MX.MMX should be parameterized\n" +
"----------\n" +
"4. ERROR in X.java (at line 4)\n" +
" new X<X.MMX>>().new MX();\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"5. WARNING in X.java (at line 7)\n" +
" void foo(X<X.MX.MMX>.MX.MMX mx) {\n" +
" ^^^^^^^^\n" +
"X.MX.MMX is a raw type. References to generic type X<T>.MX.MMX should be parameterized\n" +
"----------\n" +
"6. ERROR in X.java (at line 7)\n" +
" void foo(X<X.MX.MMX>.MX.MMX mx) {\n" +
" ^^^^^^^^\n" +
"Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter <T extends X.MMX>> of the type X\n" +
"----------\n" +
"7. WARNING in X.java (at line 7)\n" +
" void foo(X<X.MX.MMX>.MX.MMX mx) {\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
"8. WARNING in X.java (at line 7)\n" +
" void foo(X<X.MX.MMX>.MX.MMX mx) {\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n");
}
// test generic method with recursive parameter bound <T extends Comparable
public void test0118() {
this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
" public static void main(String[] args) {\n" +
" java.util.Collections.sort(new java.util.LinkedList<String>());\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
"}\n"
},
"SUCCESS");
}
// test generic method
// **
public void test0118a() {
this.runConformTest(
new String[] {
"X.java",
"class A<T> {}\n" +
"\n" +
"public class X {\n" +
" static <T extends A void foo() {}\n" +
" void bar(A<?> a) {\n" +
" foo();\n" +
" }\n" +
"}"
},
"");
}
// test binary member types **
public void _test0119() {
this.runConformTest(
new String[] {
"X.java",
"public class X <T extends X.MMX>>{\n" +
" public static void main(String [] args) {\n" +
" \n" +
" new X<X.MMX>>().new MX();\n" +
" System.out.println(\"SUCCESS\");\n" +
" }\n" +
" void foo(X<X.MX.MMX>.MX