From 43d77a8e19cb2abb16878a382e8ca06fbf22dc47 Mon Sep 17 00:00:00 2001 From: Will Lauer Date: Mon, 7 Nov 2016 09:08:24 -0600 Subject: [PATCH] Adding unit test --- .../compiler/regression/GenericTypeTest.java | 92775 ++++++++-------- 1 file changed, 46394 insertions(+), 46381 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java index 41dee5d710..8fe793c954 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java @@ -1,46382 +1,46395 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.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 extends XS {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " Integer w = new X().get(new Integer(12));\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class XS {\n" + - " Txs get(Txs t) {\n" + - " return t;\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - - public void test0002() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends XS {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " Integer w = new X().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 {\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 extends X {\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X extends X {\n" + - " ^\n" + - "The type parameter X is hiding the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class 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 implements X {\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X implements X {\n" + - " ^\n" + - "The type parameter X is hiding the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class 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 {\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 {\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 {\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 {\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 {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Object.java (at line 2)\n" + - " public class Object {\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> {\n" + - " public static void main(String[] args) {\n" + - " new X();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " new X();\n" + - " ^^^\n" + - "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n"); - } - - public void test0011() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " public static void main(String[] args) {\n" + - " new X();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " new X();\n" + - " ^^^\n" + - "Foo cannot be resolved to a type\n" + - "----------\n"); - } - - public void test0012() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T foo(T t) {\n" + - " return t;\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " String s = new X().foo(\"SUCCESS\");\n" + - " System.out.println(s);\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - - public void test0013() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T foo(T t) {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().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 {\n" + - " T foo(T t) throws T {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().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 {\n" + - " String foo() throws T {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().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 {\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().bar(new Exception());\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0017() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.IOException;\n" + - "public class X {\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().bar(new Exception());\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " new X().bar(new Exception());\n" + - " ^^^\n" + - "The method bar(IOException) in the type X is not applicable for the arguments (Exception)\n" + - "----------\n"); - } - public void test0018() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T foo(T t) {\n" + - " System.out.println(t);\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X() {\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 {\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() {\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 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 {\n" + - " void foo(Y y) {\n" + - " System.out.print(\"SUCC\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().bar();\n" + - " }\n" + - " void bar() {\n" + - " new Y() {\n" + - " @Override\n" + - " public void pre() {\n" + - " foo(this);\n" + - " }\n" + - " }.print(\"ESS\");\n" + - " }\n" + - "}\n" + - "class Y

{\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 is not applicable for the arguments (String)\n" + - "----------\n"); - } - public void test0021() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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().foo(new Object());\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\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 is not applicable for the arguments (String)\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " new X().foo(new Object());\n" + - " ^^^\n" + - "The method foo(String) in the type X is not applicable for the arguments (Object)\n" + - "----------\n"); - } - - public void test0022() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " X(T t) {\n" + - " System.out.println(t);\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - - public void test0023() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - - public void test0024() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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(new EX());\n" + - " }\n" + - "}\n" + - "class EX extends Exception {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " new X(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 {\n" + - " String foo() throws T {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(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 {\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(new Exception());\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0027() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.IOException;\n" + - "public class X {\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(new Exception());\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " new X(new Exception());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X(Exception) is undefined\n" + - "----------\n"); - } - - public void test0028() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " String s = new X(\"SU\").t;\n" + - " System.out.print(s);\n" + - " s = new X(\"failed\").t = \"CC\";\n" + - " System.out.print(s);\n" + - " s = new X(\"\").t += \"ESS\";\n" + - " System.out.println(s);\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - - public void test0029() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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().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 {\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().foo(\"SUCCESS\"));\n" + - " }\n" + - "}\n" , - }, - "SUCCESS"); - } - - public void test0031() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new X(\"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 {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new X(\"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 {\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\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\n" + - "----------\n"); - } - - public void test0034() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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\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\n" + - "----------\n"); - } - - public void test0035() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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\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\n" + - "----------\n"); - } - - public void test0036() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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 {\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 {\n" + - " void foo(E e){}\n" + - " void foo(T t){}\n" + - " public static void main(String[] args) {\n" + - " X 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\n" + - "----------\n"); - } - - public void test0039() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(L l1){}\n" + - " void foo(L l2){}\n" + - " void foo(L l){}\n" + - "}\n" + - "\n" + - "class L {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " void foo(L l1){}\n" + - " ^^^^^^^^^^^^\n" + - "Method foo(L) 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 l2){}\n" + - " ^^^^^^^^^^^^\n" + - "Method foo(L) 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" + - "Method foo(L) has the same erasure foo(L) as another method in type X\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 should be parameterized\n" + - "----------\n"); - } - - public void test0040() { - this.runConformTest( - new String[] { - "X.java", - "public class 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 {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " } \n" + - "}\n", - }, - "SUCCESS"); - } - - // ** - public void test0042() { - String[] test = new String[] { - "X.java", - "public class X {}" - }; - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - test, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {}\n" + - " ^\n" + - "Illegal forward reference to type parameter U\n" + - "----------\n"); - } else { - this.runConformTest(test, ""); - } - } - - public void test0043() { - this.runConformTest( - new String[] { - "X.java", - "public class X , U extends T> {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class L{}\n", - }, - "SUCCESS"); - } - - public void test0044() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends L {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " } \n" + - "}\n" + - "class L {}\n", - }, - "SUCCESS"); - } - - public void test0045() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public Z var;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public Z var;\n" + - " ^\n" + - "Z cannot be resolved to a type\n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " public Z 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 var;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public Object var;\n" + - " ^^^^^^\n" + - "The type Object is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " public Object var;\n" + - " ^\n" + - "T cannot be resolved to a type\n" + - "----------\n"); - } - public void test0047() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " private T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new MX(\"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 {\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 as private thus non inherited) - public void test0048() { - this.runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " private T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new 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", - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. WARNING in X.java (at line 10)\n" + - " new X(this) {\n" + - " ^\n" + - "X is a raw type. References to generic type X 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 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", - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - public void test0049() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new 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 {\n" + - " static class N {}" + - "}\n" + - "class Y {\n" + - " static class N {}" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\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 extends Super {}\n" + - "class Y extends Super {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public class X extends Super {}\n" + - " ^\n" + - "M cannot be resolved to a type\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 implements Base {\n" + - " static class InnerTest implements Inner {}\n" + - "}\n"+ - "interface Base {\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 {}\n" + - "class Y extends X {\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 {}\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 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

{\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0053() { - this.runConformTest( - new String[] { - "X.java", - "public class X 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(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new 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

{\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 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(\"OUTER\").bar();\n" + - " }\n" + - " void bar() {\n" + - " new 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

{\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(this) {\n" + - " ^\n" + - "X is a raw type. References to generic type X 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 is not applicable for the arguments (T)\n" + - "----------\n"); - } - - public void test0055() { - this.runConformTest( - new String[] { - "X.java", - "public class X 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 xs = new X(\"SUCCESS\");\n" + - " System.out.println(xs.t);\n" + - " }\n" + - "}\n", - "p/A.java", - "package p; \n" + - "public class A

{\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 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 xs = new X(\"SUCCESS\");\n" + - " System.out.println((X)xs.t);\n" + - " }\n" + - "}\n", - "p/A.java", - "package p; \n" + - "public class A

{\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

\n" + - "----------\n"); - } - - public void test0057() { - this.runConformTest( - new String[] { - "X.java", - "public class X 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> 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

{\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 {\n" + - "}\n" + - "// Valid Type Syntax\n" + - "class Y {\n" + - " X 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 {\n" + - "}\n" + - "// Invalid Valid Type Syntax (not enough parameters)\n" + - "class Y {\n" + - " X x;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X.java (at line 7)\n" + - " X x;\n" + - " ^\n" + - "Incorrect number of arguments for type X; 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 {\n" + - "}\n" + - "// Invalid Valid Type Syntax (too many parameters)\n" + - "class Y {\n" + - " X x;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X.java (at line 7)\n" + - " X x;\n" + - " ^\n" + - "Incorrect number of arguments for type X; 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 {\n" + - "}\n" + - "// Invalid Valid Type Syntax (primitive cannot be parameters)\n" + - "class Y {\n" + - " X x;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X.java (at line 7)\n" + - " X 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 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 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 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 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 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 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 {\n" + - "}\n" + - "// Valid Type Syntax\n" + - "class Y {\n" + - " X x;\n" + - "}\n" - }, - "" - ); - } - public void test0063() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X 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 xs = new X(args);\n" + - " }\n" + - "}\n", - "p/A.java", - "package p; \n" + - "public class A

{\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 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 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 should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " X xs = new X(args);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X(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

\n" + - "----------\n"); - } - // raw type: variable map to its strict erasure - public void test0064() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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\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 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 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 {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " X xioe = new X(); // ok\n" + - " \n" + - " X x2 = xioe;\n" + - " X 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 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 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 should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 10)\n" + - " X xioe2 = x; // unsafe\n" + - " ^\n" + - "Type safety: The expression of type X needs unchecked conversion to conform to X\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> {\n" + - " A1 a1;\n" + - "}\n" + - "// Valid Parameterized Type Declaration\n" + - "class X2{\n" + - " A2 a2;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X1.java (at line 3)\n" + - " public class X1> {\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{\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 {\n" + - " A1 a1;\n" + - "}\n" + - "// Invalid Parameterized Type Declaration\n" + - "class X2 {\n" + - " ^^\n" + - "A2 cannot be resolved to a type\n" + - "----------\n" + - "2. ERROR in test\\X1.java (at line 3)\n" + - " public class X1 {\n" + - " ^\n" + - "Syntax error, insert \">\" to complete ReferenceType1\n" + - "----------\n" + - "3. ERROR in test\\X1.java (at line 7)\n" + - " class X2 expected after this token\n" + - "----------\n" - ); - } - - // JSR14-V10[2.4]: Not terminated consecutive declaration - public void test0069() { - this.runNegativeTest( - new String[] { - "test/X1.java", - "package test;\n" + - "// Invalid Consecutive Parameterized Type Declaration\n" + - "public class X1 {\n" + - " A2 a2;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X1.java (at line 3)\n" + - " public class X1>\" 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> {\n" + - " A1 a1;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X1.java (at line 3)\n" + - " public class X1> {\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>> {\n" + - " A1 a1;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X1.java (at line 3)\n" + - " public class X1>> {\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>> {\n" + - " A1 a1;\n" + - "}\n" + - "// Valid Parameterized Type Declaration\n" + - "class X2 {\n" + - " A2 a2;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test\\X1.java (at line 3)\n" + - " public class X1>> {\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 > 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

{\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 > extends p.A {\n" + - " ^^^\n" + - "The type A 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 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

{\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 extends p.A {\n" + - " ^^^\n" + - "A is a raw type. References to generic type A

should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X 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 extends p.A {\n" + - " X() {\n" + - " super(null);\n" + - " }\n"+ - " X(T t) {\n" + - " super(t);\n" + - " }\n" + - " X(X 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 xs = new X(args);\n" + - " }\n" + - "}\n", - "p/A.java", - "package p;\n" + - "public class A

{\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 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 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 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 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 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 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 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 should be parameterized\n" + - "----------\n" + - "10. ERROR in X.java (at line 15)\n" + - " X xs = new X(args);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X(String[]) is undefined\n" + - "----------\n"); - } - public void test0078() { - this.runNegativeTest( - new String[] { - "X.java", - "import p.A;\n" + - "public class X {\n" + - " X(A a, A b) {\n" + - " }\n" + - " void foo(A 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 as = new A(null);\n" + - " as.print(\"hello\");\n" + - " }\n" + - "}\n", - "p/A.java", - "package p;\n" + - "public class A

{\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

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\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

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\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

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

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

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

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\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 as = new A(null);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The constructor A(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 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

\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>>> {\n" + - " A a;\n" + - " public static void main(String[] args) {\n" + - " X>>> x = new X>>>();\n" + - " x.a = new X1>>();\n" + - " x.a.a1 = new X2>();\n" + - " x.a.a1.a2 = new X3();\n" + - " x.a.a1.a2.a3 = \"SUCCESS\";\n" + - " System.out.println(x.a.a1.a2.a3);\n" + - " }\n" + - "}\n" + - "class X1>> {\n" + - " A a1;\n" + - "}\n" + - "class X2> {\n" + - " A a2;\n" + - "}\n" + - "class X3 {\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>> {}\n" + - "class X1> {}\n" + - "class X2 {}\n" + - "class X3>> {}\n" + - " ^^^\n" + - "Syntax error, insert \">\" to complete ReferenceType1\n" + - "----------\n" + - "2. ERROR in test\\X.java (at line 3)\n" + - " class X1> {}\n" + - " ^^\n" + - "Syntax error, insert \">\" to complete ReferenceType1\n" + - "----------\n" + - "3. ERROR in test\\X.java (at line 4)\n" + - " class X2 {}\n" + - " ^\n" + - "Syntax error, insert \">\" to complete ReferenceType1\n" + - "----------\n" + - "4. ERROR in test\\X.java (at line 5)\n" + - " class X3 expected after this token\n" + - "----------\n" - ); - } - // TODO (david) remove errors: insert dimension to complete array type - public void test0081() { - this.runNegativeTest( - new String[] { - "test/X.java", - "package test;\n" + - "public class X> {}\n" + - "class X1 {}\n" + - "class X2 {}\n" - }, - "----------\n" + - "1. ERROR in test\\X.java (at line 2)\n" + - " public class X> {}\n" + - " ^^\n" + - "Syntax error, insert \">>\" to complete ReferenceType2\n" + - "----------\n" + - "2. ERROR in test\\X.java (at line 3)\n" + - " class X1 {}\n" + - " ^\n" + - "Syntax error, insert \">>\" to complete ReferenceType2\n" + - "----------\n" + - "3. ERROR in test\\X.java (at line 4)\n" + - " class X2>\" 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 {}\n" + - "class X1> {}\n" + - "class X3 {}\n" - }, - "----------\n" + - "1. ERROR in test\\X.java (at line 2)\n" + - " public class X {}\n" + - " ^\n" + - "Syntax error, insert \">>>\" to complete ReferenceType3\n" + - "----------\n" + - "2. ERROR in test\\X.java (at line 3)\n" + - " class X1>>\" 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>> {}\n" + - "class X2> {}\n" + - "class X3 {}\n" - }, - "----------\n" + - "1. ERROR in test\\X.java (at line 2)\n" + - " public class X>>\" to complete ReferenceType3\n" + - "----------\n" + - "2. ERROR in test\\X.java (at line 2)\n" + - " public class X\" to complete ReferenceType1\n" + - "----------\n"); - } - public void test0084() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " X(AX a, AX b) {\n" + - " }\n" + - " void foo(AX 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 as = new AX(null);\n" + - " as.print(a);\n" + - " as.bar(a);\n" + - " }\n" + - "}\n" + - "class AX

{\n" + - " AX(AX

ax){}\n" + - " AX(P p){}\n" + - " void print(P p){}\n" + - " void foo(AX rawAx){}\n" + - " void bar(AX

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\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

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\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

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

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

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

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

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

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

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

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\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

should be parameterized\n" + - "----------\n" + - "14. ERROR in X.java (at line 13)\n" + - " AX as = new AX(null);\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor AX(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 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\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

should be parameterized\n" + - "----------\n"); - } - - public void test0085() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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

{\n" + - " \n" + - " P p;\n" + - "}\n", - }, - "null"); - } - - public void test0086() { - Map customOptions = getCompilerOptions(); - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX ax2 = ax.p;\n" + - " ax.p = new AX();\n" + - " System.out.println(ax2);\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " AX

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

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

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

should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " ax.p = new AX();\n" + - " ^\n" + - "Type safety: The field p from the raw type AX is assigned a value of type AX. 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 {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX ax2 = ax.p;\n" + - " AX ax3 = new AX();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " AX

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 {\n" + - " AX ax = new AX();\n" + - " AX ax2 = ax.p;\n" + - " AX ax3 = new AX();\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " AX

p;\n" + - "}\n", - }, - "", - null, - true, - null, - customOptions, - null/*no custom requestor*/); - } - - public void test0089() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T q;\n" + - " public static void main(String[] args) {\n" + - " X xss = new X();\n" + - " 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 {\n" + - " T q;\n" + - " \n" + - " public static void main(String[] args) {\n" + - " X xss = new X();\n" + - " X> xxs = new X>();\n" + - " xxs.q = xss;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " void foo(X[] xs) {\n" + - " xs[0] = new X();\n" + - " }\n" + - "}\n", - }, - "SUCCESS", - null, - true, - null, - customOptions, - null/*no custom requestor*/); - } - - public void test0091() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(X[] xs) {\n" + - " }\n" + - "}\n", - }, - ""); - } - - public void test0092() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " void foo() {\n" + - " X xs = new X(\"\");\n" + - " X 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(\"SUCCESS\").foo();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " X xs2 = (X) xs;\n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X 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 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. 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 {\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

{\n" + - " AX

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 extends XS {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " I w = new X().get(new I());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class S {}\n" + - "class I implements C {}\n" + - "interface C {}\n" + - "class XS {\n" + - " Txs get(Txs t) {\n" + - " return t;\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0095() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends XS {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " I w = new X().get(new I());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class S {}\n" + - "class I implements C {}\n" + - "interface C {}\n" + - "class XS {\n" + - " Txs get(Txs t) {\n" + - " return t;\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0096() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends X {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends X {}\n" + - " ^\n" + - "Cycle detected: the type X 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 extends X {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends X {}\n" + - " ^\n" + - "Cycle detected: the type X 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 {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX ax2 = ax.p;\n" + - " ax.p = new AX();\n" + - " ax.q = new AX();\n" + - " ax.r = new AX();\n" + - " ax.s = new AX();\n" + - " System.out.println(ax2);\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " AX

p;\n" + - " AX q;\n" + - " AX r;\n" + - " BX s;\n" + - "}\n" + - "\n" + - "class BX {\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

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

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

should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 6)\n" + - " ax.p = new AX();\n" + - " ^\n" + - "Type safety: The field p from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 7)\n" + - " ax.q = new AX();\n" + - " ^\n" + - "Type safety: The field q from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 8)\n" + - " ax.r = new AX();\n" + - " ^\n" + - "Type safety: The field r from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + - "----------\n" + - "7. ERROR in X.java (at line 9)\n" + - " ax.s = new AX();\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from AX 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 > {\n" + - " public static void main(String[] args) {\n" + - " AX ax;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " void foo(X x) {\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X > {\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 {\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 AX());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " P foo() { return null; }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X x = new X(new AX());\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " X x = new X(new AX());\n" + - " ^\n" + - "Cannot instantiate the type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " X x = new X(new AX());\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

should be parameterized\n" + - "----------\n"); - } - - // wilcard may not pass parameter bound check - public void test0101() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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 AX());\n" + - " x.t.foo(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\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 {\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 x = new X>(new AX());\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends AX is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " X x = new X>(new AX());\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " X x = new X>(new AX());\n" + - " ^^\n" + - "Bound mismatch: The type AX 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

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 {\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

{\n" + - " void foo(P p) { \n" + - " System.out.print(p);\n" + - " }\n" + - "}\n" + - "\n" + - "class BX 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 {\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

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

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() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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

{\n" + - " void foo(P p) { \n" + - " System.out.print(p);\n" + - " }\n" + - "}\n" + - "\n" + - "class BX 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 [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 [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\n"; - - 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); - } - } - - // wildcard bound check - public void test0104() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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 AX());\n" + - " x.t.foo(\"SUCC\");\n" + - " x.t.bar(\"ESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " void foo(P p) { \n" + - " System.out.print(p);\n" + - " }\n" + - "}\n" + - "\n" + - "class BX 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 {\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " X x = new X>(new AX());\n" + - " ^^\n" + - "BX is a raw type. References to generic type BX should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " X x = new X>(new AX());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X> 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

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 should be parameterized\n" + - "----------\n"); - } - public void test0105() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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 AX());\n" + - " x.t.foo(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\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 {\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

{\n" + - " void foo(P p) { \n" + - " System.out.print(p);\n" + - " }\n" + - "}\n" + - "\n" + - "class BX 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 is = new ArrayList();\n" + - " is.iterator();\n" + - " }\n" + - "}\n" + - "\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " Iterable is = new ArrayList();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type ArrayList needs unchecked conversion to conform to Iterable\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " Iterable is = new ArrayList();\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n", - null, - true, - customOptions); - } - // class literal: Integer.class of type Class - 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 {}\n" + - "class Y extends X implements AX {}\n" + - "interface AX

{}\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 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 {}\n" + - "interface AX

{}\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

should be parameterized\n" + - "----------\n" + - "2. 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 and AX\n" + - "----------\n"); - } - public void test0111() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X implements AX {}\n" + - "class Y extends X implements AX {}\n" + - "interface AX

{}\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 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

should be parameterized\n" + - "----------\n"); - } - // test member types - public void test0112() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X .MX.MMX>>{\n" + - " void foo(X.MX.MMX mx) {}\n" + - " class MX {\n" + - " class MMX {}\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 2)\n" + - " void foo(X.MX.MMX mx) {}\n" + - " ^^^^^^\n" + - "Bound mismatch: The type Thread is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "4. WARNING in X.java (at line 2)\n" + - " void foo(X.MX.MMX mx) {}\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n"); - this.runNegativeTest( - new String[] { - "X.java", - "public class X .MX.MMX>>{\n" + - " class MX {\n" + - " class MMX {}\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type Runnable is not a valid substitute for the bounded parameter of the type X.MX\n" + - "----------\n" + - "4. WARNING in X.java (at line 2)\n" + - " class MX {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n"); - this.runNegativeTest( - new String[] { - "X.java", - "public class X .MX.MMX>>{\n" + - " class MX {\n" + - " class MMX {}\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type Iterable 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 {}\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n"); - } - public void test0113() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class MX {\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X().foo();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " void foo() {\n" + - " new X().new MX();\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0114() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class MX {\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X().foo(new X().new MX());\n" + - " }\n" + - " void foo(X.MX mx) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0115() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class MX {\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X().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 {\n" + - " class MX {\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X().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 .MX.MMX>>{\n" + - " public static void main(String [] args) {\n" + - " \n" + - " new X.MX.MMX>>().new MX();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " void foo(X.MX.MMX mx) {\n" + - " }\n" + - " \n" + - " class MX {\n" + - " class MMX {\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X .MX.MMX>>{\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " new X.MX.MMX>>().new MX();\n" + - " ^^^^^^^^\n" + - "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 4)\n" + - " new X.MX.MMX>>().new MX();\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "5. WARNING in X.java (at line 7)\n" + - " void foo(X.MX.MMX mx) {\n" + - " ^^^^^^^^\n" + - "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 7)\n" + - " void foo(X.MX.MMX mx) {\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + - "----------\n" + - "7. WARNING in X.java (at line 7)\n" + - " void foo(X.MX.MMX mx) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 7)\n" + - " void foo(X.MX.MMX mx) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n"); - } - // test generic method with recursive parameter bound > - 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());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // test generic method - public void test0118a() { - this.runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "class A {}\n" + - "\n" + - "public class X {\n" + - " static , U> void foo() {}\n" + - " void bar(A a) {\n" + - " foo();\n" + - " }\n" + - "}" - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); - } - // test binary member types ** - public void _test0119() { - this.runConformTest( - new String[] { - "X.java", - "public class X .MX.MMX>>{\n" + - " public static void main(String [] args) {\n" + - " \n" + - " new X.MX.MMX>>().new MX();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " void foo(X.MX.MMX mx) {\n" + - " }\n" + - " void foo2(X.MX.MMX mx) {\n" + - " }\n" + - " void foo3(X.MX.MMX>> mx) {\n" + - " }\n" + - " \n" + - " class MX {\n" + - " class MMX {\n" + - " }\n" + - " }\n" + - "}\n", - }, - "SUCCESS" - ); - - // TODO (philippe) bounds checks are done before binaryType X is finished creating its type variables - this.runConformTest( - new String[] { - "Y.java", - "public class Y extends X {\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS", - null, - false, // do not flush output - null); - } - // test generic method - public void test0120() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " \n" + - " String s = new X().foo(\"SUCCESS\");\n" + - " }\n" + - " T foo (U u) {\n" + - " System.out.println(u);\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // test generic method - public void test0120a() { - this.runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " > U foo() {\n" + - " return null;\n" + - " }\n" + - " > V bar() {\n" + - " return foo();\n" + - " }\n" + - "}" - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBug6302954 /* javac test options */); - } - // substitute array types - public void test0121() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new X().foo(args);\n" + - " }\n" + - " \n" + - " void foo(T[] ts) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // generic method with most specific common supertype: U --> String - public void test0122() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new X().foo(args, new X>());\n" + - " }\n" + - " void foo(U[] us, X> xxu) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // invalid parameterized type - public void test0123() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T ts;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " T ts;\n" + - " ^\n" + - "The type T is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - } - // generic method with indirect type inference: BX --> AX - public void test0124() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo(AX aw) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X().foo(new BX());\n" + - " }\n" + - "}\n" + - "\n" + - "class AX {\n" + - "}\n" + - "class BX extends AX {\n" + - "}\n", - }, - "SUCCESS"); - } - // generic method with indirect type inference: CX --> AX - public void test0125() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo(AX aw) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X().foo(new CX());\n" + - " }\n" + - "}\n" + - "\n" + - "class AX {\n" + - "}\n" + - "class BX extends AX {\n" + - "}\n" + - "class CX extends BX {\n" + - "}\n", - }, - "SUCCESS"); - } - // variation on test0125 with typo: CX extends B instead of BX. - public void test0126() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo(AX aw) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X().foo(new CX());\n" + - " }\n" + - "}\n" + - "\n" + - "class AX {\n" + - "}\n" + - "class BX extends AX {\n" + - "}\n" + - "class CX extends B {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo(new CX());\n" + - " ^^^\n" + - "The method foo(AX) in the type X is not applicable for the arguments (CX)\n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " class CX extends B {\n" + - " ^\n" + - "B cannot be resolved to a type\n" + - "----------\n"); - } - // 57784: test generic method - public void test0127() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " java.util.Arrays.asList(new Object[] {\"1\"});\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // 58666: special treatment for Object#getClass declared of type: Class - // but implicitly converted to Class for free. - public void test0128() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " Class c1 = x.getClass();\n" + - " Class c2 = x.getClass();\n" + - " String s = \"hello\";\n" + - " Class c3 = s.getClass();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Class c1 = x.getClass();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " Class c3 = s.getClass();\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n"); - } - // variation on test0128 - public void test0129() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - "\n" + - " public static void main(String[] args) {\n" + - " XY xy = new XY();\n" + - " Class c1 = xy.getClass();\n" + - " Class c2 = xy.getClass();\n" + - " String s = \"hello\";\n" + - " Class c3 = s.getClass();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "class XY extends X {\n" + - " public Class getClass() {\n" + - " return super.getClass();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " Class c1 = xy.getClass();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Class c3 = s.getClass();\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " public Class getClass() {\n" + - " ^^^^^^^^^^\n" + - "Cannot override the final method from Object\n" + - "----------\n" + - "4. WARNING in X.java (at line 14)\n" + - " public Class getClass() {\n" + - " ^^^^^^^^^^\n" + - "The method getClass() of type XY should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n"); - } - // getClass on array type - public void test0130() { - this.runConformTest( - new String[] { - "X.java", - "public class X { \n" + - "\n" + - " public static void main(String[] args) {\n" + - " X[] x = new X[0];\n" + - " Class c = x.getClass();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // 58979 - public void test0131() { - this.runNegativeTest( - new String[] { - "ArrayList.java", - " interface List {\n" + - " List foo();\n" + - "}\n" + - "\n" + - " class ArrayList implements List {\n" + - " public List foo() {\n" + - " List lt = this;\n" + - " lt.bar();\n" + - " return this;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in ArrayList.java (at line 8)\n" + - " lt.bar();\n" + - " ^^^\n" + - "The method bar() is undefined for the type List\n" + - "----------\n"); - } - public void test0132() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " .Z> foo() {}\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " .Z> foo() {}\n" + - " ^\n" + - "The type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " .Z> foo() {}\n" + - " ^\n" + - "W cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 2)\n" + - " .Z> foo() {}\n" + - " ^^^^^\n" + - "Return type for the method is missing\n" + - "----------\n"); - } - // bridge method - public void test0133() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new Y();\n" + - " System.out.println(x.foo());\n" + - " }\n" + - " T foo() {return null;}\n" + - " void foo(T t) {}\n" + - "}\n" + - "class Y extends X {\n" + - " String foo() {return \"SUCCESS\";}\n" + - " void foo(String s) {}\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0134() { - this.runConformTest( - new String[] { - "Z.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class Z { \n" + - " T t;\n" + - " public static void main(String[] args) {\n" + - " foo(new Z().set(new ArrayList()));\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " Z set(T t) {\n" + - " this.t = t;\n" + - " return this;\n" + - " }\n" + - " T get() { \n" + - " return this.t; \n" + - " }\n" + - " \n" + - " static void foo(Z za) {\n" + - " za.get().isEmpty();\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0135() { - this.runNegativeTest( - new String[] { - "Z.java", - "public class Z { \n" + - " public static void main(String[] args) {\n" + - " foo(new Z());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " static void foo(Z zs) {\n" + - " }\n" + - "}\n" + - "\n" + - "class ZA {\n" + - " void foo() {}\n" + - "}\n" + - "\n" + - "class ZB extends ZA {\n" + - "}" - }, - "----------\n" + - "1. ERROR in Z.java (at line 3)\n" + - " foo(new Z());\n" + - " ^^^\n" + - "The method foo(Z) in the type Z is not applicable for the arguments (Z)\n" + - "----------\n" + - "2. ERROR in Z.java (at line 6)\n" + - " static void foo(Z zs) {\n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super String is not a valid substitute for the bounded parameter of the type Z\n" + - "----------\n"); - } - public void test0136() { - this.runNegativeTest( - new String[] { - "Z.java", - "public class Z { \n" + - " public static void main(String[] args) {\n" + - " foo(new Z());\n" + - " }\n" + - " static void foo(Z zs) {\n" + - " zs.foo();\n" + - " }\n" + - "}\n" + - "class ZA {\n" + - "}\n" + - "class ZB extends ZA {\n" + - " void foo() {}\n" + - "}" - }, - "----------\n" + - "1. ERROR in Z.java (at line 3)\n" + - " foo(new Z());\n" + - " ^^^\n" + - "The method foo(Z) in the type Z is not applicable for the arguments (Z)\n" + - "----------\n" + - "2. ERROR in Z.java (at line 5)\n" + - " static void foo(Z zs) {\n" + - " ^^^^^^^^^^\n" + - "Bound mismatch: The type ? super ZA is not a valid substitute for the bounded parameter of the type Z\n" + - "----------\n" + - "3. ERROR in Z.java (at line 6)\n" + - " zs.foo();\n" + - " ^^^\n" + - "The method foo(Z) in the type Z is not applicable for the arguments ()\n" + - "----------\n"); - } - public void test0137() { - this.runConformTest( - new String[] { - "Z.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class Z { \n" + - " T t;\n" + - " public static void main(String[] args) {\n" + - " foo(new Z().set(new ArrayList()));\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " Z set(T t) {\n" + - " this.t = t;\n" + - " return this;\n" + - " }\n" + - " T get() { \n" + - " return this.t; \n" + - " }\n" + - " \n" + - " static void foo(Z za) {\n" + - " za.get().isEmpty();\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // unbound wildcard still remembers its variable bound: Z behaves like Z - public void test0138() { - this.runConformTest( - new String[] { - "Z.java", - "public class Z {\n" + - " T t;\n" + - " Z(T t){\n" + - " this.t = t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Z> zax = new Z>(new AX());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " void baz(Z zu){\n" + - " zu.t.foo(null);\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " void foo(P p) { \n" + - " System.out.print(p);\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // extending wildcard considers its bound prior to its corresponding variable - public void test0139() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " T get() {\n" + - " return this.t;\n" + - " }\n" + - " void bar(X x) {\n" + - " x.get().afoo();\n" + - " x.get().bfoo();\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " void afoo() {}\n" + - "}\n" + - "class BX {\n" + - " void bfoo() {}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " void bar(X x) {\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends BX is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " x.get().afoo();\n" + - " ^^^^\n" + - "The method afoo() is undefined for the type capture#1-of ? extends BX\n" + - "----------\n"); - } - // extending wildcard considers its bound prior to its corresponding variable - public void test0140() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " T get() {\n" + - " return this.t;\n" + - " }\n" + - " void bar(X x) {\n" + - " x.get().afoo();\n" + - " x.get().bfoo();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " void afoo() {}\n" + - "}\n" + - "class BX extends AX {\n" + - " void bfoo() {}\n" + - "}\n", - }, - "SUCCESS"); - } - // super wildcard considers its variable for lookups - public void test0141() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " T get() {\n" + - " return this.t;\n" + - " }\n" + - " void bar(X x) {\n" + - " x.get().afoo();\n" + - " x.get().bfoo();\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " void afoo() {}\n" + - "}\n" + - "class BX extends AX {\n" + - " void bfoo() {}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " x.get().bfoo();\n" + - " ^^^^\n" + - "The method bfoo() is undefined for the type capture#2-of ? super BX\n" + - "----------\n"); - } - public void test0142() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " T get() {\n" + - " return this.t;\n" + - " }\n" + - " void bar(X x) {\n" + - " x = identity(x);\n" + - " }\n" + - "

X

identity(X

x) {\n" + - " return x;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " void afoo() {}\n" + - "}\n" + - "class BX extends AX {\n" + - " void bfoo() {}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " void bar(X x) {\n" + - " ^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " void bar(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " x = identity(x);\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The generic method identity(X

) of type X is not applicable for the arguments (X). The inferred type capture#2-of ? extends X is not a valid substitute for the bounded parameter

\n" + - "----------\n"); - } - public void test0143() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class xx = null;\n" + - " Class xo = xx;\n" + - " Class xo2 = xx;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Class xo2 = xx;\n" + - " ^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n"); - } - public void test0144() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class xx = null;\n" + - " Class xo = xx;\n" + - " X x = get(xx);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " static

P get(Class

cp) {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // 59641: check assign/invoke with wildcards - public void test0145() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " XList lx = new XList();\n" + - " X x = lx.get();\n" + - " lx.add(null);\n" + - " lx.add(x);\n" + - " lx.slot = x;\n" + - " lx.addAll(lx);\n" + - " } \n" + - "}\n" + - "class XList {\n" + - " E slot;\n" + - " void add(E e) {}\n" + - " E get() { return null; \n" + - " }\n" + - " void addAll(XList le) {}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " lx.add(x);\n" + - " ^^^\n" + - "The method add(capture#3-of ?) in the type XList is not applicable for the arguments (X)\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " lx.slot = x;\n" + - " ^\n" + - "Type mismatch: cannot convert from X to capture#4-of ?\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " lx.addAll(lx);\n" + - " ^^^^^^\n" + - "The method addAll(XList) in the type XList is not applicable for the arguments (XList)\n" + - "----------\n"); - } - // 59628 - public void test0146() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.AbstractList;\n" + - "public class X extends AbstractList {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public int size() { return 0; }\n" + - " public Object get(int index) { return null; }\n" + - "}\n" - }, - "SUCCESS"); - } - // 59723 - public void test0147() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " char[][] tokens = new char[0][];\n" + - " ArrayList list = new ArrayList();\n" + - " list.toArray(tokens);\n" + - " System.out.println(\"SUCCESS\");\n" + - " } \n" + - "}\n" - }, - "SUCCESS"); - } - // bridge method - public void test0148() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends AX{\n" + - " \n" + - " String foo(String s) {\n" + - " System.out.println(s);\n" + - " return s;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().bar(\"SUCCESS\");\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " T foo(T t) {\n" + - " return null;\n" + - " }\n" + - " void bar(T t) {\n" + - " foo(t);\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // method compatibility - public void test0149() { - this.runConformTest( - new String[] { - "X.java", - "public abstract class X implements java.util.Collection {\n" + - " public Object[] toArray(Object[] a) {\n" + - " return a;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - this.runNegativeTest( - new String[] { - "X.java", - "public abstract class X implements java.util.Collection {\n" + - " public Object[] toArray(Object[] a) {\n" + - " return a;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " public Object[] toArray(Object[] a) {\n" + - " ^^^^^^^^\n" + - "Type safety: The return type Object[] for toArray(Object[]) from the type X needs unchecked conversion to conform to T[] from the type Collection\n" + - "----------\n"); - } - public void test0150() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " \n" + - " void foo(T[] ta, List lt) {\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X().foo(args, new ArrayList());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo(args, new ArrayList());\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo(T[], List) of type X is not applicable for the arguments (String[], ArrayList). The inferred type String is not a valid substitute for the bounded parameter \n" + - "----------\n"); - } - public void test0151() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " \n" + - " X(T[] ta, List lt) {\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X(args, new ArrayList());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " X(T[] ta, List lt) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " new X(args, new ArrayList());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The generic constructor X(T[], List) of type X is not applicable for the arguments (String[], ArrayList). The inferred type String is not a valid substitute for the bounded parameter \n" + - "----------\n"); - } - // 60556 - public void test0152() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " List x(List list) {\n" + - " return Collections.unmodifiableList(list);\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0153() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX a = bar(ax);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static AX bar(AX a) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0154() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX a = bar(ax);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static AX bar(AX a) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0155() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX a = bar(ax);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static AX bar(AX a) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0156() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX a = bar(ax);\n" + - " }\n" + - " public static AX bar(AX a) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " public static AX bar(AX a) {\n" + - " ^\n" + - "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type AX\n" + - "----------\n"); - } - public void test0157() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX as = new AX();\n" + - " AX a = bar(ax, as);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static AX bar(AX a, AX b) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " AX a = bar(ax, as);\n" + - " ^^^\n" + - "The method bar(AX, AX) in the type X is not applicable for the arguments (AX, AX)\n" + - "----------\n"); - } - public void test0158() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX as = new AX();\n" + - " AX a = bar(ax, as);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static AX bar(AX a, AX b) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0159() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX(new X());\n" + - " AX as = new AX(\"SUCCESS\");\n" + - " AX a = bar(ax, as);\n" + - " }\n" + - " public static T bar(AX a, AX b) {\n" + - " return a.get();\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? to T\n" + - "----------\n"); - } - public void test0160() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " String s = foo(new AX(\"aaa\"));\n" + - " }\n" + - " static V foo(AX a) {\n" + - " return a.get();\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from String to V\n" + - "----------\n"); - } - public void test0161() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " boolean b = foo(new AX(\"aaa\")).equals(args);\n" + - " }\n" + - " static V foo(AX a) {\n" + - " return a.get();\n" + - " }\n" + - " String bar() {\n" + - " return \"bbb\";\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from String to V\n" + - "----------\n"); - } - public void test0162() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " String s = foo(new AX(\"aaa\")).bar();\n" + - " }\n" + - " static V foo(AX a) {\n" + - " return a.get();\n" + - " }\n" + - " String bar() {\n" + - " return \"bbb\";\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " String s = foo(new AX(\"aaa\")).bar();\n" + - " ^^^\n" + - "The method bar() is undefined for the type Object\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from String to V\n" + - "----------\n"); - } - public void test0163() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " String s = foo(new AX(\"aaa\")).bar();\n" + - " }\n" + - " static V foo(AX a) {\n" + - " return a.get();\n" + - " }\n" + - " String bar() {\n" + - " return \"bbb\";\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " String s = foo(new AX(\"aaa\")).bar();\n" + - " ^^^\n" + - "The method bar() is undefined for the type Object\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from String to V\n" + - "----------\n"); - } - public void test0164() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " foo(new AX(\"SUCCESS\"));\n" + - " }\n" + - " static List foo(AX a) {\n" + - " System.out.println(a.get());\n" + - " List v = null;\n" + - " if (a == null) v = foo(a); \n" + - " return v;\n" + - " }\n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0165() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX();\n" + - " AX a = bar(ax);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static AX bar(AX a) {\n" + - " if (a == null) {\n" + - " AX as = bar(a);\n" + - " String s = as.get();\n" + - " }\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E get() { return null; }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0166() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX(new X());\n" + - " AX a = bar(ax, true);\n" + - " String s = a.get();\n" + - " System.out.println(s);\n" + - " }\n" + - " public static AX bar(AX a, boolean recurse) {\n" + - " if (recurse) {\n" + - " AX as = bar(a, false);\n" + - " String s = as.get();\n" + - " }\n" + - " return new AX(\"SUCCESS\");\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0167() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX a = bar();\n" + - " String s = a.get();\n" + - " System.out.println(s);\n" + - " }\n" + - " public static AX bar() {\n" + - " return new AX(\"SUCCESS\");\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0168() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX a = bar();\n" + - " String s = a.get();\n" + - " System.out.println(s);\n" + - " }\n" + - " public static AX, U> bar() {\n" + - " return new AX(\"SUCCESS\");\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " AX a = bar();\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from AX,Thread> to AX\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " return new AX(\"SUCCESS\");\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The constructor AX(Object) belongs to the raw type AX. References to generic type AX should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " return new AX(\"SUCCESS\");\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type AX needs unchecked conversion to conform to AX,U>\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " return new AX(\"SUCCESS\");\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX should be parameterized\n" + - "----------\n"); - } - public void test0169() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX a = bar(new X());\n" + - " String s = a.get();\n" + - " System.out.println(s);\n" + - " }\n" + - " public static AX bar(T t) {\n" + - " return new AX(\"SUCCESS\");\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " AX a = bar(new X());\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from AX to AX\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " return new AX(\"SUCCESS\");\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The constructor AX(Object) belongs to the raw type AX. References to generic type AX should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " return new AX(\"SUCCESS\");\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " return new AX(\"SUCCESS\");\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX should be parameterized\n" + - "----------\n"); - } - // Expected type inference for cast operation - public void test0170() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX(new X());\n" + - " AX as = new AX(\"\");\n" + - " ax = (AX)bar(ax);\n" + // shouldn't complain about unnecessary cast - " }\n" + - " public static T bar(AX a) {\n" + - " return a.get();\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " ax = (AX)bar(ax);\n" + - " ^^^^^^^^^^^\n" + - "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " ax = (AX)bar(ax);\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? to T\n" + - "----------\n"); - } - // Expected type inference for cast operation - public void test0171() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX(new X());\n" + - " AX as = new AX(\"\");\n" + - " ax = (AX)bar(ax);\n" + // shouldn't complain about unnecessary cast as return type inference do not - " }\n" + // work on cast conversion - " public static T bar(AX a) {\n" + - " return a.get();\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " ax = (AX)bar(ax);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to AX\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " return a.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? to T\n" + - "----------\n"); - } - // Expected type inference for cast operation - public void test0172() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " AX ax = new AX(new X());\n" + - " AX as = new AX(\"SUCCESS\");\n" + - " ax = (AX)bar(ax);\n" + // no warn for unsafe cast, since forbidden cast - " }\n" + - " public static String bar(AX a) {\n" + - " return null;\n" + - " } \n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " ax = (AX)bar(ax);\n" + - " ^^^^^^^^^^^^^^\n" + - "Cannot cast from String to AX\n" + - "----------\n"); - } - // Expected type inference for return statement - public void test0173() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " foo();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static T bar(AX a) {\n" + - " return null;\n" + - " } \n" + - " public static AX foo() {\n" + - " AX ax = new AX(new X());\n" + - " return bar(ax);\n" + // use return type of enclosing method for type inference - " }\n" + - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" + - "\n" - }, - "SUCCESS"); - } - // Expected type inference for field declaration - public void test0174() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " Object o = foo;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static T bar(AX a) {\n" + - " return null;\n" + - " } \n" + - " static AX foo = bar(new AX(new X()));\n" + // use field type for type inference - "}\n" + - "class AX {\n" + - " E e;\n" + - " AX(E e) { this.e = e; }\n" + - " E get() { return this.e; }\n" + - "}\n" + - "\n" - }, - "SUCCESS"); - } - // 60563 - public void test0175() { - this.runConformTest( - new String[] { - "X.java", - " interface A {\n" + - " T[] m1(T x); \n" + - " }\n" + - " public class X { \n" + - " public static void main(String[] args) {\n" + - " new X().m2(new A(){ \n" + - " public X[] m1(X x) { \n" + - " System.out.println(\"SUCCESS\");\n" + - " return null;\n" + - " }\n" + - " });\n" + - " }\n" + - " void m2(A x) { \n" + - " m3(x.m1(new X())); \n" + - " }\n" + - " void m3(X[] x) {\n" + - " } \n" + - " }\n" - }, - "SUCCESS"); - } - // unsafe raw return value - public void test0176() { - Map customOptions = getCompilerOptions(); - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Vector valuesOf(Hashtable h) {\n" + - " return new Vector();\n" + - " }\n" + - " Vector data;\n" + - " \n" + - " public void t() {\n" + - " Vector v = (Vector) data.elementAt(0);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " return new Vector();\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The expression of type Vector needs unchecked conversion to conform to Vector\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " return new Vector();\n" + - " ^^^^^^\n" + - "Vector is a raw type. References to generic type Vector should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " Vector v = (Vector) data.elementAt(0);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Vector\n" + - "----------\n", - null, - true, - customOptions); - } - // cast to type variable allowed, can be diagnosed as unnecessary - public void test0177() { - Map options = getCompilerOptions(); - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " \n" + - " T foo(T t) {\n" + - " return (T) t;\n" + - " }\n" + - "}\n", - }, - // compiler options - null /* no class libraries */, - options /* custom options - happen to be the default not changed by the test suite */, - // compiler results - "----------\n" + /* expected compiler log */ - "1. WARNING in X.java (at line 4)\n" + - " return (T) t;\n" + - " ^^^^^\n" + - "Unnecessary cast from T to T\n" + - "----------\n", - // runtime results - null /* do not check output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); - } - // reject instanceof type variable or parameterized type - public void test0178() { - Map customOptions = getCompilerOptions(); - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " T foo(T t) {\n" + - " if (t instanceof X) {\n" + - " return t;\n" + - " } else if (t instanceof X) {\n" + - " return t;\n" + - " } else if (t instanceof X) {\n" + // ok - " return t;\n" + - " } else if (t instanceof T) {\n" + - " return t;\n" + - " } else if (t instanceof X) {\n" + - " return t;\n" + - " }\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (t instanceof X) {\n" + - " ^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type X. Use instead its raw form X since generic type information will be erased at runtime\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " } else if (t instanceof X) {\n" + - " ^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type X. Use instead its raw form X since generic type information will be erased at runtime\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " } else if (t instanceof T) {\n" + - " ^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against type parameter T. Use instead its erasure Object since generic type information will be erased at runtime\n" + - "----------\n", - null, - true, - customOptions); - } - // 61507 - public void test0179() { - this.runConformTest( - new String[] { - "X.java", - "class U {\n" + - " static T notNull(T t) { return t; }\n" + - "}\n" + - "public class X {\n" + - " void t() {\n" + - " String s = U.notNull(null);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().t();\n" + - " System.out.println(\"SUCCESS\");\n" + - "}\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0180() { - this.runConformTest( - new String[] { - "X.java", - "class U {\n" + - " static T notNull(T t) { return t; }\n" + - "}\n" + - "public class X {\n" + - " void t() {\n" + - " String s = U.notNull(\"\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().t();\n" + - " System.out.println(\"SUCCESS\");\n" + - "}\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=61507 - variation computing most specific type with 'null' - public void test0181() { - this.runConformTest( - new String[] { - "X.java", - "class U {\n" + - " static T notNull(T t, V vt) { return t; }\n" + - "}\n" + - "class V {}\n" + - "\n" + - "public class X {\n" + - " void t() {\n" + - " String s = U.notNull(null, new V());\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().t();\n" + - " System.out.println(\"SUCCESS\");\n" + - "}\n" + - "}\n", - }, - "SUCCESS"); - } - public void test0182() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " X foo() {\n" + - " return (X) this;\n" + - " }\n" + - " X bar() {\n" + - " return (AX) new X();\n" + - " }\n" + - " X bar(Object o) {\n" + - " return (AX) o;\n" + - " }\n" + - " X foo(Object o) {\n" + - " return (AX) o;\n" + - " } \n" + - " X baz(Object o) {\n" + - " return (AX) null;\n" + - " }\n" + - " X baz2(BX bx) {\n" + - " return (X) bx;\n" + - " } \n" + - "}\n" + - "class AX extends X {}\n" + - "class BX extends AX {}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " return (X) this;\n" + - " ^^^^^^^^^^^\n" + - "Unnecessary cast from X to X\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " return (AX) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X to AX\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " return (AX) o;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to AX\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " return (AX) o;\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to AX\n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " return (AX) null;\n" + - " ^^^^^^^^^^^^\n" + - "Unnecessary cast from null to AX\n" + - "----------\n" + - "6. WARNING in X.java (at line 18)\n" + - " return (X) bx;\n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from BX to X\n" + - "----------\n"); - } - public void test0183() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " \n" + - " {\n" + - " Dictionary d;\n" + - " Object o;\n" + - " \n" + - " Object a1 = (Hashtable) d;\n" + - " Object a2 = (Hashtable) o;\n" + - "\n" + - " Object a3 = (Hashtable) d;\n" + - " Object a4 = (Hashtable) o;\n" + - " \n" + - " abstract class Z1 extends Hashtable {\n" + - " private static final long serialVersionUID = 1L;\n" + - " }\n" + - " Z1 z1;\n" + - " Object a5 = (Hashtable) z1;\n" + - "\n" + - " abstract class Z2 extends Z1 {\n" + - " private static final long serialVersionUID = 1L;\n" + - " }\n" + - " Object a6 = (Z2) z1;\n" + - "\n" + - " abstract class Z3 extends Hashtable {\n" + - " private static final long serialVersionUID = 1L;\n" + - " }\n" + - " Z3 z3;\n" + - " Object a7 = (Hashtable) z3;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Object a1 = (Hashtable) d;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Dictionary to Hashtable\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " Object a2 = (Hashtable) o;\n" + - " ^^^^^^^^^^^^^\n" + - "Unnecessary cast from Object to Hashtable\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " Object a2 = (Hashtable) o;\n" + - " ^^^^^^^^^\n" + - "Hashtable is a raw type. References to generic type Hashtable should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 12)\n" + - " Object a3 = (Hashtable) d;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Dictionary to Hashtable\n" + - "----------\n" + - "5. WARNING in X.java (at line 12)\n" + - " Object a3 = (Hashtable) d;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Dictionary to Hashtable\n" + - "----------\n" + - "6. WARNING in X.java (at line 13)\n" + - " Object a4 = (Hashtable) o;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Hashtable\n" + - "----------\n" + - "7. WARNING in X.java (at line 13)\n" + - " Object a4 = (Hashtable) o;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Object to Hashtable\n" + - "----------\n" + - "8. WARNING in X.java (at line 19)\n" + - " Object a5 = (Hashtable) z1;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Z1 to Hashtable\n" + - "----------\n" + - "9. WARNING in X.java (at line 24)\n" + - " Object a6 = (Z2) z1;\n" + - " ^^^^^^^\n" + - "Unnecessary cast from Z1 to Z2\n" + - "----------\n" + - "10. WARNING in X.java (at line 26)\n" + - " abstract class Z3 extends Hashtable {\n" + - " ^^^^^^^^^\n" + - "Hashtable is a raw type. References to generic type Hashtable should be parameterized\n" + - "----------\n" + - "11. WARNING in X.java (at line 30)\n" + - " Object a7 = (Hashtable) z3;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Z3 to Hashtable\n" + - "----------\n" + - "12. WARNING in X.java (at line 30)\n" + - " Object a7 = (Hashtable) z3;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Z3 to Hashtable\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62292 - parameterized message send - public void test0184() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " static T foo(T t, U u) {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(X.foo(\"SUCCESS\", null));\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // parameterized message send - variation on 184 with non-static generic method - public void test0185() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " T foo(T t, U u) {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // message send parameterized with type not matching parameter bounds - public void test0186() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " T foo(T t, U u) {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " T foo(T t, U u) {\n" + - " ^^^^^^\n" + - "The type parameter U 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" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo(T, U) of type X is not applicable for the arguments (String, null). The inferred type X is not a valid substitute for the bounded parameter \n" + - "----------\n"); - } - // invalid type argument arity for parameterized message send - public void test0187() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " T foo(T t, U u) {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " T foo(T t, U u) {\n" + - " ^^^^^^\n" + - "The type parameter U 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" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " ^^^\n" + - "Incorrect number of type arguments for generic method foo(T, U) of type X; it cannot be parameterized with arguments \n" + - "----------\n"); - } - // parameterized invocation of non generic method with incorrect argument count - public void test0188() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " void foo() {\n" + - " return;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " System.out.println(new X().foo(\"SUCCESS\", null));\n" + - " ^^^\n" + - "The method foo() in the type X is not applicable for the arguments (String, null)\n" + - "----------\n"); - } - // parameterized invocation of non generic method - public void test0189() { - String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 - ? "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " System.out.println(new X().foo());\n" + - " ^^^\n" + - "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n" - : "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " System.out.println(new X().foo());\n" + - " ^^^^^^^\n" + - "The method println(boolean) in the type PrintStream is not applicable for the arguments (void)\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " System.out.println(new X().foo());\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + - "----------\n"; - - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " void foo() {\n" + - " return;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(new X().foo());\n" + - " }\n" + - "}\n", - }, - expectedOutput); - } - // parameterized allocation - public void test0190() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // parameterized allocation - wrong arity - public void test0191() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"FAILED\");\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " new X(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Incorrect number of type arguments for generic constructor X(T) of type X; it cannot be parameterized with arguments \n" + - "----------\n"); - } - // parameterized allocation - non generic target constructor - // ** - public void test0192() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(String t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"FAILED\");\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " new X(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - return; - } - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(String t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(\"FAILED\");\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " new X(\"FAILED\");\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // parameterized allocation - argument type mismatch - public void test0193() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(new X(null));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " new X(new X(null));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The parameterized constructor X(String) of type X is not applicable for the arguments (X)\n" + - "----------\n"); - } - // parameterized invocation - argument type mismatch - public void test0194() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " void foo(T t) {\n" + - " return;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(new X().foo(new X()));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " System.out.println(new X().foo(new X()));\n" + - " ^^^\n" + - "The parameterized method foo(String) of type X is not applicable for the arguments (X)\n" + - "----------\n"); - } - // parameterized qualified allocation - public void test0195() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public class MX {\n" + - " public MX(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().new MX(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // parameterized qualified allocation - wrong arity - public void test0196() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public class MX {\n" + - " public MX(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().new MX(\"FAILED\");\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().new MX(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Incorrect number of type arguments for generic constructor MX(T) of type X.MX; it cannot be parameterized with arguments \n" + - "----------\n"); - } - // parameterized qualified allocation - non generic target constructor - // ** - public void test0197() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public class MX {\n" + - " public MX(String t){\n" + - " System.out.println(t);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().new MX(\"FAILED\");\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().new MX(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor MX(String) of type X.MX is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - return; - } - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public class MX {\n" + - " public MX(String t){\n" + - " System.out.println(t);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().new MX(\"FAILED\");\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " new X().new MX(\"FAILED\");\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor X.MX(String) of type X.MX; it should not be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // parameterized qualified allocation - argument type mismatch - public void test0198() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public class MX {\n" + - " public MX(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().new MX(new X());\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().new MX(new X());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The parameterized constructor MX(String) of type X.MX is not applicable for the arguments (X)\n" + - "----------\n"); - } - // parameterized explicit constructor call - public void test0199() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(\"SUCCESS\");\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // parameterized explicit constructor call - wrong arity - public void test0200() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(\"FAILED\");\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " super(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Incorrect number of type arguments for generic constructor X(T) of type X; it cannot be parameterized with arguments \n" + - "----------\n"); - } - // parameterized explicit constructor call - non generic target constructor - // ** - public void test0201() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(String t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(\"FAILED\");\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " super(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^\n" + - "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - return; - } - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(String t){\n" + - " System.out.println(t);\n" + - " Zork z;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(\"FAILED\");\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " super(\"FAILED\");\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + - "----------\n"); - } - // parameterized explicit constructor call - argument type mismatch - public void test0202() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(T t){\n" + - " System.out.println(t);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(new X(null));\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " }\n" + - "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " super(new X(null));\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The parameterized constructor X(String) of type X is not applicable for the arguments (X)\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62822 - supertypes partially resolved during bound check - public void test0203() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " demo.AD ad;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - "demo/AD.java", - "package demo;\n" + - "public interface AD extends LIST {}\n", - "demo/ADXP.java", - "package demo;\n" + - "public interface ADXP extends BIN {}\n", - "demo/ANY.java", - "package demo;\n" + - "public interface ANY {}\n", - "demo/BL.java", - "package demo;\n" + - "public interface BL extends ANY {}\n", - "demo/LIST.java", - "package demo;\n" + - "public interface LIST extends ANY {}\n", - "demo/BIN.java", - "package demo;\n" + - "public interface BIN extends LIST {}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62806 - public void test0204() { - this.runConformTest( - new String[] { - "Function.java", - "public abstract class Function {\n" + - " public abstract Y eval(X x);\n" + - "\n" + - "}\n", - "FunctionMappedComparator.java", - "import java.util.*;\n" + - "public class FunctionMappedComparator implements Comparator {\n" + - " /*\n" + - " * \'Function\' is highlighted as an error here - the message is:\n" + - " * The type Function is not generic; it cannot be parameterized with arguments \n" + - " */\n" + - " protected Function function;\n" + - " protected Comparator comparator;\n" + - " public FunctionMappedComparator(Function function,Comparator comparator ) {\n" + - " this.function=function;\n" + - " this.comparator=comparator;\n" + - " }\n" + - "\n" + - " public int compare(X x1, X x2) {\n" + - " return comparator.compare(function.eval(x1),function.eval(x2));\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63555 - reference to static type parameter allowed inside type itself - public void test0205() { - this.runConformTest( - new String[] { - "Alpha.java", - "public class Alpha {\n" + - " static class Beta {\n" + - " T obj;\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63555 - variation on static method type parameter - public void test0206() { - this.runConformTest( - new String[] { - "Alpha.java", - "public class Alpha {\n" + - " static void Beta(T t) {\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63590 - disallow parameterized type in catch/throws clause - public void test0207() { - this.runNegativeTest( - new String[] { - "Alpha.java", - "public class Alpha extends RuntimeException {\n" + - " public static void main(String[] args) {\n" + - " new Object() {\n" + - " public void m() throws Alpha {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }.m();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in Alpha.java (at line 1)\n" + - " public class Alpha extends RuntimeException {\n" + - " ^^^^^\n" + - "The serializable class Alpha does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. ERROR in Alpha.java (at line 1)\n" + - " public class Alpha extends RuntimeException {\n" + - " ^^^^^^^^^^^^^^^^\n" + - "The generic class Alpha may not subclass java.lang.Throwable\n" + - "----------\n" + - "3. ERROR in Alpha.java (at line 4)\n" + - " public void m() throws Alpha {\n" + - " ^^^^^\n" + - "Cannot use the parameterized type Alpha either in catch block or throws clause\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63590 - disallow parameterized type in catch/throws clause - public void test0208() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends RuntimeException {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " throw new X();\n" + - " } catch(X e) {\n" + - " System.out.println(\"X\");\n" + - " } catch(X> e) {\n" + - " System.out.println(\"X>\");\n" + - " } catch(RuntimeException e) {\n" + - " System.out.println(\"RuntimeException\");\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X extends RuntimeException {\n" + - " ^\n" + - "The serializable class X does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X extends RuntimeException {\n" + - " ^^^^^^^^^^^^^^^^\n" + - "The generic class X may not subclass java.lang.Throwable\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " } catch(X e) {\n" + - " ^\n" + - "Cannot use the parameterized type X either in catch block or throws clause\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " } catch(X> e) {\n" + - " ^\n" + - "Cannot use the parameterized type X> either in catch block or throws clause\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63556 - should resolve all occurrences of A to type variable - public void test0209() { - this.runConformTest( - new String[] { - "X.java", - "public class X> {}\n" + - "class X2, B> {}\n" + - "class X3> {}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68006 - Invalid modifier after parse - public void test0210() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(Map m){\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " void foo(Map m){\n" + - " ^^^\n" + - "Map cannot be resolved to a type\n" + - "----------\n"); - } - // test compilation against binaries - public void test0211() { - this.runConformTest( - new String[] { - "p/Top.java", - "package p;\n" + - "public interface Top {}\n", - }, - ""); - - this.runConformTest( - new String[] { - "p/Super.java", - "package p;\n" + - "public class Super implements Top{\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS", - null, - false, // do not flush output - null); - } - // check type variable equivalence - public void test0212() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X{\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " X _recurse; \n" + - " public List toList(){\n" + - " List result = new ArrayList();\n" + - " result.addAll(_recurse.toList()); // should be applicable\n" + - " return result;\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0213() { - this.runConformTest( - new String[] { - "X.java", - "public class X>{\n" + - " T test;\n" + - " public Comparable getThis(){\n" + - " return test;\n" + - " }\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68133 - verify error - public void test0214() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " ArrayList l;\n" + - " switch (args.length) {\n" + - " case 1:\n" + - " l = new ArrayList();\n" + - " System.out.println(l);\n" + - " break;\n" + - " default:\n" + - " System.out.println(\"SUCCESS\");\n" + - " return;\n" + - " }\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68133 variation - public void test0215() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " java.util.ArrayList i; \n" + - " outer: {\n" + - " if (args == null) {\n" + - " i = null;\n" + - " break outer;\n" + - " }\n" + - " return;\n" + - " }\n" + - " System.out.println(i); \n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - "}\n", - }, - ""); - - String expectedOutput = - " // Method descriptor #15 ([Ljava/lang/String;)V\n" + - " // Stack: 2, Locals: 2\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 aload_0 [args]\n" + - " 1 ifnonnull 9\n" + - " 4 aconst_null\n" + - " 5 astore_1 [i]\n" + - " 6 goto 10\n" + - " 9 return\n" + - " 10 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + - " 13 aload_1 [i]\n" + - " 14 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [22]\n" + - " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + - " 20 ldc [28]\n" + - " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + - " 25 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 5]\n" + - " [pc: 4, line: 6]\n" + - " [pc: 6, line: 7]\n" + - " [pc: 9, line: 9]\n" + - " [pc: 10, line: 11]\n" + - " [pc: 17, line: 12]\n" + - " [pc: 25, line: 13]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 26] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 6, pc: 9] local: i index: 1 type: java.util.ArrayList\n" + - " [pc: 10, pc: 26] local: i index: 1 type: java.util.ArrayList\n" + - " Local variable type table:\n" + - " [pc: 6, pc: 9] local: i index: 1 type: java.util.ArrayList\n" + - " [pc: 10, pc: 26] local: i index: 1 type: java.util.ArrayList\n"; - - 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); - } - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68998 parameterized field constants - public void test0216() { - this.runConformTest( - new String[] { - "test/cheetah/NG.java", - "package test.cheetah;\n" + - "public class NG extends G {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - " public boolean test() {\n" + - " return o == null;\n" + - " }\n" + - "}\n", - "test/cheetah/G.java", - "package test.cheetah;\n" + - "public class G {\n" + - " protected Object o;\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69135 - unnecessary cast operation - public void test0217() { - Map customOptions = getCompilerOptions(); - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.util.ArrayList;\n" + - "public class X {\n" + - " public static void main(String [] args) {\n" + - " ArrayList l= new ArrayList();\n" + - " String string = (String) l.get(0);\n" + - " }\n" + - "}\n", - }, - // compiler options - null /* no class libraries */, - customOptions /* custom options */, - // compiler results - "----------\n" + /* expected compiler log */ - "1. WARNING in X.java (at line 5)\n" + - " String string = (String) l.get(0);\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from String to String\n" + - "----------\n", - // runtime results - null /* do not check output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=64154 visibility issue due to invalid use of parameterized binding - public void test0218() { - this.runConformTest( - new String[] { - "X.java", - "public class X{\n" + - " private final T _data;\n" + - " private X(T data){\n" + - " _data = data;\n" + - " }\n" + - " public T getData(){\n" + - " return _data;\n" + - " }\n" + - " public static X create(E data) {\n" + - " return new X(data);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " create(new Object());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=64154 variation - public void test0219() { - this.runConformTest( - new String[] { - "X.java", - "public class X{\n" + - " private final T _data;\n" + - " private X(T data){\n" + - " _data = data;\n" + - " }\n" + - " public T getData(){\n" + - " return _data;\n" + - " }\n" + - " public static E create(E data) {\n" + - " return new X(data)._data;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " create(new Object());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141 unsafe wildcard operation tolerates wildcard with lower bounds - public void test0220() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "\n" + - "public class X {\n" + - " void foo() {\n" + - " ArrayList al = new ArrayList();\n" + - " al.add(new Integer(1)); // (1)\n" + - " Integer i = al.get(0); // (2)\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " Integer i = al.get(0); // (2)\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#2-of ? super Integer to Integer\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141 variation - public void test0221() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "\n" + - "public class X {\n" + - " void foo() {\n" + - " ArrayList al = new ArrayList();\n" + - " al.add(new Integer(1)); // (1)\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " al.add(new Integer(1)); // (1)\n" + - " ^^^\n" + - "The method add(capture#1-of ? extends Integer) in the type ArrayList is not applicable for the arguments (Integer)\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141: variation - public void test0222() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " XList lx = new XList();\n" + - " lx.slot = new Integer(1);\n" + - " Integer i = lx.slot;\n" + - " } \n" + - "}\n" + - "class XList {\n" + - " E slot;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Integer i = lx.slot;\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from capture#2-of ? super Integer to Integer\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69251- instantiating wildcards - public void test0223() { - Map customOptions = getCompilerOptions(); - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.HashMap;\n" + - "import java.util.Map;\n" + - "public class X {\n" + - " static final Map> classes \n" + - " = new HashMap>();\n" + - " \n" + - " static final Map> classes2 \n" + - " = new HashMap();\n" + - " \n" + - " class MX {\n" + - " E get() { return null; }\n" + - " void foo(E e) {}\n" + - " }\n" + - " \n" + - " void foo() {\n" + - " MX> mx1 = new MX>();\n" + - " MX mx2 = new MX();\n" + - " mx1.foo(mx2.get());\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " = new HashMap();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from HashMap to Map>\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " = new HashMap();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 17)\n" + - " MX mx2 = new MX();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 17)\n" + - " MX mx2 = new MX();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 18)\n" + - " mx1.foo(mx2.get());\n" + - " ^^^^^^^^^\n" + - "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + - "----------\n", - null, - true, - customOptions); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68998 variation - public void test0224() { - this.runNegativeTest( - new String[] { - "test/cheetah/NG.java", - "package test.cheetah;\n" + - "public class NG extends G {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - " public boolean test() {\n" + - " return o == null;\n" + - " }\n" + - "}\n", - "test/cheetah/G.java", - "package test.cheetah;\n" + - "public class G {\n" + - " protected final Object o;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in test\\cheetah\\NG.java (at line 2)\n" + - " public class NG extends G {\n" + - " ^\n" + - "G is a raw type. References to generic type G should be parameterized\n" + - "----------\n" + - "----------\n" + - "1. ERROR in test\\cheetah\\G.java (at line 2)\n" + - " public class G {\n" + - " ^\n" + - "The blank final field o may not have been initialized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69353 - prevent using type parameter in catch block - public void test0225() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " String foo() throws T {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().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 (T t) {\n" + - " }\n" + - " }\n" + - " }.print();\n" + - " }\n" + - "}\n" + - "class EX extends Exception {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " } catch (T t) {\n" + - " ^\n" + - "Cannot use the type parameter T in a catch block\n" + - "----------\n" + - "2. WARNING in X.java (at line 13)\n" + - " } catch (T t) {\n" + - " ^\n" + - "The parameter t is hiding another local variable defined in an enclosing type scope\n" + - "----------\n" + - "3. WARNING in X.java (at line 19)\n" + - " class EX extends Exception {\n" + - " ^^\n" + - "The serializable class EX does not declare a static final serialVersionUID field of type long\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69170 - invalid generic array creation - public void test0226() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X{\n" + - " Object x1= new T[0];\n" + - " Object x2= new X[0]; \n" + - " Object x3= new X[0]; \n" + - " Object x4= new X[0]; \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " Object x1= new T[0];\n" + - " ^^^^^^^^\n" + - "Cannot create a generic array of T\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " Object x2= new X[0]; \n" + - " ^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of X\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " Object x3= new X[0]; \n" + - " ^^^^^^^^^^^\n" + - "Cannot create a generic array of X\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69359 - unsafe cast diagnosis - public void test0227() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.*;\n" + - " public class X {\n" + - " List list() { return null; }\n" + - " void m() { List l = (List)list(); } // unsafe cast\n" + - " void m0() { List l = list(); } // unsafe conversion\n" + - " void m1() { for (X a : list()); } // type mismatch\n" + - " void m2() { for (Iterator i = list().iterator(); i.hasNext();); } // unsafe conversion\n" + - " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + - " void m4() { Collection c = null; List l = (List)c; } // ok\n" + - " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + - "}\n" , - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " List list() { return null; }\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " void m() { List l = (List)list(); } // unsafe cast\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " void m() { List l = (List)list(); } // unsafe cast\n" + - " ^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from List to List\n" + - "----------\n" + - "4. WARNING in X.java (at line 5)\n" + - " void m0() { List l = list(); } // unsafe conversion\n" + - " ^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 6)\n" + - " void m1() { for (X a : list()); } // type mismatch\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from element type Object to X\n" + - "----------\n" + - "6. WARNING in X.java (at line 7)\n" + - " void m2() { for (Iterator i = list().iterator(); i.hasNext();); } // unsafe conversion\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + - "----------\n" + - "7. WARNING in X.java (at line 8)\n" + - " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 8)\n" + - " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "9. WARNING in X.java (at line 8)\n" + - " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Collection to List\n" + - "----------\n" + - "10. WARNING in X.java (at line 9)\n" + - " void m4() { Collection c = null; List l = (List)c; } // ok\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "11. WARNING in X.java (at line 9)\n" + - " void m4() { Collection c = null; List l = (List)c; } // ok\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "12. WARNING in X.java (at line 10)\n" + - " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "13. WARNING in X.java (at line 10)\n" + - " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "14. WARNING in X.java (at line 10)\n" + - " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to Collection\n" + - "----------\n" + - "15. ERROR in X.java (at line 10)\n" + - " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Collection to List\n" + - "----------\n" + - "16. WARNING in X.java (at line 11)\n" + - " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "17. WARNING in X.java (at line 11)\n" + - " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "18. ERROR in X.java (at line 11)\n" + - " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Collection to List\n" + - "----------\n"); - } - // conversion from raw to X is safe (no unsafe warning) - public void test0228() { - this.runConformTest( - new String[] { - "X.java", - " import java.util.*;\n" + - " public class X {\n" + - " List list = new ArrayList();\n" + - " }\n", - }, - ""); - } - // can resolve member through type variable - public void test0229() { - runConformTest( - true, - new String[] { - "X.java", - " public class X {\n" + - " T.MXC f;\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " class XC {\n" + - " class MXC {}\n" + - " }\n", - }, - null, - "SUCCESS", - null, - JavacTestOptions.JavacHasABug.JavacBug6569404); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69375 - equivalence of wildcards - public void test0230() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void foo() {\n" + - " List li= null;\n" + - " List ln= null;\n" + - " ln = li;\n" + - " li= ln;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " li= ln;\n" + - " ^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69170 - variation - public void test0231() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X{\n" + - " Object x1= new X[0]; \n" + - " Object x2= new X[0]; \n" + - " Object x3= new X[0]; \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Object x2= new X[0]; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of X\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " Object x3= new X[0]; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of X\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - generic cast should be less strict - public void test0232() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " private T val;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(\"BAD\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont=new Container();\n" + - " cont.setVal(new Integer(0));\n" + - " badMethod(cont);\n" + - " Object someVal = cont.getVal(); // no cast \n" + - " System.out.println(cont.getVal()); // no cast \n" + - " }\n" + - "}\n", - }, - "BAD"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0233() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " private T val;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(new Long(0));\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont=new Container();\n" + - " cont.setVal(new Integer(0));\n" + - " badMethod(cont);\n" + - " Number someVal = cont.getVal();// only cast to Number \n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0234() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " public T val;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(\"BAD\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont=new Container();\n" + - " cont.setVal(new Integer(0));\n" + - " badMethod(cont);\n" + - " Object someVal = cont.val; // no cast \n" + - " System.out.println(cont.val); // no cast \n" + - " }\n" + - "}\n", - }, - "BAD"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0235() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " public T val;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(new Long(0));\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont=new Container();\n" + - " cont.setVal(new Integer(0));\n" + - " badMethod(cont);\n" + - " Number someVal = cont.val;// only cast to Number \n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0236() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " public T val;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(\"BAD\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont=new Container();\n" + - " cont.setVal(new Integer(0));\n" + - " badMethod(cont);\n" + - " Object someVal = (cont).val; // no cast \n" + - " System.out.println((cont).val); // no cast \n" + - " }\n" + - "}\n", - }, - "BAD"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0237() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " public T val;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(new Long(0));\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont=new Container();\n" + - " cont.setVal(new Integer(0));\n" + - " badMethod(cont);\n" + - " Number someVal = (cont).val;// only cast to Number \n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0238() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " public T val;\n" + - " Container next;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(\"BAD\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont = new Container();\n" + - " cont.next = new Container();\n" + - " cont.next.setVal(new Integer(0));\n" + - " badMethod(cont.next);\n" + - " Object someVal = cont.next.val; // no cast \n" + - " System.out.println(cont.next.val); // no cast \n" + - " }\n" + - "}\n", - }, - "BAD"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation - public void test0239() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Container{\n" + - " public T val;\n" + - " Container next;\n" + - " public T getVal() {\n" + - " return val;\n" + - " }\n" + - " public void setVal(T val) {\n" + - " this.val = val;\n" + - " }\n" + - " }\n" + - " public static void badMethod(Container param){\n" + - " Container x=param;\n" + - " x.setVal(new Long(0));\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Container cont = new Container();\n" + - " cont.next = new Container();\n" + - " cont.next.setVal(new Integer(0));\n" + - " badMethod(cont.next);\n" + - " Number someVal = cont.next.val;// only cast to Number \n" + - " System.out.println(\"SUCCESS\"); \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69713 NPE due to length pseudo field - public void test0240() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " String[] elements = null;\n" + - " \n" + - " public X() {\n" + - " String s = \"a, b, c, d\";\n" + - " elements = s.split(\",\");\n" + - " if(elements.length = 3) {\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " if(elements.length = 3) {\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from int to boolean\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69776 - missing checkcast on cast operation - public void test0241() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.HashMap;\n" + - "import java.util.Map;\n" + - "public class X {\n" + - " private static final Map classes = new HashMap();\n" + - " public static void main(String[] args) throws Exception {\n" + - " classes.put(\"test\", X.class);\n" + - " final Class clazz = (Class) classes.get(\"test\");\n" + - " Object o = clazz.newInstance();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // 69776 - variation - public void test0242() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.HashMap;\n" + - "import java.util.Map;\n" + - "public class X {\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " private static final Map classes = new HashMap();\n" + - " public static void main(String[] args) throws Exception {\n" + - " classes.put(\"test\", X.class);\n" + - " final Class clazz = (Class) classes.get(\"test\");\n" + - " final Class clazz2 = (Class) classes.get(\"test\");\n" + - " final Class clazz3 = (Class) classes.get(\"test\");\n" + - " Object o = clazz.newInstance();\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " final Class clazz = (Class) classes.get(\"test\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Class to Class\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " final Class clazz = (Class) classes.get(\"test\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Class to Class\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " final Class clazz2 = (Class) classes.get(\"test\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Class to Class\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " final Class clazz2 = (Class) classes.get(\"test\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Class to Class\n" + - "----------\n" + - "5. WARNING in X.java (at line 10)\n" + - " final Class clazz3 = (Class) classes.get(\"test\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Class to Class\n" + - "----------\n" + - "6. WARNING in X.java (at line 10)\n" + - " final Class clazz3 = (Class) classes.get(\"test\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Class to Class\n" + - "----------\n"); - } - public void test0243() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public X foo() {\n" + - " System.out.println(\"Did NOT add bridge method\");\n" + - " return this;\n" + - " }\n" + - " public static void main(String[] args) throws Exception {\n" + - " X x = new A();\n" + - " x.foo();\n" + - " System.out.print(\" + \");\n" + - " I i = new A();\n" + - " i.foo();\n" + - " }\n" + - "}\n" + - "interface I {\n" + - " public I foo();\n" + - "}\n" + - "class A extends X implements I {\n" + - " public A foo() {\n" + - " System.out.print(\"Added bridge method\");\n" + - " return this;\n" + - " }\n" + - "}\n" - }, - "Added bridge method + Added bridge method"); - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X foo() { return this; }\n" + - " public static void main(String[] args) throws Exception {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - "SubTypes.java", - "class A extends X {\n" + - " @Override public A foo() { return this; }\n" + - "}\n" + - "class B extends X {\n" + - " @Override public X foo() { return new X(); }\n" + - " @Override public B foo() { return this; }\n" + - "}\n" + - "class C extends A {\n" + - " @Override public X foo() { return new X(); }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in SubTypes.java (at line 5)\n" + - " @Override public X foo() { return new X(); }\n" + - " ^^^^^\n" + - "Duplicate method foo() in type B\n" + - "----------\n" + - "2. ERROR in SubTypes.java (at line 6)\n" + - " @Override public B foo() { return this; }\n" + - " ^^^^^\n" + - "Duplicate method foo() in type B\n" + - "----------\n" + - "3. ERROR in SubTypes.java (at line 9)\n" + - " @Override public X foo() { return new X(); }\n" + - " ^\n" + - "The return type is incompatible with A.foo()\n" + - "----------\n"); - } - // generic method of raw type - public void test0244() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " T foo(G g) {\n" + - " return null;\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " X rx = new X();\n" + - " rx.foo(\"hello\");\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X rx = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " X rx = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " rx.foo(\"hello\");\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n"); - } - // generic method of raw type - public void test0245() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " T foo(G g) {\n" + - " return null;\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " X rx = new X();\n" + - " rx.foo(\"hello\");\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X rx = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " X rx = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " rx.foo(\"hello\");\n" + - " ^^^\n" + - "The method foo(Object) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + - "----------\n", - JavacTestOptions.EclipseHasABug.EclipseBug236242); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 parameterized type compatibility - public void test0246() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " class MX {\n" + - " }\n" + - " void foo() {\n" + - " MX> mx2 = new MX();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " MX> mx2 = new MX();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.MX to X.MX>\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " MX> mx2 = new MX();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 variation - public void test0247() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " void foo() {\n" + - " MX> mx2 = new MX(); // wrong\n" + - " MX> mx3 = new MX>(); // wrong\n" + - " MX> mx4 = new MX>(); // wrong\n" + - " MX mx5 = new MX(); // ok\n" + - " MX mx6 = new MX(); // ok\n" + - " MX> mx7 = new MX>(); // wrong\n" + - " MX> mx8 = new MX>(); // wrong\n" + - " }\n" + - "}\n" + - "\n" + - "class MX {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " MX> mx2 = new MX(); // wrong\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from MX to MX>\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " MX> mx2 = new MX(); // wrong\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " MX> mx3 = new MX>(); // wrong\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " MX> mx4 = new MX>(); // wrong\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "5. WARNING in X.java (at line 6)\n" + - " MX mx5 = new MX(); // ok\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 6)\n" + - " MX mx5 = new MX(); // ok\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 7)\n" + - " MX mx6 = new MX(); // ok\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 7)\n" + - " MX mx6 = new MX(); // ok\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "9. WARNING in X.java (at line 8)\n" + - " MX> mx7 = new MX>(); // wrong\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "10. ERROR in X.java (at line 8)\n" + - " MX> mx7 = new MX>(); // wrong\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "11. WARNING in X.java (at line 8)\n" + - " MX> mx7 = new MX>(); // wrong\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "12. WARNING in X.java (at line 9)\n" + - " MX> mx8 = new MX>(); // wrong\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "13. ERROR in X.java (at line 9)\n" + - " MX> mx8 = new MX>(); // wrong\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "14. WARNING in X.java (at line 9)\n" + - " MX> mx8 = new MX>(); // wrong\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70247 check type variable is bound during super type resolution - public void test0248() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X extends Vector>{}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public class X extends Vector>{}\n" + - " ^^^^^^\n" + - "The type X cannot extend or implement Vector>. A supertype may not specify any wildcard\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70247 variation - public void test0249() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X implements List>{}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public class X implements List>{}\n" + - " ^^^^\n" + - "The type X cannot extend or implement List>. A supertype may not specify any wildcard\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70295 Class is compatible with Class - public void test0250() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void test(Object o) {\n" + - " X.class.isAssignableFrom(o.getClass());\n" + - " }\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69800 '? extends Object' is not compatible with A - public void test0251() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " static class A {\n" + - " }\n" + - " A test() throws Exception {\n" + - " Class clazz = null;\n" + - " return clazz.newInstance(); // ? extends Object\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " return clazz.newInstance(); // ? extends Object\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? extends Object to X.A\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69799 NPE in foreach checkcast - // effective result may change depending upon - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=148241 - // ** - public void test0252() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Set channel = channels.get(0);\n" + - " for (Iterator iter = channel.iterator(); iter.hasNext();) {\n" + - " Set element;\n" + - " element = (Set) iter.next();\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Set channel = channels.get(0);\n" + - " ^^^^^^^^\n" + - "channels cannot be resolved\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " element = (Set) iter.next();\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to Set\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70243 unsafe cast when wildcards - public void test0253() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List li= new ArrayList();\n" + - " List ls= li; \n" + - " List x2= (List)ls;//unsafe\n" + - " x2.add(new Float(1.0));\n" + - " \n" + - " Integer i= li.get(0);//ClassCastException!\n" + - " \n" + - " List ls2 = (List)ls;\n" + - " List ls3 = (List) li;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " List x2= (List)ls;//unsafe\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to List\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " List ls2 = (List)ls;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " List ls3 = (List) li;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from List to List\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70053 missing checkcast in string concatenation - public void test0254() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " System.out.print(\"S\" + x.a() + \"U\" + x.b().get(0) + \"C\" + x.a() + \"C\");\n" + - " System.out.println(new StringBuilder(\"E\").append(x.a()).append(\"S\").append(x.b().get(0)).append(\"S\").append(x.a()).append(\"!\")); \n" + - " }\n" + - " String a() { return \"\"; }\n" + - " List b() { \n" + - " ArrayList als = new ArrayList(1);\n" + - " als.add(a());\n" + - " return als;\n" + - " }\n" + - "}\n" - }, - "SUCCESS!"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69351 generic type cannot extend Throwable - public void test0255() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Throwable {\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X extends Throwable {\n" + - " ^\n" + - "The serializable class X does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X extends Throwable {\n" + - " ^^^^^^^^^\n" + - "The generic class X may not subclass java.lang.Throwable\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70616 - reference to binary Enum - public void test0256() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - "\n" + - " Enum ex = null;\n" + - " String s = ex.name();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Enum ex = null;\n" + - " ^\n" + - "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type Enum\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70618 - reference to variable allowed in parameterized super type - public void test0257() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public abstract class M extends java.util.AbstractList {}\n" + - "}\n" + - "class Y extends T {}\n" + - "class Z {\n" + - " class M extends T {}\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " class Y extends T {}\n" + - " ^\n" + - "Cannot refer to the type parameter T as a supertype\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " class M extends T {}\n" + - " ^\n" + - "Cannot refer to the type parameter T as a supertype\n" + - "----------\n"); - } - public void test0258() { - this.runConformTest( - new String[] { - "X.java", - "abstract class X implements java.util.Map {\n" + - " static abstract class M implements Entry {}\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70767 - NPE compiling code with explicit constructor invocation - public void test0259() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " X(E e) {\n" + - " this();\n" + - " }\n" + - " \n" + - " X() {\n" + - " }\n" + - "}\n" - }, - ""); - } - public void test0260() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class MX {\n" + - " }\n" + - "}\n" + - "\n" + - "class XC extends X {\n" + - " class MXC extends MX {\n" + - " }\n" + - "}\n" - }, - ""); - } - public void test0261() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(){\n" + - " X xi = (X) new X();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " X xi = (X) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n"); - } - public void test0262() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(){\n" + - " X xe = (X) new X();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " X xe = (X) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to X\n" + - "----------\n"); - } - public void test0263() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(){\n" + - " XC xe = (XC) new X();\n" + - " }\n" + - "}\n" + - "class XC extends X {\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " XC xe = (XC) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to XC\n" + - "----------\n"); - } - public void test0264() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(){\n" + - " XC xe = (XC) new X();\n" + - " }\n" + - "}\n" + - "class XC extends X {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " XC xe = (XC) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to XC\n" + - "----------\n"); - } - public void test0265() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(){\n" + - " XC xcu = (XC) new X();\n" + - " XC xcu1 = (XC) new X(); \n" + - " XC xcu2 = (XC) new X(); \n" + - " }\n" + - "}\n" + - "class XC extends X {\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " XC xcu = (XC) new X();\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to XC\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " XC xcu1 = (XC) new X(); \n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from XC to XC\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " XC xcu2 = (XC) new X(); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to XC\n" + - "----------\n" + - "4. WARNING in X.java (at line 5)\n" + - " XC xcu2 = (XC) new X(); \n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n"); - } - public void test0266() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void bar() {\n" + - " X xe = new X();\n" + - " }\n" + - "}\n" - }, - ""); - } - public void test0267() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static void foo(X xany) { \n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " foo(new X());\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0268() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "public class X {\n" + - " X[] foo() {\n" + - " ArrayList list = new ArrayList();\n" + - " return list.toArray(new X[list.size()]);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " X[] foo() {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " ArrayList list = new ArrayList();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " ArrayList list = new ArrayList();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type ArrayList needs unchecked conversion to conform to ArrayList\n" + - "----------\n" + - "4. WARNING in X.java (at line 4)\n" + - " ArrayList list = new ArrayList();\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70975 - test compilation against binary generic method - public void test0269() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " U[] bar(U[] u) { \n" + - " System.out.println(\"SUCCESS\");\n" + - " return null; }\n" + - "\n" + - " static String[] foo() {\n" + - " X xs = new X();\n" + - " return xs.bar(new String[0]);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " foo();\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - - this.runConformTest( - new String[] { - "Y.java", - "public class Y {\n" + - " public static void main(String [] args) {\n" + - " X xs = new X();\n" + - " String[] s = xs.bar(new String[0]);\n" + - " }\n" + - "}\n", - }, - "SUCCESS", - null, - false, // do not flush output - null); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70969 - lub(List, List) --> List - public void test0270() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "\n" + - "public class X {\n" + - " public void test(boolean param) {\n" + - " ArrayList ls = (param) \n" + - " ? new ArrayList()\n" + - " : new ArrayList();\n" + - " \n" + - " X x = param ? new XY() : new XZ();\n" + - " XY y = (XY) new XZ();\n" + - " }\n" + - "}\n" + - "class XY extends X {}\n" + - "class XZ extends X {}\n" - }, - - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " XY y = (XY) new XZ();\n" + - " ^^^^^^^^^^^^^\n" + - "Cannot cast from XZ to XY\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - parameter bound > should be allowed - public void test0271() { - this.runConformTest( - new String[] { - "X.java", - "public class X> {\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - variation - public void test0272() { - this.runConformTest( - new String[] { - "X.java", - "public class X> {\n" + - "}\n" + - "\n" + - "class XY implements Cloneable {\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - variation - public void test0273() { - this.runConformTest( - new String[] { - "X.java", - "public class X & Cloneable> {\n" + - "}\n" + - "\n" + - "class XY {\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - public void test0274() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " public List useList(List l) {\n" + - " l.add(\"asdf\");\n" + - " return l;\n" + - " }\n" + - "}\n" + - "class Y extends X {\n" + - " public List useList(List l) {\n" + - " l.add(\"asdf\");\n" + - " return l;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public List useList(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " public List useList(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " l.add(\"asdf\");\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " public List useList(List l) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method useList(List) of type Y has the same erasure as useList(List) of type X but does not override it\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation - public void test0275() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " public List useList(List l) {\n" + - " l.add(\"asdf\");\n" + - " return l;\n" + - " }\n" + - "}\n" + - "class Y extends X {\n" + - " public List useList(List l) {\n" + - " l.add(\"asdf\");\n" + - " return l;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " public List useList(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " public List useList(List l) {\n" + - " ^^^^\n" + - "Type safety: The return type List for useList(List) from the type Y needs unchecked conversion to conform to List from the type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " public List useList(List l) {\n" + - " ^^^^^^^^^^^^^^^\n" + - "The method useList(List) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " public List useList(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 10)\n" + - " l.add(\"asdf\");\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation - public void test0276() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " public void useList(List l) {}\n" + - "}\n" + - "class Y extends X {\n" + - " public void useList(List l) {\n" + - " super.useList(l);\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public void useList(List l) {}\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " public void useList(List l) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method useList(List) of type Y has the same erasure as useList(List) of type X but does not override it\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation - public void test0277() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " public void useList(List l) {}\n" + - "}\n" + - "class Y extends X {\n" + - " public void useList(List l) {\n" + - " super.useList(l);\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " public void useList(List l) {\n" + - " ^^^^^^^^^^^^^^^\n" + - "The method useList(List) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " public void useList(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " super.useList(l);\n" + - " ^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation - public void test0278() { - this.runConformTest( - new String[] { - "X.java", - "public class X implements I {\n" + - " public Class getDeclaringClass() { return null; }\n" + - "}\n" + - "class Y implements I {\n" + - " public Class getDeclaringClass() { return null; }\n" + - "}\n" + - "interface I {\n" + - " public Class getDeclaringClass();\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69901 - public void test0279() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X implements ISomething {\n" + - " public Class getSomething() { return null; }\n" + - "}\n" + - "class Y {}\n" + - "interface ISomething {\n" + - " public Class getSomething();\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " public Class getSomething() { return null; }\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " public Class getSomething() { return null; }\n" + - " ^^^^^\n" + - "Type safety: The return type Class for getSomething() from the type X needs unchecked conversion to conform to Class from the type ISomething\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62822 - public void test0280() { - this.runConformTest( - new String[] { - "X.java", - "interface X, T2 extends Z> {}\n" + - "interface Y {}\n" + - "interface Z {}\n" - }, - ""); - } - public void test0281() { - this.runNegativeTest( - new String[] { - "X.java", - "interface X, T2 extends Z> {}\n" + - "interface Y {}\n" + - "interface Z {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " interface X, T2 extends Z> {}\n" + - " ^^\n" + - "Bound mismatch: The type T2 is not a valid substitute for the bounded parameter of the type Y\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " interface Y {}\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n"); - } - public void test0282() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends Y.Member {}\n" + - "class Y { static class Member {} }\n" - }, - ""); - this.runConformTest( - new String[] { - "p1/X.java", - "package p1;\n" + - "public class X extends p1.Y.Member {}\n" + - "class Y { static class Member {} }\n" - }, - ""); - } - public void test0283() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y.Missing {}\n" + - "class Y { static class Member {} }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends Y.Missing {}\n" + - " ^^^^^^^^^\n" + - "Y.Missing cannot be resolved to a type\n" + - "----------\n"); - this.runNegativeTest( - new String[] { - "p1/X.java", - "package p1;\n" + - "public class X extends Y.Missing {}\n" + - "class Y { static class Member {} }\n" - }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 2)\n" + - " public class X extends Y.Missing {}\n" + - " ^^^^^^^^^\n" + - "Y.Missing cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72083 - public void test0284() { - this.runConformTest( - new String[] { - "p1/A.java", - "package p1;\n" + - "public class A , T2 extends B> {\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - "p1/B.java", - "package p1;\n" + - "public class B , T4 extends B> {}\n" - }, - "SUCCESS"); - this.runConformTest( - new String[] { - "p1/A.java", - "package p1;\n" + - "public class A , T2 extends A> {\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - "p1/B.java", - "package p1;\n" + - "public class B , T4 extends A> {}\n" - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73530 - public void test0285() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Vector;\n" + - "public class X {\n" + - " public static void main(String[] args){\n" + - " Vector v = new Vector();\n" + - " Integer[] array1 = new Integer[5];\n" + - " array1[0] = new Integer(17);\n" + - " array1[1] = new Integer(42);\n" + - " v.add(array1);\n" + - " Integer twentyfour = v.get(0)[1]; // responsible for the crash\n" + - " System.out.println(twentyfour);\n" + - " }\n" + - "}" - }, - "42"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72644 - // TODO (philippe) we need a way to test these 2 methods & find them 'equivalent'... right isEquivalentTo return false - public void test0286() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T foo(Class c) {return null;}\n" + - "}\n" + - "class Y extends X {\n" + - " T foo(Class c) {return null;}\n" + - "}" - }, - ""); - } - public void test0287() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public class A {\n" + - " \n" + - " public class B {\n" + - " \n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " X.A.B bs;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " X.A.B bs;\n" + - " ^^^^^\n" + - "The member type X.A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n"); - } - public void test0288() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public static class A {\n" + - " \n" + - " public static class B {\n" + - " \n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " X.A.B bs;\n" + - " }\n" + - "}\n" - }, - ""); - } - public void test0289() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public class A {\n" + - " \n" + - " public class B {\n" + - " \n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " X.A.B bs;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " X.A.B bs;\n" + - " ^^^^^^^^^^^^^\n" + - "The member type X.A must be parameterized, since it is qualified with a parameterized type\n" + - "----------\n"); - } - public void test0290() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public static class A {\n" + - " \n" + - " public class B {\n" + - " \n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " X.A.B bs;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " X.A.B bs;\n" + - " ^^^^^^^^^^^^^\n" + - "The member type X.A cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + - "----------\n"); - } - // ensure bound check deals with supertype (and their enclosing type) - public void test0291() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class MX {\n" + - " }\n" + - "}\n" + - "class SX extends X.MX {\n" + - " SX(X x){\n" + - " x.super();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^^^^\n" + - "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " class MX {\n" + - " ^^^^^^^^\n" + - "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " class SX extends X.MX {\n" + - " ^^^^^^\n" + - "Bound mismatch: The type Thread is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " class SX extends X.MX {\n" + - " ^^^^^^\n" + - "Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type X.MX\n" + - "----------\n" + - "5. WARNING in X.java (at line 6)\n" + - " SX(X x){\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n"); - } - public void test0292() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class Y {\n" + - " class Z {\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X.Y.Z zo;\n" + - " }\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73837 - public void test0293() { - this.runConformTest( - new String[] { - "B.java", //--------------------------- - "public class B{\n"+ - " public B(X str,D dValue){}\n"+ - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" , - "D.java", //--------------------------- - "public class D{}\n", - }, - "SUCCESS"); - - this.runConformTest( - new String[] { - "C.java", //--------------------------- - "public class C {\n" + - " public B test(Z zValue,D yValue){ return new B(zValue,yValue); }\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS", - null, - false, // do not flush output - null); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73837 variation - public void test0294() { - this.runConformTest( - new String[] { - "B.java", //--------------------------- - "public class B{\n"+ - " public B(X str, B dValue){}\n"+ - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" , - "D.java", //--------------------------- - "public class D{}\n", - }, - "SUCCESS"); - - this.runNegativeTest( - new String[] { - "C.java", //--------------------------- - "public class C {\n" + - " public B test(Z zValue,B> yValue){ return new B(zValue,yValue); }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in C.java (at line 2)\n" + - " public B test(Z zValue,B> yValue){ return new B(zValue,yValue); }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor B(Z, B>) is undefined\n" + - "----------\n", - null, - false, // do not flush output - null); - } - // non-static method #start() gets its type substituted when accessed through raw type - public void test0295() { - this.runNegativeTest( - new String[] { - "C.java", //--------------------------- - "public class C {\n" + - "\n" + - " void bar() {\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " }\n" + - "}\n", - "B.java", //--------------------------- - "public class B{\n" + - " X get(B bx) { return null; }\n" + - " B> start() { return null; }\n" + - "}", - "D.java", //--------------------------- - "public class D{}\n", - }, - "----------\n" + - "1. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method get(B) belongs to the raw type B. References to generic type B should be parameterized\n" + - "----------\n" + - "2. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "3. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "4. ERROR in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^^^\n" + - "The method get(B) is undefined for the type Object\n" + - "----------\n" + - "5. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "----------\n" + - "1. WARNING in B.java (at line 3)\n" + - " B> start() { return null; }\n" + - " ^\n" + - "D is a raw type. References to generic type D should be parameterized\n" + - "----------\n"); - } - // static method #start() gets its type does not get substituted when accessed through raw type - public void test0296() { - this.runNegativeTest( - new String[] { - "C.java", //--------------------------- - "public class C {\n" + - "\n" + - " void bar() {\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " }\n" + - "}\n", - "B.java", //--------------------------- - "public class B{\n" + - " X get(B bx) { return null; }\n" + - " static B> start() { return null; }\n" + - "}", - "D.java", //--------------------------- - "public class D{}\n", - }, - "----------\n" + - "1. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^^^^^^^^^^^^^^^\n" + - "The static method start() from the type B should be accessed in a static way\n" + - "----------\n" + - "2. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "3. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^^^^^^^^^^^^^^^\n" + - "The static method start() from the type B should be accessed in a static way\n" + - "----------\n" + - "4. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "5. ERROR in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^^^\n" + - "The method get(B) in the type B is not applicable for the arguments (B>)\n" + - "----------\n" + - "6. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^^^^^^^^^^^^^^^\n" + - "The static method start() from the type B should be accessed in a static way\n" + - "----------\n" + - "7. WARNING in C.java (at line 4)\n" + - " new B().start().get(new B().start()).get(new B().start());\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "----------\n" + - "1. WARNING in B.java (at line 3)\n" + - " static B> start() { return null; }\n" + - " ^\n" + - "D is a raw type. References to generic type D should be parameterized\n" + - "----------\n"); - } - public void test0297() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "import java.util.HashMap;\n" + - "import java.util.Iterator;\n" + - "import java.util.Map;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Map map = new HashMap();\n" + - " \n" + - " map.put(\"foo\", \"bar\");\n" + - " \n" + - " // Error reported on the following line\n" + - " Iterator> i = map.entrySet().iterator();\n" + - " while (i.hasNext()) {\n" + - " Map.Entry entry = i.next();\n" + - " System.out.println(entry.getKey() + \", \" + entry.getValue());\n" + - " }\n" + - " }\n" + - "}\n", - }, - "foo, bar"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72644 - public void test0298() { - this.runNegativeTest( - new String[] { - "X.java", //--------------------------- - "import java.util.Collection;\n" + - "import java.util.Map;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X implements Map {\n" + - " private Map backingMap;\n" + - " public int size() { return 0; }\n" + - " public boolean isEmpty() { return false; }\n" + - " public boolean containsKey(Object key) { return false; }\n" + - " public boolean containsValue(Object value) { return false; }\n" + - " public V get(Object key) { return null; }\n" + - " public V put(String key, V value) { return null; }\n" + - " public V remove(Object key) { return null; }\n" + - " public void clear() { }\n" + - " public Set keySet() { return null; }\n" + - " public Collection values() { return null; }\n" + - " public void putAll(Map t) { }\n" + - " public Set> entrySet() {\n" + - " return this.backingMap.entrySet();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " public class X implements Map {\n" + - " ^\n" + - "The type X must implement the inherited abstract method Map.putAll(Map)\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " public void putAll(Map t) { }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method putAll(Map) of type X has the same erasure as putAll(Map) of type Map but does not override it\n" + - "----------\n"); - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public abstract class X implements java.util.Map {\n" + - " public void putAll(java.util.Map t) { }\n" + - "}\n", - }, - ""); - this.runNegativeTest( - new String[] { - "X.java", //--------------------------- - "public abstract class X implements java.util.Map {\n" + - " public void putAll(java.util.Map t) { }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public void putAll(java.util.Map t) { }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method putAll(Map) of type X has the same erasure as putAll(Map) of type Map but does not override it\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74244 - public void test0299() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " System.out.println(Boolean.class == boolean.class ? \"FAILED\" : \"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74119 - public void test0300() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public class X {\n" + - " static interface I extends Visitible {\n" + - " }\n" + - " static interface Visitible {\n" + - " void acceptVisitor(Visitor visitor);\n" + - " }\n" + - " static interface Visitor {\n" + - " void visit(T t);\n" + - " }\n" + - " static class C implements I {\n" + - " public void acceptVisitor(Visitor visitor) {\n" + - " visitor.visit(this); // should be ok\n" + - " visitor.visit((I) this); // (2) This is a workaround\n" + - " }\n" + - " }\n" + - " public static void main(String [] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74320: check no complaint for unused private method - public void test0301() { - this.runNegativeTest( - new String[] { - "X.java", //--------------------------- - "import java.util.List;\n" + - "public class X {\n" + - " public static void reverse(List list) { \n" + - " rev(list);\n" + - " }\n" + - " private static void rev(List list) {\n" + - " }\n" + - " Zork foo() {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " Zork foo() {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74514 - public void test0302() { - this.runNegativeTest( - new String[] { - "X.java", //--------------------------- - "import java.util.ArrayList;\n" + - "import java.util.Enumeration;\n" + - "import java.util.Iterator;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " public void test02() {\n" + - " List l= new ArrayList();\n" + - " for (Iterator i= l.iterator(); i.next(); ) {\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " for (Iterator i= l.iterator(); i.next(); ) {\n" + - " ^^^^^^^^\n" + - "Type mismatch: cannot convert from String to boolean\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74544 - public void test0303() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Y ys = new Y();\n" + - " Y.Member m = ys.new Member();\n" + - " m.foo();\n" + - " } \n" + - " }\n" + - " class Y {\n" + - " class Member {\n" + - " void foo(){\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " }\n" + - "\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74592 - public void test0304() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public class X {}\n" + - "class Y extends X {}" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74420 - public void test0305() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public class X {\n" + - " T x;\n" + - " T foo(U u) { return u; }\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74096 - public void test0306() { - this.runNegativeTest( - new String[] { - "X.java", //--------------------------- - "public class X> {\n" + - " static int CONSTANT = 1;\n" + - " private int i = 1;\n" + - " private int i() {return i;}\n" + - " private static class M { private static int j = 2; }\n" + - " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + - " public int foo2(T t) { return T.CONSTANT; }\n" + // why is this allowed? - "}\n" + - "class Y extends Zork {\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + - " ^^^^^\n" + - "Read access to enclosing field X.M.j is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " class Y extends Zork {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" - // 5: operator + cannot be applied to int,.j - // 5: incompatible type, found : , required: int - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72583 - public void test0307() { - this.runConformTest( - new String[] { - "X.java", //--------------------------- - "public class X {\n" + - " static T foo(T t1, T t2){ return t1; }\n" + - " public static void main(String[] args) {\n" + - " IX s = null;\n" + - " foo(new Object(), s);\n" + - " }\n" + - "}\n" + - "interface IX {}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73696 - public void test0308() { - this.runConformTest( - new String[] { - "p/X.java", - "package p;\n" + - "public class X {\n" + - " class Member {}\n" + - "}\n", - "p/Y.java", - "package p;\n" + - "public class Y {\n" + - " p.X.Member m;\n" + - " p.X.Member ms = m;\n" + - "}\n" - }); - } - public void test0309() { - this.runConformTest( - new String[] { - "p/X.java", - "package p;\n" + - "public class X {\n" + - " class Member {\n" + - " class Sub {}\n" + - " }\n" + - "}\n", - "p/Y.java", - "package p;\n" + - "public class Y {\n" + - " p.X.Member.Sub s;\n" + - " p.X.Member.Sub es = s;\n" + - "}\n" - }); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75156 - should report name clash - public void test0310() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X extends X2 {\n" + - " void foo(List lx) { }\n" + - "}\n" + - "\n" + - "abstract class X2 {\n" + - " void foo(List lo) { }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " void foo(List lx) { }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75156 variation - should report name clash and ambiguity - public void test0311() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X extends X2 {\n" + - " void foo(List lx) { }\n" + - " void bar(){\n" + - " this.foo((List)null);\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class X2 {\n" + - " void foo(List lo) { }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " void foo(List lx) { }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " this.foo((List)null);\n" + - " ^^^\n" + - "The method foo(List) is ambiguous for the type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " this.foo((List)null);\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n"); - } - // 75156 variation - should report name clash instead of final method override - public void test0312() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X extends X2 {\n" + - " void foo(List lx) { }\n" + - "}\n" + - "\n" + - "abstract class X2 {\n" + - " final void foo(List lo) { }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " void foo(List lx) { }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73963 - public void test0313() { - this.runConformTest( - new String[] { - "X.java", - "import java.net.Inet6Address;\n" + - "import java.net.InetAddress;\n" + - "import java.util.AbstractList;\n" + - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "void takeAbstract(AbstractList arg) { }\n" + - "\n" + - "void takeList(List arg) { }\n" + - "\n" + - "void construct() {\n" + - " AbstractList a= new ArrayList();\n" + - " takeAbstract(a);\n" + - " takeAbstract(new ArrayList()); // a inlined: error 1:\n" + - "//The method takeAbstract(AbstractList) in the type A\n" + - "// is not applicable for the arguments (ArrayList)\n" + - " \n" + - " List l= new ArrayList();\n" + - " takeList(l);\n" + - " takeList(new ArrayList()); // l inlined: ok\n" + - " \n" + - " ArrayList aw= new ArrayList();\n" + - " takeAbstract(aw);\n" + - " takeAbstract(new ArrayList()); // aw inlined: error 2:\n" + - "//The method takeAbstract(AbstractList) in the type A\n" + - "// is not applicable for the arguments (ArrayList)\n" + - "\n" + - " takeList(aw);\n" + - " takeList(new ArrayList()); //aw inlined: ok\n" + - "}\n" + - "}" - }, - ""); - } - public void test0314() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class XMember {}\n" + - "\n" + - " // with toplevel element type\n" + - " void foo() {\n" + - " XIter> iter = fooSet().iterator();\n" + - " }\n" + - " XSet> fooSet() { return null; }\n" + - "\n" + - " // with member element type\n" + - " void bar() {\n" + - " XIter> iter = barSet().iterator();\n" + - " }\n" + - " XSet> barSet() { return null; }\n" + - "\n" + - " \n" + - "}\n" + - "\n" + - "class XSet {\n" + - " XIter iterator() { return null; }\n" + - "}\n" + - "class XIter {\n" + - "}\n" + - "class XElement {\n" + - "}\n" - }, - ""); - } - public void test0315() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class XMember {}\n" + - "\n" + - " // with member element type\n" + - " void bar() {\n" + - " XIter> iter = barSet().iterator();\n" + - " }\n" + - " XSet> barSet() { return null; }\n" + - "\n" + - " \n" + - "}\n" + - "\n" + - "class XSet {\n" + - " XIter iterator() { return null; }\n" + - "}\n" + - "class XIter {\n" + - "}\n" + - "class XElement {\n" + - "}\n" - }, - ""); - } - public void test0316() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " \n" + - " E element() { return null; }\n" + - " \n" + - " void bar(X xe) {\n" + - " xe.element().add(this);\n" + - " xe.element().run();\n" + - " }\n" + - " void foo(X xe) {\n" + - " xe.element().add(this);\n" + - " xe.element().run();\n" + - " }\n" + - " void baz(X xe) {\n" + - " xe.element().add(this);\n" + - " xe.element().run();\n" + - " }\n" + - " abstract class XM implements List, Runnable {}\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public class X {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " xe.element().add(this);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " xe.element().add(this);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 16)\n" + - " xe.element().add(this);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 19)\n" + - " abstract class XM implements List, Runnable {}\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 20)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0317() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " \n" + - " E element() { return null; }\n" + - " \n" + - " void foo(X xe) {\n" + - " xe.element().add(this);\n" + - " xe.element().run();\n" + - " }\n" + - " void baz(X xe) {\n" + - " xe.element().add(this);\n" + - " xe.element().run();\n" + - " }\n" + - " interface XI extends Runnable {}\n" + - " \n" + - " class XM {\n" + - " void foo() {}\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public class X {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " xe.element().add(this);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " xe.element().add(this);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 20)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75548 - public void test0318() { - this.runConformTest( - new String[] { - "MyCache.java", - "class Cache {\n" + - "}\n" + - "\n" + - "class Index {\n" + - " public Index(Cache parentCache) {\n" + - " }\n" + - "}\n" + - "\n" + - "public class MyCache extends Cache {\n" + - " class AnIndex extends Index {\n" + - " public AnIndex() {\n" + - " super(MyCache.this); // <-- Eclipse cannot find the constructor!\n" + - " }\n" + - " }\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76729 - public void test0319() { - this.runConformTest( - new String[] { - "test/Test1.java", - "package test;\n" + - "\n" + - "class A\n" + - "{}\n" + - "\n" + - "class B\n" + - "{}\n" + - "\n" + - "public interface Test1, D extends A>\n" + - "{}\n" + - "\n" + - "class AbstractA extends A {};\n" + - "class AbstractB extends B {};\n" + - "\n" + - "class Test2 implements Test1\n" + - "{}" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74032 - public void test0320() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "class TestElement extends ArrayList implements Runnable {\n" + - " public void run() {\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public X(E element) {\n" + - " element.run();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(new TestElement());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74032 - variation with wildcard - public void test0321() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "class TestElement extends ArrayList implements Runnable {\n" + - " static final long serialVersionUID = 1l;\n" + - " public void run() {\n" + - " // empty\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " E element;\n" + - " public X(E element) {\n" + - " this.element = element;\n" + - " element.run();\n" + - " }\n" + - " public X(X x) {\n" + - " x.element.run();\n" + // should be able to bind to #run() - " }\n" + - " public static void main(String[] args) {\n" + - " new X(new TestElement());\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75134 - public void test0322() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - "\n" + - " A v2;\n" + - " X(A a) { v2 = a; }\n" + - " \n" + - " void func() {\n" + - " List> l = new ArrayList>();\n" + - " }\n" + - "\n" + - " class B {\n" + - " T v1;\n" + - " B(T b) { v1 = b; }\n" + - " }\n" + - " \n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76359 - also check warnings for raw conversion - public void test0323() { - this.runNegativeTest( - new String[] { - "X.java", - "class G {\n" + - " class Member {}\n" + - "}\n" + - "public class X {\n" + - " G g = new G();\n" + - " G.Member gsm = g.new Member();\n" + - " G.Member gm = null;\n" + - " G.Member gtm = gm;\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " G g = new G();\n" + - " ^^^^^^^\n" + - "Type safety: The expression of type G needs unchecked conversion to conform to G\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " G g = new G();\n" + - " ^\n" + - "G is a raw type. References to generic type G should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " G.Member gm = null;\n" + - " ^^^^^^^^\n" + - "G.Member is a raw type. References to generic type G.Member should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " G.Member gtm = gm;\n" + - " ^^\n" + - "Type safety: The expression of type G.Member needs unchecked conversion to conform to G.Member\n" + - "----------\n" + - "5. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72998 - public void test0324() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - " private TreeNode root;\n" + - "\n" + - " public void doSomething() {\n" + - " for (TreeNode child : root.children()) {\n" + - " // root.children() should work??\n" + - " }\n" + - " }\n" + - "\n" + - " public void doSomethingElse() {\n" + - " for (Iterator> it = root.children().iterator(); it.hasNext();) {\n" + - " // this also should work\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class TreeNode {\n" + - " private Set> children;\n" + - " \n" + - " public Set> children() {\n" + - " return children;\n" + - " }\n" + - "}\n" - }, - ""); - } - public void test0325() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo1() {\n" + - " X.Item i = new X().new Item();\n" + - " }\n" + - " void foo2() {\n" + - " X.Item j = new X.Item();\n" + // allowed per grammar - " }\n" + - " void foo3() {\n" + - " X.Item k = new X.Item();\n" + - " }\n" + - " static void foo4() {\n" + - " X.Item k = new X.Item();\n" + - " }\n" + - " class Item {}\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " X.Item i = new X().new Item();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.Item to X.Item\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " X.Item j = new X.Item();\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot allocate the member type X.Item using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " X.Item k = new X.Item();\n" + - " ^^^^^^\n" + - "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " X.Item k = new X.Item();\n" + - " ^^^^^^\n" + - "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 12)\n" + - " X.Item k = new X.Item();\n" + - " ^^^^^^\n" + - "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 12)\n" + - " X.Item k = new X.Item();\n" + - " ^^^^^^^^^^^^\n" + - "No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instance of type X (e.g. x.new A() where x is an instance of X).\n" + - "----------\n" + - "7. WARNING in X.java (at line 12)\n" + - " X.Item k = new X.Item();\n" + - " ^^^^^^\n" + - "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75400 - public void test0326() { - this.runConformTest( - new String[] { - "X.java", - "public class X implements I {\n" + - " public I.A foo() {\n" + - " return a;\n" + - " }\n" + - "} \n" + - "interface I {\n" + - " A a = new A();\n" + - " class A {\n" + - " }\n" + - "}\n" + - "\n" + - "class XM {\n" + - " A a = new A();\n" + - " class A {\n" + - " }\n" + - "} \n" + - "\n" + - "class XMSub extends XM {\n" + - " public XM.A foo() {\n" + - " return a;\n" + - " }\n" + - "} \n" + - "\n" - }, - ""); - } - // wildcard captures bound and variable superinterfaces - public void test0327() { - this.runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " \n" + - " T element() { return null; }\n" + - " void baz(X x) {\n" + - " x.element().foo();\n" + - " x.element().bar();\n" + - " }\n" + - "}\n" + - "interface IFoo {\n" + - " void foo();\n" + - "}\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - // wildcard captures bound and variable superinterfaces - public void test0328() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " X(T element) { \n" + - " this.element = element; \n" + - " }\n" + - " static void baz(X x) {\n" + - " x.element.foo();\n" + - " x.element.bar();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X x1 = new X(new Foo());\n" + - " baz(x1);\n" + - " X x2 = new X(new Bar());\n" + - " baz(x2);\n" + - " X x3 = new X(new FooBar());\n" + - " baz(x3);\n" + - " }\n" + - "}\n" + - "interface IFoo {\n" + - " void foo();\n" + - "}\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" + - "class Foo implements IFoo {\n" + - " public void foo() {\n" + - " System.out.print(\"FOO\");\n" + - " }\n" + - "}\n" + - "class Bar implements IBar {\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n" + - "class FooBar extends Foo implements IBar {\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " baz(x1);\n" + - " ^^^\n" + - "The method baz(X) in the type X is not applicable for the arguments (X)\n" + - "----------\n" + - "2. ERROR in X.java (at line 13)\n" + - " X x2 = new X(new Bar());\n" + - " ^^^\n" + - "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 13)\n" + - " X x2 = new X(new Bar());\n" + - " ^^^\n" + - "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n"); - } - // wildcard captures bound and variable superinterfaces - public void test0329() { - this.runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " T element;\n" + - " X(T element) { \n" + - " this.element = element; \n" + - " }\n" + - " static void baz(X x) {\n" + - " x.element.foo();\n" + - " x.element.bar();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X x3 = new X(new FooBar());\n" + - " baz(x3);\n" + - " }\n" + - "}\n" + - "interface IFoo {\n" + - " void foo();\n" + - "}\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" + - "class FooBar implements IFoo, IBar {\n" + - " public void foo() {\n" + - " System.out.print(\"FOO\");\n" + - " }\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "FOOBAR" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - // wildcard captures bound superclass and variable superclass - public void test0330() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " X(T element) { \n" + - " this.element = element; \n" + - " }\n" + - " static void baz(X x) {\n" + - " x.element.foo();\n" + - " x.element.bar();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X x3 = new X(new FooBar());\n" + - " baz(x3);\n" + - " }\n" + - "}\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" + - "class Foo {\n" + - " public void foo() {\n" + - " System.out.print(\"FOO\");\n" + - " }\n" + - "}\n" + - "class FooBar extends Foo implements IBar {\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n", - }, - "FOOBAR"); - } - // wildcard captures bound superclass and variable superclass - public void test0331() { - this.runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " T element;\n" + - " X(T element) { \n" + - " this.element = element; \n" + - " }\n" + - " static void baz(X x) {\n" + - " x.element.foo();\n" + - " x.element.bar();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X x3 = new X(new FooBar());\n" + - " baz(x3);\n" + - " }\n" + - "}\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" + - "class Foo {\n" + - " public void foo() {\n" + - " System.out.print(\"FOO\");\n" + - " }\n" + - "}\n" + - "class FooBar extends Foo implements IBar {\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "FOOBAR" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - // wildcard considers bound superclass or variable superclass - public void test0332() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " X(T element) { \n" + - " this.element = element; \n" + - " }\n" + - " static void baz(X x) {\n" + // captures Foo & IBar - " x.element.foo();\n" + - " x.element.bar();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " baz(new X(new FooBar()));\n" + - " baz(new X(new Bar()));\n" + - " }\n" + - "}\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" + - "\n" + - "class Bar implements IBar {\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n" + - "\n" + - "class Foo {\n" + - " public void foo() {\n" + - " System.out.print(\"FOO\");\n" + - " }\n" + - "}\n" + - "\n" + - "class FooBar extends Foo implements IBar {\n" + - " public void bar() {\n" + - " System.out.print(\"BAR\");\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " baz(new X(new Bar()));\n" + - " ^^^\n" + - "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n"); - } - // receveir generic cast matches receiver type (not declaring class) - public void test0333() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " X(T element) { this.element = element; }\n" + - " T element() { return this.element; }\n" + - " public static void main(String[] args) {\n" + - " new X(new XB()).element().afoo();\n" + - " }\n" + - "}\n" + - "\n" + - "class XA {\n" + - " void afoo() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class XB extends XA {\n" + - " void bfoo() {}\n" + - "}\n" , - }, - "SUCCESS"); - } - // check cannot allocate type parameters - public void test0334() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X() {\n" + - " new E();\n" + - " new E() {\n" + - " void perform() {\n" + - " run();\n" + - " }\n" + - " }.perform();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " new E();\n" + - " ^\n" + - "Cannot instantiate the type E\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " new E() {\n" + - " void perform() {\n" + - " run();\n" + - " }\n" + - " }.perform();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot refer to the type parameter E as a supertype\n" + - "----------\n"); - } - // variation - check cannot allocate type parameters - public void test0335() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + // firstBound is class, still cannot be instantiated - " public X() {\n" + - " new E();\n" + - " new E() {\n" + - " void perform() {\n" + - " run();\n" + - " }\n" + - " }.perform();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^^\n" + - "The type parameter E should not be bounded by the final type String. Final types cannot be further extended\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " new E();\n" + - " ^\n" + - "Cannot instantiate the type E\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " new E() {\n" + - " void perform() {\n" + - " run();\n" + - " }\n" + - " }.perform();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot refer to the type parameter E as a supertype\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74669 - public void test0336() { - this.runNegativeTest( - new String[] { - "X.java", - "interface IMyInterface {\n" + - "}\n" + - "class MyClass {\n" + - "\n" + - " public Type myMethod(Object obj, Class type) {\n" + - " return null;\n" + - " }\n" + - " public static Type myStaticMethod(Object obj, Class type) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public IMyInterface getThis() {\n" + - " if (true)\n" + - " return new MyClass().myMethod(this, IMyInterface.class);\n" + - " else\n" + - " return MyClass.myStaticMethod(this, IMyInterface.class);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public Type myMethod(Object obj, Class type) {\n" + - " ^^^^\n" + - "The type parameter Type is hiding the type Type\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " public Type myMethod(Object obj, Class type) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " public static Type myStaticMethod(Object obj, Class type) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 15)\n" + - " return new MyClass().myMethod(this, IMyInterface.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to IMyInterface\n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " return new MyClass().myMethod(this, IMyInterface.class);\n" + - " ^^^^^^^\n" + - "MyClass is a raw type. References to generic type MyClass should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77078 - public void test0337() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Vector;\n" + - "public class X {\n" + - " public void foo() {\n" + - " Vector objectVector = new Vector() {\n" + - " protected void bar() {\n" + - " baz(this); /* ERROR */\n" + - " }\n" + - " };\n" + - " baz(objectVector);\n" + - " baz(new Vector());\n" + - " }\n" + - " public void baz(Vector mysteryVector) { }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77052 - public void test0338() { - this.runConformTest( - new String[] { - "X.java", - "interface M { }\n" + - "\n" + - "class N { \n" + - " M> pni = null;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " N var1 = null;\n" + - "\n" + - " M> var2 = var1.pni;\n" + - " // Above line reports as error in Eclipse. \n" + - " // \"var2\" is underlined and the error message is: \n" + - " // Type mismatch: cannot convert from M> to M>\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77052 - variation - public void test0339() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "import java.util.Set;\n" + - "\n" + - "class X {\n" + - " static class Entry {}\n" + - " void foo() {\n" + - " Iterator> i = entrySet().iterator();\n" + - " }\n" + - " Set> entrySet() { return null; }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76313 - public void test0340() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " private T data;\n" + - " private X(T data){ this.data=data; }\n" + - " public static X createObject(S data){\n" + - " System.out.println(data);\n" + - " return new X(data);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X res=X.createObject(\"Hallo\");\n" + - " }\n" + - "}\n", - }, - "Hallo"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77118 - public void test0341() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public Object getItem() { return null; }\n" + - "}\n", - "Y.java", - "public class Y extends X {\n" + - " public String getItem() { return null; }\n" + - "}\n", - "Z.java", - "public class Z extends X {\n" + - " public Comparable getItem() { return null; }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77142 - check no raw unsafe warning is issued when accessing generic method from raw type - public void test0342() { - this.runNegativeTest( - new String[] { - "Test.java", - "class MyClass {\n" + - " \n" + - " private T thing;\n" + - " { Zork z; }\n" + - " \n" + - " public\n" + - " MyClass(T thing) {\n" + - " this.thing = thing;\n" + - " }\n" + - " \n" + - " public static MyClass\n" + - " factoryMakeMyClass(U thing) {\n" + - " return new MyClass(thing);\n" + - " }\n" + - "}\n" + - "\n" + - "class External {\n" + - "\n" + - " public static MyClass\n" + - " factoryMakeMyClass(U thing) {\n" + - " return new MyClass(thing);\n" + - " }\n" + - "}\n" + - "\n" + - "public class Test {\n" + - " public static void\n" + - " test()\n" + - " {\n" + - " // No problem with this line:\n" + - " MyClass foo = External.factoryMakeMyClass(\"hi\");\n" + - " \n" + - " // This line gives me an error:\n" + - " // Type mismatch: cannot convert from MyClass to MyClass\n" + - " MyClass bar = MyClass.factoryMakeMyClass(\"hi\");\n" + - " MyClass bar2 = MyClass.factoryMakeMyClass(\"hi\");\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Test.java (at line 4)\n" + - " { Zork z; }\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74588 - public void test0343() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T m;\n" + - "\n" + - " class Y {\n" + - " void test() {\n" + - " new Y() {\n" + - " void test() {\n" + - " System.out.println(X.this.m);\n" + - " }\n" + - " }.test();\n" + - " }\n" + - " }\n" + - "}\n" + - "\n", - }, - ""); - } - // checking scenario where generic type and method share the same type parameter name - public void test0344() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.IOException;\n" + - "\n" + - "public abstract class X {\n" + - " \n" + - " public abstract T bar(T t);\n" + - "\n" + - " static void foo(X x) {\n" + - " x.bar(null);\n" + - " \n" + - " class R implements Runnable {\n" + - " public void run() {\n" + - " }\n" + - " }\n" + - " X xr = new X(){ \n" + - " public T bar(T t) { \n" + - " return t; \n" + - " }\n" + - " };\n" + - " IOException e = xr.bar(new IOException());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public abstract T bar(T t);\n" + - " ^\n" + - "The type parameter T is hiding the type T\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " static void foo(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " x.bar(null);\n" + - " ^^^\n" + - "The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "4. ERROR in X.java (at line 14)\n" + - " X xr = new X(){ \n" + - " ^^^^^^\n" + - "The type new X(){} must implement the inherited abstract method X.bar(T)\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 - public void test0345() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " X1 o1 = new X1();\n" + - " ((J)o1).get();\n" + - " }\n" + - "}\n" + - "\n" + - "class X1 implements I {\n" + - " public X1 get() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return this;\n" + - " }\n" + - "}\n" + - "\n" + - "interface I extends J {\n" + - " I get();\n" + - "}\n" + - "\n" + - "interface J {\n" + - " J get();\n" + - "}", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 - public void test0346() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " X1 o1 = new X1(new Integer(4));\n" + - " System.out.println(o1.get().t);\n" + - " }\n" + - "}\n" + - "\n" + - "class X1 implements I {\n" + - " T t;\n" + - " X1(T arg) {\n" + - " t = arg;\n" + - " }\n" + - " public X1 get() {\n" + - " return this;\n" + - " }\n" + - "}\n" + - "\n" + - "interface I extends J {\n" + - " I get();\n" + - "}\n" + - "\n" + - "interface J {\n" + - " J get();\n" + - "}" - , - }, - "4"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 - public void test0347() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " X1 o = new X1(new Integer(4));\n" + - " System.out.println(o.get().t);\n" + - " }\n" + - "}\n" + - "\n" + - "class X1 implements I {\n" + - " T t;\n" + - " X1(T arg) {\n" + - " t = arg;\n" + - " }\n" + - " public X1 get() {\n" + - " return this;\n" + - " }\n" + - "} \n" + - "\n" + - "interface I extends K, L {\n" + - " I get();\n" + - "}\n" + - "\n" + - "interface J {\n" + - " J get();\n" + - "}\n" + - "\n" + - "interface K extends J {\n" + - "}\n" + - "\n" + - "interface L {\n" + - " K get();\n" + - "}", - }, - "4"); - } - // checking scenario where generic type and method share the same type parameter name - public void test0348() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.IOException;\n" + - "public abstract class X {\n" + - " public abstract T bar(T t);\n" + - " static void foo(X x) {\n" + - " x.bar(null);\n" + - " class R implements Runnable {\n" + - " public void run() {}\n" + - " }\n" + - " X xr = new X(){ \n" + - " public T bar(T t) { return t; }\n" + - " };\n" + - " IOException e = xr.bar(new IOException());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public abstract T bar(T t);\n" + - " ^\n" + - "The type parameter T is hiding the type T\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " static void foo(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " x.bar(null);\n" + - " ^^^\n" + - "The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "4. WARNING in X.java (at line 10)\n" + - " public T bar(T t) { return t; }\n" + - " ^^^^^^^^\n" + - "The method bar(T) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n", - JavacTestOptions.EclipseHasABug.EclipseBug236242); - } - // test wildcard compatibilities - public void test0349() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " static void foo(X out, X1 in) {\n" + - " out.element = in.element;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class X1{\n" + - " U element;\n" + - "}\n", - }, - "SUCCESS"); - } - // test wildcard compatibilities - public void test0350() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " static void foo(X out, X1 in) {\n" + - " out.element = in.element;\n" + - " }\n" + - "}\n" + - "class X1{\n" + - " U element;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " out.element = in.element;\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#2-of ? to capture#1-of ?\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75328 - public void test0351() { - this.runConformTest( - new String[] { - "X.java", - "interface Intf, I extends Comparable> { \n" + - " public void f(Intf val);\n" + - "}\n" + - "\n" + - "public class X , P extends Comparable> implements Intf {\n" + - "\n" + - " public void f(Intf val) { } \n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77051 - public void test0352() { - this.runConformTest( - new String[] { - "X.java", - "interface C { }\n" + - "interface PC extends C { } \n" + - "interface PO { \n" + - " C proc1();\n" + - " C proc2();\n" + - " C proc3();\n" + - "}\n" + - "abstract class X implements PO {\n" + - " public C proc1() { return result1; }\n" + - " private final PC result1 = null;\n" + - " public C proc2() { return result2; }\n" + - " private final PC result2 = null;\n" + - " public C proc3() { return result3; }\n" + - " private final PC result3 = null;\n" + - "}\n", - }, - ""); - } - public void test0353() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " T foo(Class c) { return null; }\n" + - "}\n" + - "class Y {\n" + - " T foo(Class c) { return null; }\n" + - "}" - }, - ""); - } - public void test0354() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " S foo(Class c) { return null; }\n" + - "}\n" + - "class Y {\n" + - " T foo(Class c) { return null; }\n" + - "}" - }, - ""); - } - public void test0355() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " S foo(Class c) { return null; }\n" + - "}\n" + - "class Y {\n" + - " S foo(Class c) { return null; }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " S foo(Class c) { return null; }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + - "----------\n"); - } - public void test0356() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " T foo(Class c) { return null; }\n" + - "}\n" + - "class Y {\n" + - " T foo(Class c) { return null; }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " T foo(Class c) { return null; }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + - "----------\n"); - } - public void test0357() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " T foo(Class c) { return null; }\n" + - "}\n" + - "class Y {\n" + - " T foo(Class c) { return null; }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " T foo(Class c) { return null; }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76720 - public void test0358() { - this.runConformTest( - new String[] { - "MyClass.java", - "public class MyClass {}\n", - "A.java", - "public interface A {}\n", - "B.java", - "public interface B extends A {}\n", - "C.java", - "public class C implements B {}\n", // compile against sources - "D.java", - "public class D implements A{}\n", // compile against sources - }, - ""); - // compile against generated binaries - this.runConformTest( - new String[] { - "C.java", - "public class C implements B {}\n", - "D.java", - "public class D implements A{}\n", - }, - "", - null, - false, - null); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76790 - public void test0359() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " class List1 extends LinkedList {};\n" + - " public static void main (String[] args) {\n" + - " Map> x = new HashMap>();\n" + - " Map> m = new HashMap>();\n" + - " }\n" + - "}" - } - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76786 - public void test0360() { - this.runConformTest( - new String[] { - "Test.java", - "import java.lang.Comparable;\n" + - "public class Test {\n" + - " private static final class X implements Comparable> {\n" + - " public int compareTo(X arg0) { return 0; }\n" + - " };\n" + - " private static class Y {};\n" + - " private static final class Z extends Y implements Comparable> {\n" + - " public int compareTo(Z arg0) { return 0; }\n" + - " };\n" + - " public static void doSomething(Comparable a, Comparable b) {}\n" + - " public static void doSomethingElse(Z a, Z b) {\n" + - " doSomething(a, b);\n" + - " }\n" + - " private static final class W { };\n" + - " public static void main(String[] args) {\n" + - " doSomething(new X(), new X());\n" + - " doSomething(new Z(), new Z());\n" + - " doSomethingElse(new Z(), new Z());\n" + - " doSomethingElse(new Z(), new Z());\n" + - " // The next line won\'t compile. It\'s the generic, String>(), new Z, String>());\n" + - " }\n" + - "}" - } - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75525 - public void test0361() { - this.runConformTest( - new String[] { - "Test.java", - "import java.util.AbstractSet;\n" + - "import java.util.Iterator;\n" + - "import java.util.Map.Entry;\n" + - "public class Test extends AbstractSet> {\n" + - " public Iterator> iterator() {\n" + - " return new Iterator>() {\n" + - " public boolean hasNext() {return false;}\n" + - " public Entry next() {return null;}\n" + - " public void remove() {} \n" + - " };\n" + - " }\n" + - " public int size() {return 0;}\n" + - "}" - } - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72643 - public void test0362() { - Map customOptions= getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); - this.runConformTest( - new String[] { - "Test.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "public class Test {\n" + - " public void a() {\n" + - " List list1 = new ArrayList();\n" + - " List list2 = new ArrayList();\n" + - " compare(list1, list2);\n" + - " }\n" + - " private void compare(List list1, List list2) {\n" + - " // do some comparing logic...\n" + - " }\n" + - "}\n" + - "\n" - }, - "", - null, - true, - null, - customOptions, - null/*no custom requestor*/); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76434 - public void test0363() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "import java.util.Set;\n" + - "public class X {\n" + - " Set> m_values;\n" + - " X(Map values) {\n" + - " m_values = values.entrySet();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " m_values = values.entrySet();\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Set> to Set>\n" + - "----------\n"); - } - // check param type equivalences - public void test0364() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " \n" + - " void bar1(MX> mxcs, MX> mxco) {\n" + - " mxco = mxcs;\n" + // wrong - " }\n" + - " void bar1(Class cs, Class co) {\n" + - " co = cs;\n" + // ok - " }\n" + - " \n" + - "}\n" + - "class MX {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " mxco = mxcs;\n" + - " ^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n"); - } - // check param type equivalences - public void test0365() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " class MX {\n" + - " }\n" + - " \n" + - " MX createMX() { return new MX(); }\n" + - "\n" + - " void foo(X x, MX mx) {\n" + - " mx = x.createMX();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " mx = x.createMX();\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.MX to X.MX\n" + - "----------\n"); - } - // check param type equivalences - public void test0366() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " \n" + - " void foo1(MX> target, MX value) {\n" + - " target= value; // foo1 - wrong\n" + - " }\n" + - " void foo2(MX> target, MX> value) {\n" + - " target= value; // foo2 - wrong\n" + - " }\n" + - " void foo3(MX> target, MX> value) {\n" + - " target= value; // foo3 - wrong\n" + - " }\n" + - " void foo4(MX> target, MX> value) {\n" + - " target= value; // foo4 - wrong\n" + - " }\n" + - " void foo5(MX target, MX value) {\n" + - " target= value; // foo5\n" + - " }\n" + - " void foo6(MX target, MX value) {\n" + - " target= value; // foo6\n" + - " }\n" + - " void foo7(MX> target, MX> value) {\n" + - " target= value; // foo7 - wrong\n" + - " }\n" + - " void foo8(MX> target, MX> value) {\n" + - " target= value; // foo8 - wrong\n" + - " }\n" + - " void foo9(MX target, MX value) {\n" + - " target= value; // foo9\n" + - " }\n" + - " void foo10(MX target, MX value) {\n" + - " target= value; // foo10 - wrong\n" + - " }\n" + - " void foo11(MX target, MX value) {\n" + - " target= value; // foo11 - wrong\n" + - " }\n" + - " void foo12(MX target, MX value) {\n" + - " target= value; // foo12\n" + - " }\n" + - "}\n" + - "\n" + - "class MX {\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " void foo1(MX> target, MX value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " target= value; // foo1 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX to MX>\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " target= value; // foo2 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "4. ERROR in X.java (at line 10)\n" + - " target= value; // foo3 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "5. ERROR in X.java (at line 13)\n" + - " target= value; // foo4 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "6. WARNING in X.java (at line 15)\n" + - " void foo5(MX target, MX value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 15)\n" + - " void foo5(MX target, MX value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 18)\n" + - " void foo6(MX target, MX value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "9. WARNING in X.java (at line 18)\n" + - " void foo6(MX target, MX value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "10. WARNING in X.java (at line 21)\n" + - " void foo7(MX> target, MX> value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "11. WARNING in X.java (at line 21)\n" + - " void foo7(MX> target, MX> value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "12. ERROR in X.java (at line 22)\n" + - " target= value; // foo7 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "13. WARNING in X.java (at line 24)\n" + - " void foo8(MX> target, MX> value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "14. WARNING in X.java (at line 24)\n" + - " void foo8(MX> target, MX> value) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "15. ERROR in X.java (at line 25)\n" + - " target= value; // foo8 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX>\n" + - "----------\n" + - "16. ERROR in X.java (at line 31)\n" + - " target= value; // foo10 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX to MX\n" + - "----------\n" + - "17. ERROR in X.java (at line 34)\n" + - " target= value; // foo11 - wrong\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX to MX\n" + - "----------\n"); - } - // check param type equivalences - public void test0367() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " \n" + - " void foo1(MX target, MX> value) {\n" + - " target= value; // foo1\n" + - " }\n" + - " void foo2(MX target, MX> value) {\n" + - " target= value; // foo2\n" + - " }\n" + - " void foo3(MX target, MX> value) {\n" + - " target= value; // foo3\n" + - " }\n" + - "}\n" + - "\n" + - "class MX {\n" + - "}\n" , - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " void foo1(MX target, MX> value) {\n" + - " ^^\n" + - "MX is a raw type. References to generic type MX should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " void foo3(MX target, MX> value) {\n" + - " ^^\n" + - "MX is a raw type. References to generic type MX should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " target= value; // foo3\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from MX> to MX\n" + - "----------\n"); - } - // check param type equivalences - public void test0368() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " static class MX {\n" + - " }\n" + - " \n" + - " MX createMX() { return new MX(); }\n" + - "\n" + - " void foo(X x, MX mx) {\n" + - " mx = x.createMX();\n" + - " }\n" + - "}\n" , - }, - ""); - } - // bound check for Enum - public void test0369() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " > T foo(T t) { return null; }\n" + - "}\n", - }, - ""); - } - // decoding raw binary type - public void test0370() { - this.runConformTest( - new String[] { - "p/B.java", - "package p;\n" + - "import java.util.Map;\n" + - "public class B {\n" + - " public static Map foo(byte[] byteArray, Object o, Class c) {\n" + - " return null;\n" + - " }\n" + - "}" - }, - ""); - - this.runConformTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "\n" + - "import p.B;\n" + - "\n" + - "public class X {\n" + - " {\n" + - " Map map = B.foo(null, null, null);\n" + - " }\n" + - "}\n", - }, - "", - null, - false, - null); - } - // X is not compatible with X - public void test0371() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public void foo(XC target, XC value) {\n" + - " target = value;\n" + - " }\n" + - "}\n" + - "class XC {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " target = value;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from XC to XC\n" + - "----------\n"); - } - public void test0372() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "import java.util.Map;\n" + - "import java.util.Map.Entry;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void foo(Iterator> iter) {\n" + - " new XA.MXA(iter.next());\n" + - " }\n" + - "}\n" + - "class XA {\n" + - " static class MXA implements Entry {\n" + - " MXA(Entry e) {\n" + - " }\n" + - " public K getKey() {\n" + - " return null;\n" + - " }\n" + - " public V getValue() {\n" + - " return null;\n" + - " }\n" + - " public V setValue(V value) {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n" , - }, - ""); - } - public void test0373() { - this.runConformTest( - new String[] { - "XA.java", - "import java.util.Map.Entry;\n" + - "\n" + - "public class XA {\n" + - " static class MXA implements Entry {\n" + - " MXA(Entry e) {\n" + - " }\n" + - " public K getKey() {\n" + - " return null;\n" + - " }\n" + - " public V getValue() {\n" + - " return null;\n" + - " }\n" + - " public V setValue(V value) {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n" , - }, - ""); - // compile against binaries - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "import java.util.Map;\n" + - "import java.util.Map.Entry;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void foo(Iterator> iter) {\n" + - " new XA.MXA(iter.next());\n" + - " }\n" + - "}\n" , - }, - "", - null, - false, - null); - } - // wildcard with no upper bound uses type variable as upper bound - public void test0374() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " void foo1(X target, X value) {\n" + - " target = value; // foo1\n" + - " }\n" + - " void foo2(X target, X value) {\n" + - " target = value; // foo2\n" + - " } \n" + - "}\n", - }, - ""); - } - public void test0375() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " void foo1(X target, X value) {\n" + - " target = value; // foo1\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " target = value; // foo1\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n"); - } - public void test0376() { - this.runConformTest( - new String[] { - "XA.java", - "import java.util.Map.Entry;\n" + - "\n" + - "public class XA {\n" + - " XA self() { return this; } \n" + - " static class MXA implements Entry {\n" + - " MXA(Entry e) {\n" + - " }\n" + - " public K getKey() {\n" + - " return null;\n" + - " }\n" + - " public V getValue() {\n" + - " return null;\n" + - " }\n" + - " public V setValue(V value) {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n" , - }, - ""); - // compile against binaries - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "import java.util.Map;\n" + - "import java.util.Map.Entry;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void foo(Iterator> iter) {\n" + - " new XA.MXA(iter.next());\n" + - " }\n" + - "}\n" , - }, - "", - null, - false, - null); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76601 - public void test0377() { - this.runConformTest( - new String[] { - "Test.java", - "public class Test {\n" + - " public static void main (String[] args) {\n" + - " final String val = (args == null||args.length==0 ? \"SUCC\" : args[0]) + \"ESS\";\n" + - " class AllegedBoundMismatch> {\n" + - " String field = val;\n" + - " }\n" + - " System.out.println(new Object() {\n" + - " AllegedBoundMismatch> trial = new AllegedBoundMismatch>();\n" + - " }.trial.field);\n" + - " }\n" + - "}\n" + - "class Q {}\n" + - "interface SubI extends SuperI> {}\n" + - "interface SuperI {}" - }, - "SUCCESS"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76219 - public void test0378() { - this.runConformTest( - new String[] { - "BB.java", - "interface AA> { \n" + - " public boolean m(AA that); \n" + - " public Z z(); \n" + - " public boolean b(); \n" + - "}\n" + - "abstract class BB> implements AA { \n" + - " public boolean m(AA wht) { return wht.z().b(); } \n" + - "}\n"} - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71612 - public void test0379() { - this.runConformTest( - new String[] { - "Test.java", - "import java.util.AbstractSet;\n" + - "import java.util.Iterator;\n" + - "public class Test extends AbstractSet{\n" + - " public static void main(String[] args) {\n" + - " Test t=new Test();\n" + - " t.add(null);\n" + - " }\n" + - " public boolean add(Runnable run) {\n" + - " System.out.println(\"success\");\n" + - " return true;\n" + - " }\n" + - " public Iterator iterator() {return null;}\n" + - " public int size() {return 0;}\n" + - "}" - } - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77327 - public void test0380() { - this.runConformTest( - new String[] { - "Test.java", - "import java.util.List;\n" + - "public class Test {\n" + - " List wsn= null; // Contravariance\n" + - " List wsi= wsn; // should work!\n" + - "}\n" - } - ); - } - - public void test0381() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " void foo(Class s) {}\n" + - "}\n" + - "class Y {\n" + - " void foo(Class s) {}\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " void foo(Class s) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + - "----------\n"); - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " void foo(Class s) {}\n" + - "}\n" + - "class Y {\n" + - " void foo(Class s) {}\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " void foo(Class s) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + - "----------\n"); - } - public void test0382() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y implements I {}\n" + - "interface I { void foo(Class s); }\n" + - "class Y { void foo(Class s) {} }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends Y implements I {}\n" + - " ^\n" + - "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X extends Y implements I {}\n" + - " ^\n" + - "The type X must implement the inherited abstract method I.foo(Class)\n" + - "----------\n"); - this.runNegativeTest( - new String[] { - "X.java", - "public abstract class X extends Y implements I {}\n" + - "interface I { void foo(Class s); }\n" + - "class Y { void foo(Class s) {} }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public abstract class X extends Y implements I {}\n" + - " ^\n" + - "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + - "----------\n"); - } - public void test0383() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y implements I { public void foo(Class s) {} }\n" + - "interface I { void foo(Class s); }\n" + - "class Y { public void foo(Class s) {} }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends Y implements I { public void foo(Class s) {} }\n" + - " ^\n" + - "The type X must implement the inherited abstract method I.foo(Class)\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X extends Y implements I { public void foo(Class s) {} }\n" + - " ^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type I but does not override it\n" + - "----------\n" + - "3. WARNING in X.java (at line 1)\n" + - " public class X extends Y implements I { public void foo(Class s) {} }\n" + - " ^^^^^^^^^^^^^^^\n" + - "The method foo(Class) of type X should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n"); - /* - X.java:1: X is not abstract and does not override abstract method foo(java.lang.Class) in I - public class X extends Y implements I { public void foo(Class s) {} } - ^ - */ - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y implements I {}\n" + - "interface I { void foo(Class s); }\n" + - "class Y { public void foo(Class s) {} }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends Y implements I {}\n" + - " ^\n" + - "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X extends Y implements I {}\n" + - " ^\n" + - "The type X must implement the inherited abstract method I.foo(Class)\n" + - "----------\n"); - /* - X.java:1: X is not abstract and does not override abstract method foo(java.lang.Class) in I - public class X extends Y implements I {} - ^ - */ - this.runNegativeTest( - new String[] { - "X.java", - "public abstract class X extends Y implements I {}\n" + // NOTE: X is abstract - "interface I { void foo(Class s); }\n" + - "class Y { public void foo(Class s) {} }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public abstract class X extends Y implements I {}\n" + - " ^\n" + - "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + - "----------\n"); - /* - X.java:1: name clash: foo(java.lang.Class) in Y and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other - public abstract class X extends Y implements I {} - ^ - */ - } - public void test0384a() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " java.util.List foo3(java.util.List t) { return t; }\n" + - " Class foo4() { return null; }\n" + - " Class[] foo5() { return null; }\n" + - "}\n" + - "class Y {\n" + - " java.util.List foo3(java.util.List t) { return t; }\n" + - " Class foo4() { return null; }\n" + - " Class[] foo5() { return null; }\n" + - "}\n" - }, - ""); - } - public void test0384b() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " @Override Class foo() { return null; }\n" + - " @Override Class[] foo2() { return null; }\n" + - "}\n" + - "class Y {\n" + - " Class foo() { return null; }\n" + - " Class[] foo2() { return null; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " @Override Class foo() { return null; }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The return type is incompatible with Y.foo()\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " @Override Class[] foo2() { return null; }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The return type is incompatible with Y.foo2()\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77496 - public void test0385() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "interface IDoubles { List getList(); }\n" + - "class A implements IDoubles {\n" + - " public List getList() { return null; }\n" + - "}\n" + - "class B {\n" + - " public List getList() { return null; }\n" + - "}\n" + - "class C extends B implements IDoubles {\n" + - " void use() { List l= getList(); }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " public List getList() { return null; }\n" + - " ^^^^^^^^^^^^\n" + - "The return type is incompatible with IDoubles.getList()\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " class C extends B implements IDoubles {\n" + - " ^\n" + - "The return type is incompatible with IDoubles.getList(), B.getList()\n" + - "----------\n"); - /* - X.java:3: A is not abstract and does not override abstract method getList() in IDoubles - class A implements IDoubles { - ^ - X.java:4: getList() in A cannot implement getList() in IDoubles; attempting to use incompatible return type - found : java.util.List - required: java.util.List - public List getList() { return null; } - ^ - X.java:9: C is not abstract and does not override abstract method getList() in IDoubles - class C extends B implements IDoubles { - */ - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77325 - public void test0386() { - this.runNegativeTest( - new String[] { - "X.java", - "class X {\n" + - " private U u;\n" + - " private V v;\n" + - " public X(U u,V v) { this.u= u; this.v= v; }\n" + - " public R getU() { return (R)u; } // Warning\n" + - " public R getV() { return (R)v; } // Warning\n" + - " Object o;\n" + - " public T getT() { return (T)o; } // Warning\n" + - "}" - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public R getU() { return (R)u; } // Warning\n" + - " ^^^^\n" + - "Type safety: Unchecked cast from U to R\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " public R getV() { return (R)v; } // Warning\n" + - " ^^^^\n" + - "Type safety: Unchecked cast from V to R\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " public T getT() { return (T)o; } // Warning\n" + - " ^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - generic varargs method - public void test0387() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X\n" + - "{\n" + - "\n" + - " public boolean test1()\n" + - " {\n" + - " test2(\"test\", null, 0);\n" + - " }\n" + - "\n" + - " public List test2(final List list, final String... strings)\n" + - " {\n" + - " return null;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " test2(\"test\", null, 0);\n" + - " ^^^^^\n" + - "The method test2(List, String...) in the type X is not applicable for the arguments (String, null, int)\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation - public void test0388() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X\n" + - "{\n" + - "\n" + - " public boolean test01()\n" + - " {\n" + - " test02(null, null, \"test\");\n" + - " return false;\n" + - " }\n" + - "\n" + - " public List test02(final List list, final String... strings)\n" + - " {\n" + - " return null;\n" + - " }\n" + - "}\n" - }, - "" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation - public void test0389() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public boolean test01() {\n" + - " String s = foo(\"hello\");\n" + - " return s != null;\n" + - " }\n" + - "\n" + - " public F foo(F f, F... others) {\n" + - " return f;\n" + - " }\n" + - "}\n" - }, - "" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation - public void test0390() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public boolean test01() {\n" + - " String s = foo(null, \"hello\");\n" + - " return s != null;\n" + - " }\n" + - "\n" + - " public F foo(F f, F... others) {\n" + - " return f;\n" + - " }\n" + - "}\n" - }, - "" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation - public void test0391() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public boolean test01() {\n" + - " String[] s = foo(null, new String[]{ \"hello\" });\n" + - " return s != null;\n" + - " }\n" + - "\n" + - " public F foo(F f, F... others) {\n" + - " return f;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " String[] s = foo(null, new String[]{ \"hello\" });\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from String to String[]\n" + - "----------\n" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation - public void test0392() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public boolean test01() {\n" + - " foo(null, \"hello\");\n" + // no inference on expected type - " return true;\n" + - " }\n" + - "\n" + - " public F foo(F f, F... others) {\n" + - " return f;\n" + - " }\n" + - "}\n" - }, - "" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78049 - chech invalid array initializer - public void test0393() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public boolean test01() {\n" + - " foo(null, \"hello\");\n" + // no inference on expected type - " return true;\n" + - " }\n" + - "\n" + - " public F foo(F f, F... others) {\n" + - " return f;\n" + - " }\n" + - "}\n" - }, - "" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78027 - public void test0394() { - this.runConformTest( - new String[] { - "X.java", - "public class X \n" + - "{\n" + - "}\n" + - "\n" + - "interface ITest\n" + - "{ \n" + - "}\n" + - "\n" + - "abstract class Test implements ITest\n" + - "{\n" + - " protected Manager m_manager;\n" + - " \n" + - " public ITest get()\n" + - " {\n" + - " return m_manager.getById(getClass(), new Integer(1));\n" + - " }\n" + - " \n" + - " public static class Manager\n" + - " {\n" + - " public > T getById(Class cls, Integer id)\n" + - " {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n" - }, - "" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74119 - variation - public void test0395() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T element;\n" + - " \n" + - " void foo(X xnpe) {\n" + - " xnpe.element = new java.io.IOException();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " xnpe.element = new java.io.IOException();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from IOException to capture#1-of ? super NullPointerException\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78139 - downcast generic method inference - public void test0396() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Collection;\n" + - "import java.util.List;\n" + - "import java.util.ArrayList;\n" + - "\n" + - "public class X\n" + - "{\n" + - " public static List emptyList() {\n" + - " return new ArrayList();\n" + - " }\n" + - " public static Collection emptyCollection() {\n" + - " return new ArrayList();\n" + - " }\n" + - " public static Iterable emptyIterable() {\n" + - " return new ArrayList();\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " // generic inference using expected lhs type: T --> String\n" + - " final List lL = emptyList(); // 1\n" + - " \n" + - " // generic inference using expected cast type: T --> String\n" + - " final Collection cL = (Collection)emptyList(); // 2\n" + - " \n" + - " // generic inference using expected cast type: T --> String\n" + - " final Iterable iL = (Iterable)emptyList(); // 3\n" + - " \n" + - " // generic inference using expected lhs type: T --> String\n" + - " final Collection cC = emptyCollection(); // 4\n" + - " \n" + - " // generic inference using expected cast type: T --> String\n" + - " final Iterable iC = (Iterable)emptyCollection(); // 5\n" + - " \n" + - " // generic inference using expected lhs type: T --> String\n" + - " final Iterable iI = emptyIterable(); // 6\n" + - " \n" + - " // generic inference using expected lhs type: T --> String\n" + - " final Collection cL2 = emptyList(); // 7\n" + - " \n" + - " // generic inference using expected lhs type: T --> String\n" + - " final Iterable iC2 = emptyCollection(); // 8\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 22)\n" + - " final Collection cL = (Collection)emptyList(); // 2\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to Collection\n" + - "----------\n" + - "2. ERROR in X.java (at line 25)\n" + - " final Iterable iL = (Iterable)emptyList(); // 3\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to Iterable\n" + - "----------\n" + - "3. ERROR in X.java (at line 31)\n" + - " final Iterable iC = (Iterable)emptyCollection(); // 5\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Collection to Iterable\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76132 - public void test0397() { - this.runNegativeTest( - new String[] { - "X.java", - "interface K1 { \n" + - " public void kk(K1 x); \n" + - "} \n" + - " \n" + - "class K2 implements K1 { \n" + - " public void kk(K1 y) { \n" + - " System.out.println(\"K2::kk(\" + y.toString() + \")\"); \n" + - " } \n" + - "} \n" + - " \n" + - "// --------------------------------------------------- \n" + - " \n" + - "interface L1 { \n" + - " public void ll(L1 a); \n" + - "} \n" + - " \n" + - "class L2 implements L1 { \n" + - " public void ll(L1 b) { \n" + - " ll2(b); \n" + - " } \n" + - " \n" + - " private void ll2(L1 c) { \n" + - " System.out.println(\"L2::ll2(\" + c.toString() + \")\"); \n" + - " } \n" + - "} \n" + - " \n" + - "// --------------------------------------------------- \n" + - " \n" + - "interface M1 { \n" + - " public void mm(M1 p); \n" + - "} \n" + - " \n" + - "class M2 implements M1 { \n" + - " public void mm(M1 q) { \n" + - " System.out.println(\"M2::mm(\" + q.toString() + \")\"); \n" + - " } \n" + - "} \n" + - " \n" + - "// =================================================== \n" + - " \n" + - "class XX { public String toString() { return \"XX\"; } } \n" + - "class YY extends XX { public String toString() { return \"YY\"; } } \n" + - "class ZZ extends YY { public String toString() { return \"ZZ\"; } } \n" + - " \n" + - "// --------------------------------------------------- \n" + - " \n" + - "public class X { \n" + - " public static void main(String arg[]) { \n" + - " goK(new K2()); \n" + - " goL(new L2()); \n" + - " goM(new M2()); \n" + - " } \n" + - " \n" + - " \n" + - " public static void goK(K1 k) { \n" + - " // k.kk(new K2()); // Would fail \n" + - " k.kk(new K2()); \n" + - " k.kk(new K2()); \n" + - " } \n" + - " \n" + - " \n" + - " public static void goL(L1 l) { \n" + - " // l.ll(new L2()); // Would fail \n" + - " l.ll(new L2()); \n" + - " l.ll(new L2()); \n" + - " } \n" + - " \n" + - " \n" + - " public static void goM(M1 m) { \n" + - " // m.mm(new M2()); // Would fail \n" + - " m.mm(new M2()); \n" + - " m.mm(new M2()); \n" + - " } \n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 33)\n" + - " class M2 implements M1 { \n" + - " ^^\n" + - "The type M2 must implement the inherited abstract method M1.mm(M1)\n" + - "----------\n" + - "2. ERROR in X.java (at line 34)\n" + - " public void mm(M1 q) { \n" + - " ^^^^^^^^^^^\n" + - "Name clash: The method mm(M1) of type M2 has the same erasure as mm(M1) of type M1 but does not override it\n" + - "----------\n" + - "3. WARNING in X.java (at line 41)\n" + - " class XX { public String toString() { return \"XX\"; } } \n" + - " ^^^^^^^^^^\n" + - "The method toString() of type XX should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "4. WARNING in X.java (at line 42)\n" + - " class YY extends XX { public String toString() { return \"YY\"; } } \n" + - " ^^^^^^^^^^\n" + - "The method toString() of type YY should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "5. WARNING in X.java (at line 43)\n" + - " class ZZ extends YY { public String toString() { return \"ZZ\"; } } \n" + - " ^^^^^^^^^^\n" + - "The method toString() of type ZZ should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n"); - } - // cannot allocate parameterized type with wildcards - public void test0398() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " X(){\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X();\n" + - " new X();\n" + - " new X(){};\n" + - " new X(){};\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " new X();\n" + - " ^\n" + - "Cannot instantiate the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " new X();\n" + - " ^\n" + - "Cannot instantiate the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " new X(){};\n" + - " ^\n" + - "The type new X(){} cannot extend or implement X. A supertype may not specify any wildcard\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " new X(){};\n" + - " ^\n" + - "The type new X(){} cannot extend or implement X. A supertype may not specify any wildcard\n" + - "----------\n"); - } - - public void test0399() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\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 AX());\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " P foo() { return null; }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X x = new X>(new AX());\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " X x = new X>(new AX());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X>(AX) is undefined\n" + - "----------\n"); - } - - public void test0400() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " X(X xt){\n" + - " this.t = xt.t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X x = new X>(new X>(null));\n" + - " }\n" + - "}\n" + - "class AX

{\n" + - " P foo() { return null; }\n" + - "}", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X x = new X>(new X>(null));\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX

should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " X x = new X>(new X>(null));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X>(X>) is undefined\n" + - "----------\n"); - } - - // legal to allocate/inherit from a type with wildcards, as long as non direct arguments - public void test0401() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " new X>();\n" + - " new X>();\n" + - " new X>(){};\n" + - " new X>(){};\n" + - " }\n" + - "}", - }, - ""); - } - - // legal to inherit from a type with wildcards, as long as non direct arguments - public void test0402() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends Y> {\n" + - "}\n" + - "class Y {}", - }, - ""); - } - // check cast between generic types - public void test0403() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo(X> xs) {\n" + - " X> x = (X>) xs;\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X> x = (X>) xs;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X> to X>\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - // check cast between generic types - public void test0404() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo(X xs) {\n" + - " X x = (X) xs;\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " X x = (X) xs;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - // check cast between generic types - public void test0405() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo(X> xs) {\n" + - " X> x = (X>) xs;\n" + - " }\n" + - " void bar(X xs) {\n" + - " X x = (X) xs;\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X> x = (X>) xs;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X> to X>\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " X x = (X) xs;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to X\n" + - "----------\n"); - } - - public void test0406() { - this.runConformTest( - new String[] { - "X.java", - "public abstract class X implements M {\n" + - " abstract M other();\n" + - " public S> entrySet() {\n" + - " return other().entrySet();\n" + - " }\n" + - "}\n" + - "interface M {\n" + - " interface E { }\n" + - " S> entrySet();\n" + - "}\n" + - "interface S {}", - }, - ""); - } - - public void test0407() { - this.runConformTest( - new String[] { - "X.java", - "public abstract class X implements M {\n" + - " abstract M other();\n" + - " public S> entrySet() {\n" + // qualified M.E... - " return other().entrySet();\n" + - " }\n" + - "}\n" + - "interface M {\n" + - " interface E { }\n" + - " S> entrySet();\n" + - "}\n" + - "interface S {}", - }, - ""); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78008 - public void test0408() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public Integer[] getTypes() {\n" + - " List list = new ArrayList();\n" + - " return list == null \n" + - " ? new Integer[0] \n" + - " : list.toArray(new Integer[list.size()]);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Class clazz = null;\n" + - " try {\n" + - " clazz = Class.forName(\"X\");\n" + - " System.out.println(\"SUCCESS\");\n" + - " } catch (Throwable e) {\n" + - " e.printStackTrace();\n" + - " }\n" + - " }\n" + - "}", - }, - "SUCCESS"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78008 - public void test0409() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public Number getTypes() {\n" + - " List list = new ArrayList();\n" + - " return list == null \n" + - " ? Float.valueOf(0)\n" + - " : list.get(0);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Class clazz = null;\n" + - " try {\n" + - " clazz = Class.forName(\"X\");\n" + - " System.out.println(\"SUCCESS\");\n" + - " } catch (Throwable e) {\n" + - " e.printStackTrace();\n" + - " }\n" + - " }\n" + - "}", - }, - "SUCCESS"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74178 - public void test0410() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - "public void write(List list) {\n" + - " \n" + - " list.add(new RuntimeException()); // works\n" + - " list.add(new IllegalMonitorStateException()); // works\n" + - " Exception exc = new Exception();\n" + - " list.add(exc); // works\n" + - " list.add(new Object()); // should fail\n" + - " list.add(new Throwable()); // should fail\n" + - " list.add(new Exception()); // works\n" + - "}\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " list.add(new Object()); // should fail\n" + - " ^^^\n" + - "The method add(capture#4-of ? super Exception) in the type List is not applicable for the arguments (Object)\n" + - "----------\n" + - "2. ERROR in X.java (at line 12)\n" + - " list.add(new Throwable()); // should fail\n" + - " ^^^\n" + - "The method add(capture#5-of ? super Exception) in the type List is not applicable for the arguments (Throwable)\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78015 - public void test0411() { - this.runConformTest( - new String[] { - "X.java", - "interface I {\n" + - " void m1(T t);\n" + - " void m2(T t);\n" + - "}\n" + - "\n" + - "class A {};\n" + - "\n" + - "class B implements I {\n" + - " public void m1(A a) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public void m2(A a) {}\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " m(new B());\n" + - " }\n" + - "\n" + - " public static void m(I x) {\n" + - " x.m1(null);\n" + - " }\n" + - "}", - }, - "SUCCESS"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78467 - public void test0412() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public static T first(T... args) {\n" + - " return args[0];\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " if (false) { \n" + - " String s = first(); \n" + - " int i; \n" + - " i++; \n" + - " }\n" + - " System.out.println(first(\"SUCCESS\", \"List\"));\n" + - " }\n" + - " Zork z;\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78467 - variation - public void test0412a() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - "\n" + - " public static T first(T... args) {\n" + - " return args[0];\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " if (false) { \n" + - " List ls = first(); \n" + - " int i; \n" + - " i++; \n" + - " }\n" + - " System.out.println(first(\"SUCCESS\", \"List\"));\n" + - " }\n" + - " Zork z;\n" + - "}", - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " List ls = first(); \n" + - " ^^^^^^^\n" + - "Type safety : A generic array of List is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - public void test0413() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class TLM {\n" + - " }\n" + - " TLM getMap(TL t) {\n" + - " return t.tls;\n" + - " }\n" + - " static TLM createInheritedMap(TLM parentMap) {\n" + - " return new TLM();\n" + - " } \n" + - "}\n" + - "\n" + - "class TL {\n" + - " X.TLM tls = null;\n" + - "}", - }, - ""); - } - - public void test0414() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(L l, C c) {\n" + - " bar(l, c);\n" + - " }\n" + - " void bar(L l, C c) { \n" + - " } \n" + - "}\n" + - "class C {}\n" + - "class L {}", - }, - ""); - } - - public void test0415() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public S> foo(HM hm) {\n" + - " return C.bar(hm).foo();\n" + - " }\n" + - "}\n" + - "class C {\n" + - " public static M bar(M m) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "class S {\n" + - "}\n" + - "abstract class HM implements M{\n" + - "}\n" + - "interface M {\n" + - " static class E {}\n" + - " S> foo(); \n" + - "}", - }, - ""); - } - - public void test0416() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public S> foo(HM hm) {\n" + - " M m = C.bar(hm);\n" + - " if (false) return m.foo();\n" + - " return C.bar(hm).foo();\n" + - " }\n" + - "}\n" + - "class C {\n" + - " public static M bar(M m) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "class S {\n" + - "}\n" + - "abstract class HM implements M{\n" + - "}\n" + - "interface M {\n" + - " static class E {}\n" + - " S> foo(); \n" + - "}", - }, - ""); - } - - public void test0417() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " X foo(X xt) {\n" + - " return null;\n" + - " }\n" + - " X identity() {\n" + - " return this;\n" + - " }\n" + - " void bar(X x) {\n" + - " X xs = foo(x).identity();\n" + - " }\n" + - "}\n", - }, - ""); - } - - public void test0418() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " X foo(X xt, X xt2) {\n" + - " return null;\n" + - " }\n" + - " X identity() {\n" + - " return this;\n" + - " }\n" + - " void bar(X x, X xs) {\n" + - " X xs2 = foo(x, xs).identity();\n" + - " }\n" + - "}\n", - }, - ""); - } - - public void test0419() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " X foo(X xt, X xt2) {\n" + - " return null;\n" + - " }\n" + - " X identity() {\n" + - " return this;\n" + - " }\n" + - " void bar(X x, X xs) {\n" + - " X xs2 = foo(x, xs).identity();\n" + - " }\n" + - "}\n", - }, - ""); - } - - public void test0420() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " X foo(X xt, X xt2) {\n" + - " return null;\n" + - " }\n" + - " X identity() {\n" + - " return this;\n" + - " }\n" + - " void bar(X x, X xs) {\n" + - " X xs2 = foo(x, xs).identity();\n" + - " }\n" + - "}\n", - }, - ""); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78863 - public void test0421() { - this.runConformTest( - new String[] { - "Test.java", - "import java.util.HashMap;\n" + - "import java.util.List;\n" + - "import java.util.Map;\n" + - "\n" + - "public class Test\n" + - "{\n" + - " protected Map, List> m_test\n" + - " = new HashMap, List>();\n" + - "}\n", - "Test2.java", - "import java.util.List;\n" + - "import java.util.Map;\n" + - "\n" + - "public class Test2 extends Test\n" + - "{\n" + - " public Map, List> test()\n" + - " {\n" + - " return m_test;\n" + - " }\n" + - "}\n", - }, - ""); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78704 - public void test0422() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " String foo() {\n" + - " return new X();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " return new X();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from X to String\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " return new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n"); - } - - public void test0423() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " static T bar() {\n" + - " return null;\n" + - " }\n" + - " static U foo() {\n" + - " return null;\n" + - " }\n" + - "\n" + - " public static void main(String argv[]) {\n" + - " bar();\n" + - " foo();\n" + - " }\n" + - "\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " foo();\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo() of type X is not applicable for the arguments (). The inferred type X is not a valid substitute for the bounded parameter \n" + - "----------\n"); - } - - public void test0424() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " T foo(T t) {\n" + - " return t;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().bar();\n" + - " }\n" + - " void bar() {\n" + - " B b = foo(new B());\n" + - " }\n" + - "}\n" + - "\n" + - "class A {}\n" + - "class B extends A {}\n" + - "\n", - }, - ""); - } - - // check tiebreak eliminates related generic methods which are less specific - public void test0425() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.IOException;\n" + - "\n" + - "public class X {\n" + - " static void m(E e) { System.out.println(\"A:\"+e.getClass()); }\n" + - " static void m(F f) throws Exception { System.out.println(\"B:\"+f.getClass()); }\n" + - " static void m(G g) throws IOException { System.out.println(\"C:\"+g.getClass()); }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " m(new A());\n" + - " m(new B());\n" + - " m(new C());\n" + - " }\n" + - "}\n" + - "\n" + - "class A {}\n" + - "class B extends A {}\n" + - "class C extends A {}\n" + - "\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " m(new B());\n" + - " ^^^^^^^^^^\n" + - "Unhandled exception type Exception\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " m(new C());\n" + - " ^^^^^^^^^^\n" + - "Unhandled exception type IOException\n" + - "----------\n"); - } - - // check inferred return types are truly based on arguments, and not on parameter erasures - public void test0426() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static E m(E e) { System.out.print(\"[A:\"+e.getClass()+\"]\"); return e; }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " A a = m(new A());\n" + - " B b = m(new B());\n" + - " C c = m(new C());\n" + - " }\n" + - "}\n" + - "\n" + - "class A {}\n" + - "class B extends A {}\n" + - "class C extends A {}\n", - }, - "[A:class A][A:class B][A:class C]"); - } - - // check inferred return types are truly based on arguments, and not on parameter erasures - public void test0427() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static E m(E e, E... e2) { System.out.print(\"[A:\"+e.getClass()+\"]\"); return e; }\n" + - " static F m(F f, F... f2) { System.out.print(\"[B:\"+f.getClass()+\"]\"); return f; }\n" + - " static G m(G g, G... g2) { System.out.print(\"[C:\"+g.getClass()+\"]\"); return g; }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " A a = m(new A(), new A());\n" + - " B b = m(new B(), new B());\n" + - " C c = m(new C(), new C());\n" + - " }\n" + - "}\n" + - "\n" + - "class A {}\n" + - "class B extends A {}\n" + - "class C extends A {}\n", - }, - "[A:class A][B:class B][C:class C]"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79390 - public void test0428() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Zork z;\n" + - " public static void foo() {\n" + - " class A {\n" + - " T t = null;\n" + - " T get() {\n" + - " return t;\n" + - " }\n" + - " }\n" + - " A a = new A() {\n" + - " @Override\n" + - " Long get() {\n" + - " return new Long(5);\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429() { - this.runConformTest( - new String[] { - "X1.java", - "class X1 > {}\n" + - "abstract class Y implements Comparable {}", - }, - "" - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429a() { - this.runConformTest( - new String[] { - "X2.java", - "class X2 > {}\n" + - "abstract class Y extends Z {}\n" + - "abstract class Z implements Comparable {}", - }, - "" - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429b() { - this.runConformTest( - new String[] { - "X3.java", - "class X3 > {}\n" + - "abstract class Y extends Z {}\n" + - "abstract class Z implements Comparable {}", - }, - "" - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429c() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X4.java", - "class X4 & Comparable> {}\n" + - "abstract class Y extends Z {}\n" + - "abstract class Z implements Comparable {}", - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X4.java (at line 1)\n" + - " class X4 & Comparable> {}\n" + - " ^^^^^^^^^^\n" + - "Duplicate bound Comparable\n" + - "----------\n", - // no complaints about duplicates if they are both parameterized with same args - // but you cannot extend Comparable & Comparable so we'll report an error - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429d() { - this.runNegativeTest( - new String[] { - "X5.java", - "class X5 > {}\n" + - "abstract class Y implements Comparable {}", - }, - "----------\n" + - "1. ERROR in X5.java (at line 1)\n" + - " class X5 > {}\n" + - " ^^^^^^^^^^\n" + - "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + - "----------\n" + - "2. WARNING in X5.java (at line 1)\n" + - " class X5 > {}\n" + - " ^^\n" + - "X5 is a raw type. References to generic type X5 should be parameterized\n" + - "----------\n" - // Comparable cannot be inherited with different arguments: and - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429e() { - this.runNegativeTest( - new String[] { - "X6.java", - "class X6 > {}\n" + - "abstract class Y extends Z {}\n" + - "abstract class Z implements Comparable {}", - }, - "----------\n" + - "1. ERROR in X6.java (at line 1)\n" + - " class X6 > {}\n" + - " ^^^^^^^^^^\n" + - "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + - "----------\n" + - "2. WARNING in X6.java (at line 1)\n" + - " class X6 > {}\n" + - " ^^\n" + - "X6 is a raw type. References to generic type X6 should be parameterized\n" + - "----------\n" - // Comparable cannot be inherited with different arguments: and - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429f() { - this.runNegativeTest( - new String[] { - "X7.java", - "class X7 & Comparable> {}\n" + - "abstract class Y extends Z {}\n" + - "abstract class Z implements Comparable {}", - }, - "----------\n" + - "1. ERROR in X7.java (at line 1)\n" + - " class X7 & Comparable> {}\n" + - " ^^^^^^^^^^\n" + - "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + - "----------\n" + - "2. WARNING in X7.java (at line 1)\n" + - " class X7 & Comparable> {}\n" + - " ^^\n" + - "X7 is a raw type. References to generic type X7 should be parameterized\n" + - "----------\n" - // Comparable cannot be inherited with different arguments: and - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 - public void test0429g() { - this.runNegativeTest(new String[] { - "X.java", - "interface I {}\n" + - "\n" + - "class A implements I, I {}\n" + - "public class X & I> {\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " class A implements I, I {}\n" + - " ^\n" + - "Duplicate interface I for the type A\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " public class X & I> {\n" + - " ^\n" + - "The interface I cannot be implemented more than once with different arguments: I and I\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " public class X & I> {\n" + - " ^\n" + - "Duplicate bound I\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79797 - public void test0430() { - this.runConformTest( - new String[] { - "p/MMM.java", - "package p;\n" + - "public interface MMM< F extends MMM, G extends NNN> { } \n", - "p/NNN.java", - "package p;\n" + - "public interface NNN { } \n", - }, - ""); - - this.runConformTest( - new String[] { - "X.java", - "import p.MMM;\n" + - "import p.NNN;\n" + - "\n" + - "interface RRR< A extends MMM, B extends NNN> {}\n" + - "\n" + - "class J1 implements MMM { }\n" + - "class J2 implements NNN { }\n" + - "\n" + - "class J3 implements RRR {} \n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " J3 thing = null;\n" + - " }\n" + - "}\n", - }, - "", - null, - false, // do not flush output - null); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79891 - public void test0431() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " private class Element {\n" + - " }\n" + - " public X() {\n" + - " Element[] eArray = new Element[10];\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Element[] eArray = new Element[10];\n" + - " ^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of X.Element\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79891 - public void test0432() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " private static class Element {\n" + - " }\n" + - " public X() {\n" + - " Element[] eArray = new Element[10];\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80144 - public void test0433() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "interface Alpha<\n" + - " A1 extends Alpha, \n" + - " B1 extends Beta> {\n" + - "}\n" + - "interface Beta<\n" + - " A2 extends Alpha, \n" + - " B2 extends Beta> {\n" + - "}\n" + - "interface Phi<\n" + - " A3 extends Alpha, \n" + - " B3 extends Beta> {\n" + - " \n" + - " public void latinize(A3 s);\n" + - "}\n" + - "\n" + - "public class X<\n" + - " A extends Alpha, \n" + - " B extends Beta, \n" + - " P extends Phi> extends ArrayList

implements Phi {\n" + - " \n" + - " public final void latinize(A a) {\n" + - " frenchify(this, a); // (X, A)\n" + - " }\n" + - " // -----------------------------------------------------------------\n" + - " public static final , BB extends Beta> \n" + - " void frenchify(Collection< ? extends Phi> phis, AA aa) {\n" + - " for (final Phi phi : phis)\n" + - " phi.latinize(aa);\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80083 - public void test0434() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "\n" + - "public class X\n" + - "{\n" + - "\n" + - " public static void main(String[] args)\n" + - " {\n" + - " ArrayList l = new ArrayList();\n" + - " l.add(\"x\");\n" + - " String s = \"\";\n" + - " s += l.get(0); // X\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "\n" + - "}\n", - }, - "SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80765 - public void test0435() { - this.runNegativeTest( - new String[] { - "Test.java",//=============================== - "import java.lang.reflect.InvocationTargetException;\n" + - "import java.lang.reflect.Method;\n" + - "\n" + - "import orders.DiscreteOrder;\n" + - "import orders.impl.IntegerOrder;\n" + - "import orders.impl.IntegerOrder2;\n" + - "\n" + - "public class Test {\n" + - "\n" + - " public static void main(String[] args) throws SecurityException,\n" + - " NoSuchMethodException, IllegalArgumentException,\n" + - " IllegalAccessException {\n" + - " Test test = new Test();\n" + - "\n" + - " for (String method : new String[] { \"test01\", \"test02\", \"test03\", \"test04\" }) {\n" + - " Method m = test.getClass().getMethod(method);\n" + - " try {\n" + - " m.invoke(test);\n" + - " System.out.print(\"*** \" + m + \": success\");\n" + - " } catch (InvocationTargetException e) {\n" + - " System.out.print(\"*** \" + m + \": failed, stacktrace follows\");\n" + - " e.getCause().printStackTrace(System.out);\n" + - " }\n" + - " }\n" + - " }\n" + - "\n" + - " public void test01() { // works\n" + - " new IntegerOrder().next(new Integer(0)); // works\n" + - " }\n" + - "\n" + - " public void test02() { // doesn\'t work\n" + - " final DiscreteOrder order = new IntegerOrder();\n" + - " order.next(new Integer(0));\n" + - " }\n" + - "\n" + - " public void test03() { // works\n" + - " new IntegerOrder2().next(new Integer(0)); // works\n" + - " }\n" + - "\n" + - " public void test04() { // doesn\'t work\n" + - " final DiscreteOrder order = new IntegerOrder2();\n" + - " order.next(new Integer(0));\n" + - " }\n" + - "}\n", - "orders/DiscreteOrder.java",//=============================== - "package orders;\n" + - "public interface DiscreteOrder> {\n" + - " /**\n" + - " * @return The element immediately before element in the\n" + - " * discrete ordered space.\n" + - " */\n" + - " public E previous(E element);\n" + - " /**\n" + - " * @return The element immediately after element in the\n" + - " * discrete ordered space.\n" + - " */\n" + - " public E next(E element);\n" + - "}\n", - "orders/impl/IntegerOrder.java",//=============================== - "package orders.impl;\n" + - "import orders.DiscreteOrder;\n" + - "\n" + - "public class IntegerOrder implements DiscreteOrder {\n" + - "\n" + - " public IntegerOrder() {\n" + - " super();\n" + - " }\n" + - "\n" + - " public Integer previous(Integer arg0) {\n" + - " return new Integer(arg0.intValue() - 1);\n" + - " }\n" + - "\n" + - " public Integer next(Integer arg0) {\n" + - " return new Integer(arg0.intValue() + 1);\n" + - " }\n" + - "}\n", - "orders/impl/IntegerOrder2.java",//=============================== - "package orders.impl;\n" + - "\n" + - "\n" + - "public class IntegerOrder2 extends IntegerOrder {\n" + - "\n" + - " public IntegerOrder2() {\n" + - " super();\n" + - " }\n" + - "\n" + - " public Comparable previous(Comparable arg0) {\n" + - " return previous((Integer) arg0);\n" + - " }\n" + - "\n" + - " public Comparable next(Comparable arg0) {\n" + - " return next((Integer) arg0);\n" + - " }\n" + - "\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in orders\\impl\\IntegerOrder2.java (at line 10)\n" + - " public Comparable previous(Comparable arg0) {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "2. ERROR in orders\\impl\\IntegerOrder2.java (at line 10)\n" + - " public Comparable previous(Comparable arg0) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method previous(Comparable) of type IntegerOrder2 has the same erasure as previous(E) of type DiscreteOrder but does not override it\n" + - "----------\n" + - "3. WARNING in orders\\impl\\IntegerOrder2.java (at line 10)\n" + - " public Comparable previous(Comparable arg0) {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "4. WARNING in orders\\impl\\IntegerOrder2.java (at line 14)\n" + - " public Comparable next(Comparable arg0) {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "5. ERROR in orders\\impl\\IntegerOrder2.java (at line 14)\n" + - " public Comparable next(Comparable arg0) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method next(Comparable) of type IntegerOrder2 has the same erasure as next(E) of type DiscreteOrder but does not override it\n" + - "----------\n" + - "6. WARNING in orders\\impl\\IntegerOrder2.java (at line 14)\n" + - " public Comparable next(Comparable arg0) {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" - // "*** public void Test.test01(): success*** public void Test.test02(): success*** public void Test.test03(): success*** public void Test.test04(): success" - // name clash: next(java.lang.Comparable) in orders.impl.IntegerOrder2 and next(E) in orders.DiscreteOrder have the same erasure, yet neither overrides the other - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80028 - public void test0436() { - this.runConformTest( - new String[] { - "A.java", - "public class A {\n" + - " public static void main(String[] args) {\n" + - " Number n= new Integer(1);\n" + - " X x = new X();\n" + - " x.m(n);\n" + - " x.m(new Integer(2));\n" + - " Y y= new Y();\n" + - " y.m(n);\n" + - " y.m(new Integer(2));\n" + - " }\n" + - "}\n", - "X.java", - "class X {\n" + - " public void m(Number num) { System.out.print(\"X.m(Number) = \" + num + ','); }\n" + - " public void m(T t) { System.out.print(\"X.m(T) = \" + t + ','); }\n" + - "}\n", - "Y.java", - "class Y extends X {\n" + - " public void m(Number num) { System.out.print(\"Y.m(Number) = \" + num + ','); }\n" + - "}\n", - }, - "X.m(Number) = 1,X.m(Number) = 2,Y.m(Number) = 1,Y.m(Number) = 2,"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80028 - public void test0437() { - this.runConformTest( - new String[] { - "A.java", - "public class A {\n" + - " public static void main(String[] args) {\n" + - " Number n= new Integer(1);\n" + - " X x = new X();\n" + - " x.m(n);\n" + - " x.m(new Integer(2));\n" + - " Y y= new Y();\n" + - " y.m(n);\n" + - " y.m(new Integer(2));\n" + - " }\n" + - "}\n", - "X.java", - "class X {\n" + - " public void m(Number num) { System.out.print(\"X.m(Number) = \" + num + ','); }\n" + - " public void m(T t) { System.out.print(\"X.m(T) = \" + t + ','); }\n" + - "}\n", - "Y.java", - "class Y extends X {\n" + - " public void m(Number num) { System.out.print(\"Y.m(Number) = \" + num + ','); }\n" + - "}\n", - }, - "X.m(Number) = 1,X.m(Number) = 2,Y.m(Number) = 1,Y.m(Number) = 2,"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78591 - public void test0438() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " Zork z;\n" + - " List list;\n" + - " void add(Object abs) {\n" + - " list.add((T) list.get(0)); // checked cast\n" + - " list.add((T) abs); // unchecked cast\n" + - " }\n" + - " void bar(List other) {\n" + - " list.add((T) other.get(0)); // checked cast\n" + - " }\n" + - " void baz(List other) {\n" + - " list.add((T) other.get(0)); // unchecked cast\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " list.add((T) list.get(0)); // checked cast\n" + - " ^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from T to T\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " list.add((T) abs); // unchecked cast\n" + - " ^^^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "4. WARNING in X.java (at line 10)\n" + - " list.add((T) other.get(0)); // checked cast\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from capture#1-of ? extends T to T\n" + - "----------\n" + - "5. WARNING in X.java (at line 13)\n" + - " list.add((T) other.get(0)); // unchecked cast\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from capture#2-of ? super T to T\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78592 - public void test0439() { - this.runNegativeTest( - new String[] { - "X.java", - "class Node {\n" + - "}\n" + - "class Composite {\n" + - "}\n" + - "class Concrete extends Composite {\n" + - "}\n" + - "public class X {\n" + - " Composite comp = new Concrete(); // unchecked cast\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " class Concrete extends Composite {\n" + - " ^^^^^^^^^\n" + - "Composite is a raw type. References to generic type Composite should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " Composite comp = new Concrete(); // unchecked cast\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Concrete needs unchecked conversion to conform to Composite\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - public void test0440() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class Y {\n" + - " public void foo(X xt) {\n" + - " U u = (U) xt;\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " U u = (U) xt;\n" + - " ^^^^^^\n" + - "Type safety: Unchecked cast from X to U\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - public void test0441() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T[] array;\n" + - " X(int s) {\n" + - " array = (T[]) new Number[s]; // Unnecessary cast from Number[] to T[]\n" + - " array = new Number[s]; // Type mismatch: cannot convert from Number[] to T[]\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " array = (T[]) new Number[s]; // Unnecessary cast from Number[] to T[]\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Number[] to T[]\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " array = new Number[s]; // Type mismatch: cannot convert from Number[] to T[]\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Number[] to T[]\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82053 - public void test0442() { - this.runConformTest( - new String[] { - "X.java", - "class Foo {\n" + - " public interface Model {\n" + - " }\n" + - " public interface View {\n" + - " M getTarget() ;\n" + - " }\n" + - "}\n" + - "class Bar {\n" + - " public interface Model extends Foo.Model {\n" + - " }\n" + - " public interface View extends Foo.View {\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public void baz() {\n" + - " Bar.View bv = null ;\n" + - " Bar.Model m = bv.getTarget() ;\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81757 - public void test0443() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "public class X implements Iterator {\n" + - " public boolean hasNext() { return false; }\n" + - " public String next() { return null; }\n" + - " public void remove() {}\n" + - "}\n", - }, - ""); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81824 - public void test0444() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X implements I, I {}\n" + - "interface I {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X implements I, I {}\n" + - " ^\n" + - "The interface I cannot be implemented more than once with different arguments: I and I\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78810 - public void test0445() { - this.runNegativeTest( - new String[] { - "X.java", - "public abstract class X {\n" + - " public abstract Object getProperty(final Object src, final String name);\n" + - " Zork z;\n" + - " public T getTheProperty(final Object src, final String name)\n" + - " {\n" + - " final T val = (T) getProperty(src, name); // this gives erroneous cast warning\n" + - " return val;\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " final T val = (T) getProperty(src, name); // this gives erroneous cast warning\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - public void test0446() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class Inner { }\n" + - "\n" + - " void method() {\n" + - " X.Inner a= new X().new Inner();\n" + - " Inner b= new X().new Inner();\n" + - " Inner c= new Inner();\n" + - " // OK\n" + - "\n" + - " X.Inner d= new X.Inner();\n" + - " //eclipse: OK\n" + - " //other: error: \'(\' or \'[\' expected\n" + - "\n" + - " X.Inner e= new X().new Inner();\n" + - " X.Inner f= new Inner();\n" + - " e= b;\n" + - " f= c;\n" + - " //other: OK\n" + - " //eclipse: Type mismatch: cannot convert from X.Inner to X.Inner\n" + - "\n" + - " }\n" + - "}\n" + - "\n" + - "class External {\n" + - " void m() {\n" + - " X.Inner x= new X().new Inner();\n" + - " // OK\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " X.Inner d= new X.Inner();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + - "----------\n", - JavacTestOptions.EclipseHasABug.EclipseBug236243); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation - public void test0447() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class Inner { }\n" + - "\n" + - " void method() {\n" + - " X.Inner d1 = new X.Inner();\n" + - " X.Inner d2 = new X.Inner();\n" + - " X.Inner d3 = new X.Inner();\n" + - " d1 = d2;\n" + - " d2 = d1;\n" + - " d1 = d3;\n" + - " d3 = d1;\n" + - " d2 = d3;\n" + - " d3 = d2;\n" + - "\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " X.Inner d1 = new X.Inner();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " X.Inner d2 = new X.Inner();\n" + - " ^^^^^^^\n" + - "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " X.Inner d2 = new X.Inner();\n" + - " ^^^^^^^\n" + - "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " X.Inner d3 = new X.Inner();\n" + - " ^^^^^^^\n" + - "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "5. ERROR in X.java (at line 7)\n" + - " X.Inner d3 = new X.Inner();\n" + - " ^^^^^^^\n" + - "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "6. WARNING in X.java (at line 8)\n" + - " d1 = d2;\n" + - " ^^\n" + - "Type safety: The expression of type X.Inner needs unchecked conversion to conform to X.Inner\n" + - "----------\n" + - "7. ERROR in X.java (at line 10)\n" + - " d1 = d3;\n" + - " ^^\n" + - "Type mismatch: cannot convert from X.Inner to X.Inner\n" + - "----------\n" + - "8. ERROR in X.java (at line 11)\n" + - " d3 = d1;\n" + - " ^^\n" + - "Type mismatch: cannot convert from X.Inner to X.Inner\n" + - "----------\n" + - "9. WARNING in X.java (at line 13)\n" + - " d3 = d2;\n" + - " ^^\n" + - "Type safety: The expression of type X.Inner needs unchecked conversion to conform to X.Inner\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation - public void test0448() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Inner { }\n" + - "\n" + - " void method() {\n" + - " X.Inner d = new X.Inner(); \n" + - " }\n" + - "}\n", - }, - ""); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation - public void test0448a() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " class Y {}\n" + - " X.Y[] tab = new X.Y[] {};\n" + - "}" - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); - } - - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation - public void test0449() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class Inner { \n" + - " }\n" + - "\n" + - " void method() {\n" + - " X.Inner d4 = new X.Inner();\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X.Inner d4 = new X.Inner();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.Inner to X.Inner\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " X.Inner d4 = new X.Inner();\n" + - " ^^^^^^^\n" + - "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation - public void test0450() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Inner { \n" + - " }\n" + - "\n" + - " void method() {\n" + - " X.Inner d4 = new X.Inner();\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X.Inner d4 = new X.Inner();\n" + - " ^^^^^^^^^^^^^^^\n" + - "The member type X.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " X.Inner d4 = new X.Inner();\n" + - " ^^^^^^^^^^^^^^^\n" + - "The member type X.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation - public void test0451() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class Inner { \n" + - " }\n" + - "\n" + - " void method() {\n" + - " X.Inner d4 = new X.Inner() {};\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X.Inner d4 = new X.Inner() {};\n" + - " ^^^^^^^^^^^^^^^\n" + - "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + - "----------\n", - JavacTestOptions.EclipseHasABug.EclipseBug236243); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82187 - public void test0452() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " \n" + - " public > S test01(S param){\n" + - " System.out.println(\"SUCCESS\");\n" + - " return null;\n" + - " }\n" + - " \n" + - " public void test02() {\n" + - " test01(new Vector());\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X().test02();\n" + - " }\n" + - "}\n" , - }, - "SUCCESS"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82250 - public void test0453() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {}\n" + - "interface I {}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {}\n" + - " ^\n" + - "Duplicate bound I\n" + - "----------\n" - ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82504 - public void test0454() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Object[] objectArr;\n" + - " void foo(T t) {\n" + - " T x1= (T) objectArr;\n" + - " U x2= (U) objectArr;\n" + - " int[] x= (int[]) t;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " T x1= (T) objectArr;\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object[] to T\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " U x2= (U) objectArr;\n" + - " ^^^^^^^^^^^^^\n" + - "Cannot cast from Object[] to U\n" + - "----------\n"); - } - - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81719 - public void test0455() { - this.runConformTest( - new String[] { - "AbstractTest.java", - "public abstract class AbstractTest {\n" + - " abstract void array(T[] a);\n" + - " abstract void type(T a);\n" + - " abstract T[] foo();\n" + - "}\n", - }, - ""); - - this.runConformTest( - new String[] { - "Test.java", - "public class Test extends AbstractTest {\n" + - " void array(T[] a) {}\n" + - " void type(T a) {}\n" + - " T[] foo() { return null; }\n" + - "}\n", - }, - "", - null, - false, // do not flush output - null); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81721 - public void test0456() { - this.runConformTest( - new String[] { - "X.java", - "interface I {\n" + - " void doTest(S[] a);\n" + - "}\n" + - "\n" + - "abstract class AbstractTest implements I {\n" + - " public void doTest(V[] a) {}\n" + - "}\n" + - "\n" + - "public class X extends AbstractTest {}\n", - }, - ""); - } - - public void test0457() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " \n" + - " void add(List l) { \n" + - " l.add(new X()); \n" + - " }\n" + - " void add2(List l) { \n" + - " l.add(new X()); \n" + - " }\n" + - " \n" + - " static void add3(List l, List l2) { \n" + - " }\n" + - " public static void main(String[] args) {\n" + - " List lx = null;\n" + - " List ls = null;\n" + - " add3(lx, ls);\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " l.add(new X()); \n" + - " ^^^\n" + - "The method add(capture#2-of ? extends X) in the type List is not applicable for the arguments (X)\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " add3(lx, ls);\n" + - " ^^^^\n" + - "The method add3(List, List) in the type X is not applicable for the arguments (List, List)\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82243 - public void test0458() { - this.runNegativeTest( - new String[] { - "X.java", - "interface A{\n" + - " E getOne();\n" + - "}\n" + - "\n" + - "\n" + - "abstract class B implements A {\n" + - " Number getTwo() {\n" + - " return getOne(); // succeeds\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class C extends B {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " void foo(A a, B b, C c){\n" + - " Object o= a.getOne();\n" + - " Number n1= b.getOne(); // fails\n" + - " Number n2= b.getTwo(); // succeeds, but inlining fails\n" + - " Integer i = c.getOne(); // succeeds\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 16)\n" + - " void foo(A a, B b, C c){\n" + - " ^\n" + - "A is a raw type. References to generic type A should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 16)\n" + - " void foo(A a, B b, C c){\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 18)\n" + - " Number n1= b.getOne(); // fails\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to Number\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78027 - variation (check unchecked warnings) - public void test0459() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X \n" + - "{\n" + - "Zork z;\n" + - "}\n" + - "\n" + - "interface ITest\n" + - "{ \n" + - "}\n" + - "\n" + - "abstract class Test implements ITest\n" + - "{\n" + - " protected Manager m_manager;\n" + - " \n" + - " public ITest get()\n" + - " {\n" + - " return m_manager.getById(getClass(), new Integer(1));\n" + - " }\n" + - " \n" + - " public static class Manager\n" + - " {\n" + - " public > T getById(Class cls, Integer id)\n" + - " {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 16)\n" + - " return m_manager.getById(getClass(), new Integer(1));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation getById(Class, Integer) of the generic method getById(Class, Integer) of type Test.Manager\n" + - "----------\n" + - "3. WARNING in X.java (at line 16)\n" + - " return m_manager.getById(getClass(), new Integer(1));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type capture#1-of ? extends Test needs unchecked conversion to conform to ITest\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82439 - public void test0460() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public > S test(S param) {\n" + - " \n" + - " Class c = param.getClass(); // ok\n" + - " Class d = getClazz(); // ko\n" + - " return null;\n" + - " }\n" + - " Class getClazz() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "abstract class Z implements Collection {\n" + - " void foo() {\n" + - " Class c = getClass(); // ok\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " Class c = param.getClass(); // ok\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " Class d = getClazz(); // ko\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " Class d = getClazz(); // ko\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n" + - "4. WARNING in X.java (at line 17)\n" + - " Class c = getClass(); // ok\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82844 - public void test0461() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^\n" + - "The array type int[] cannot be used as a type parameter bound\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79628 - public void test0462() { - this.runConformTest( - new String[] { - "PropertiedObject.java", - "interface PropertiedObject> {}\n" + - "interface Model extends PropertiedObject {}\n" + - "interface View extends PropertiedObject> {}\n" - }, - ""); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79144 - public void test0463() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Set;\n" + - "public class X {\n" + - " Zork z;\n" + - " public Set[] test() {\n" + - " Set[] sets = new Set[10];\n" + - " return sets;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " Set[] sets = new Set[10];\n" + - " ^^^\n" + - "Set is a raw type. References to generic type Set should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " return sets;\n" + - " ^^^^\n" + - "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79144 - public void test0464() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Zork z;\n" + - " public static void main(String[] args) {\n" + - " List[] nums = new List[] {Collections.singletonList(\"Uh oh\")};\n" + - " System.out.println(nums[0].get(0).intValue());\n" + - " } \n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " List[] nums = new List[] {Collections.singletonList(\"Uh oh\")};\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type List[] needs unchecked conversion to conform to List[]\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82547 - public void test0465() { - this.runNegativeTest( - new String[] { - "Cla.java", - "class Cla {\n" + - " T getT() {\n" + - " return null;\n" + - " }\n" + - " \n" + - " void m() {\n" + - " String s= new Cla.getT();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in Cla.java (at line 7)\n" + - " String s= new Cla.getT();\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Cla.getT cannot be resolved to a type\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83096 - public void test0466() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X { }\n" + - " ^\n" + - "Duplicate type parameter A\n" + - "----------\n" - ); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - public void test0467() { - this.runConformTest( - new String[] { - "test/Foo.java", - "package test; \n" + - "public class Foo { \n" + - " protected String s; \n" + - " protected String dosomething(){ return \"done\"; } \n" + - " protected class Bar {} \n" + - "} \n", - "test02/FooBar.java", - "package test02; \n" + - "import test.Foo; \n" + - "public class FooBar extends Foo { \n" + - " void fail() { \n" + - " FooBar f = new FooBar(); \n" + - " f.s = \"foo\"; \n" + - " this.s = \"foo\";\n" + - " f.dosomething(); \n" + - " this.dosomething(); \n" + - " Bar b1; \n" + - " FooBar.Bar b2; \n" + - " Foo.Bar b3; \n" + - " } \n" + - "}\n" - }, - "" - ); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation - public void test0468() { - this.runConformTest( - new String[] { - "test/Foo.java", - "package test; \n" + - "public class Foo { \n" + - " String s; \n" + - " String dosomething(){ return \"done\"; } \n" + - " class Bar {} \n" + - "} \n", - "test/FooBar.java", - "package test; \n" + - "import test.Foo; \n" + - "public class FooBar extends Foo { \n" + - " void fail() { \n" + - " FooBar f = new FooBar(); \n" + - " f.s = \"foo\"; \n" + - " this.s = \"foo\";\n" + - " f.dosomething(); \n" + - " this.dosomething(); \n" + - " Bar b1; \n" + - " FooBar.Bar b2; \n" + - " Foo.Bar b3; \n" + - " } \n" + - "}\n" - }, - "" - ); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83083 - public void test0469() { - this.runConformTest( - new String[] { - "a/C.java", - "package a; \n" + - "import p.B; \n" + - "public class C extends B { \n" + - " public void foo(Object obj) {} \n" + - "} \n", - "p/B.java", - "package p; \n" + - "public class B extends A {} \n", - "p/A.java", - "package p; \n" + - "public class A { \n" + - " public void foo(E e) {} \n" + - "}\n", - }, - "" - ); - this.runConformTest( - new String[] { - "a/C.java", - "package a; \n" + - "import p.B; \n" + - "public class C extends B { \n" + - " public void foo(Object obj) {} \n" + - "} \n", - "p/A.java", - "package p; \n" + - "public class A { \n" + - " public void foo(E e) {} \n" + - "}\n", - }, - "", - null, - false, // do not flush output - null); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83225 - public void test0470() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static T choose(boolean b, T t1, T t2) {\n" + - " if (b)\n" + - " return t1;\n" + - " return t2;\n" + - " }\n" + - "\n" + - " public static void foo() {\n" + - " Comparable s1 = choose(true, \"string\", new Integer(1));\n" + - " Number s2 = choose(true, new Integer(1), new Float(2));\n" + - " Comparable s3 = choose(true, new Integer(1), new Float(2));\n" + - " Cloneable s4 = choose(true, new Integer(1), new Float(2));\n" + - " Cloneable s5 = choose(true, \"string\", new Integer(1));\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Comparable s1 = choose(true, \"string\", new Integer(1));\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " Comparable s3 = choose(true, new Integer(1), new Float(2));\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 12)\n" + - " Cloneable s4 = choose(true, new Integer(1), new Float(2));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Number&Comparable to Cloneable\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " Cloneable s5 = choose(true, \"string\", new Integer(1));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object&Serializable&Comparable to Cloneable\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation - public void test0471() { - this.runNegativeTest( - new String[] { - "test/Foo.java", - "package test; \n" + - "public class Foo { \n" + - " protected R s; \n" + - " protected R dosomething(){ return s; } \n" + - " protected class Bar {} \n" + - "} \n", - "test02/FooBar.java", - "package test02; \n" + - "import test.Foo; \n" + - "public class FooBar extends Foo { \n" + - " void fail() { \n" + - " FooBar f = new FooBar(); \n" + - " f.s = \"foo\"; \n" + - " this.s = \"foo\";\n" + - " f.dosomething(); \n" + - " this.dosomething(); \n" + - " Bar b1; \n" + - " FooBar.Bar b2; \n" + - " Foo.Bar b3; \n" + - " } \n" + - "}\n" - }, - "----------\n" + - "1. ERROR in test02\\FooBar.java (at line 7)\n" + - " this.s = \"foo\";\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from String to R\n" + - "----------\n" ); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation - public void test0472() { - this.runNegativeTest( - new String[] { - "test/Foo.java", - "package test; \n" + - "public class Foo { \n" + - " private R s; \n" + - " private R dosomething(){ return s; } \n" + - " private class Bar {} \n" + - "} \n", - "test02/FooBar.java", - "package test02; \n" + - "import test.Foo; \n" + - "public class FooBar extends Foo { \n" + - " void fail() { \n" + - " FooBar f = new FooBar(); \n" + - " f.s = \"foo\"; \n" + - " this.s = \"foo\";\n" + - " f.dosomething(); \n" + - " this.dosomething(); \n" + - " Bar b1; \n" + - " FooBar.Bar b2; \n" + - " Foo.Bar b3; \n" + - " } \n" + - "}\n" - }, - "----------\n" + - "1. WARNING in test\\Foo.java (at line 4)\n" + - " private R dosomething(){ return s; } \n" + - " ^^^^^^^^^^^^^\n" + - "The method dosomething() from the type Foo is never used locally\n" + - "----------\n" + - "2. WARNING in test\\Foo.java (at line 5)\n" + - " private class Bar {} \n" + - " ^^^\n" + - "The type Foo.Bar is never used locally\n" + - "----------\n" + - "----------\n" + - "1. ERROR in test02\\FooBar.java (at line 6)\n" + - " f.s = \"foo\"; \n" + - " ^\n" + - "The field Foo.s is not visible\n" + - "----------\n" + - "2. ERROR in test02\\FooBar.java (at line 7)\n" + - " this.s = \"foo\";\n" + - " ^\n" + - "The field Foo.s is not visible\n" + - "----------\n" + - "3. ERROR in test02\\FooBar.java (at line 8)\n" + - " f.dosomething(); \n" + - " ^^^^^^^^^^^\n" + - "The method dosomething() from the type Foo is not visible\n" + - "----------\n" + - "4. ERROR in test02\\FooBar.java (at line 9)\n" + - " this.dosomething(); \n" + - " ^^^^^^^^^^^\n" + - "The method dosomething() from the type Foo is not visible\n" + - "----------\n" + - "5. ERROR in test02\\FooBar.java (at line 10)\n" + - " Bar b1; \n" + - " ^^^\n" + - "The type Bar is not visible\n" + - "----------\n" + - "6. ERROR in test02\\FooBar.java (at line 11)\n" + - " FooBar.Bar b2; \n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "The type FooBar.Bar is not visible\n" + - "----------\n" + - "7. ERROR in test02\\FooBar.java (at line 12)\n" + - " Foo.Bar b3; \n" + - " ^^^^^^^^^^^^^^^\n" + - "The type Foo.Bar is not visible\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 - public void test0473() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X\n" + - "{\n" + - " List itsList;\n" + - " B itsB;\n" + - " MyTyped itsTyped;\n" + - " \n" + - " \n" + - " public void test()\n" + - " {\n" + - " method (itsList, itsB, itsTyped);\n" + - " }\n" + - " \n" + - " public void method (List arg1, T arg2, Typed arg3)\n" + - " {\n" + - " }\n" + - " \n" + - " interface A{}\n" + - " class B implements A{}\n" + - " class Typed{}\n" + - " class MyTyped extends Typed{}\n" + - "\n" + - "}\n" - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 - variation - public void test0474() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " Typed itsList;\n" + - " Typed itsTyped;\n" + - " public void test() {\n" + - " method(itsList, itsTyped);\n" + - " }\n" + - " public void method(Typed arg1, Typed arg3) {\n" + - " }\n" + - " interface A {\n" + - " }\n" + - " class B implements A {\n" + - " }\n" + - " class Typed {\n" + - " }\n" + - "}\n" - }, - ""); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - public void test0475() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void method(List list) {\n" + - " list.add(new Object()); // should fail\n" + - " list.add(new Integer(3)); // correct\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " list.add(new Object()); // should fail\n" + - " ^^^\n" + - "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (Object)\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation - public void test0476() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void method(List list, List lo) {\n" + - " list = lo;\n" + - " lo = list;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " lo = list;\n" + - " ^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation - public void test0477() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List lhs;\n" + - " List rhs;\n" + - " {\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#1-of ? super T) in the type List is not applicable for the arguments (capture#2-of ? extends Number)\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation - public void test0478() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List lhs;\n" + - " List rhs;\n" + - " {\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (capture#2-of ? super U)\n" + - "----------\n"); - } - - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation - public void test0479() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List lhs;\n" + - " List rhs;\n" + - " {\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - "}\n" - }, - ""); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation - public void test0480() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List lhs;\n" + - " List rhs;\n" + - " {\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#1-of ? super Integer) in the type List is not applicable for the arguments (capture#2-of ? extends Number)\n" + - "----------\n"); - } - - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation - public void test0481() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List lhs;\n" + - " List rhs;\n" + - " {\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (capture#2-of ? super Integer)\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83799 - public void test0482() { - this.runConformTest( - new String[] { - "X.java", - "public final class X {\n" + - " public void testEquals(final String x, T one, T two) {\n" + - " }\n" + - "\n" + - " public void testEqualsAlt(final String x, T1 one, T2 two) {\n" + - " }\n" + - "\n" + - " public interface Fooey {\n" + - " }\n" + - "\n" + - " public interface Bar extends Fooey {\n" + - " }\n" + - "\n" + - " public interface GenericFooey {\n" + - " }\n" + - "\n" + - " public interface GenericBar extends GenericFooey {\n" + - " }\n" + - "\n" + - " public void testGeneric() {\n" + - " testEquals(\"Should work\", new GenericBar() {\n" + - " }, new GenericBar() {\n" + - " });\n" + - " final GenericBar child = new GenericBar() {\n" + - " };\n" + - " final GenericFooey parent = child;\n" + - " testEquals(\"Doesn\'t work but should\", child, parent); // this\n" + - " // fails\n" + - " // but should work it\'s identical to next line.\n" + - " testEquals(\"Doesn\'t work but should\", (GenericFooey) child, parent);\n" + - " testEqualsAlt(\"Should work\", child, parent);\n" + - " }\n" + - " public void test() {\n" + - " testEquals(\"Should work\", new Bar() {\n" + - " }, new Bar() {\n" + - " });\n" + - " final Bar child = new Bar() {\n" + - " };\n" + - " final Fooey parent = child;\n" + - " testEquals(\"Doesn\'t work but should\", child, parent);\n" + - " testEquals(\"Doesn\'t work but should\", (Fooey) child, parent);\n" + - " testEqualsAlt(\"Should work\", child, parent);\n" + - " }\n" + - "}\n" - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83904 - public void test0483() { - this.runNegativeTest( - new String[] { - "X.java", - "class Y {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " m(new Y(), new Y());\n" + - " }\n" + - "\n" + - " public static void m(Y x, Y y) {\n" + - " }\n" + - "}\n" + - "\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " m(new Y(), new Y());\n" + - " ^\n" + - "The method m(Y, Y) in the type X is not applicable for the arguments (Y, Y)\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - public void test0484() { - this.runConformTest( - new String[] { - "X.java", - "class Base {\n" + - " public class Inner {\n" + - " }\n" + - " Inner a;\n" + - "}\n" + - "\n" + - "public class X extends Base {\n" + - " class DerivedInner extends Inner {\n" + - " }\n" + - " X() {\n" + - " a = new DerivedInner();\n" + - " }\n" + - "}\n" - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - variation - public void test0485() { - this.runConformTest( - new String[] { - "X.java", - "class Base {\n" + - " public class Inner {\n" + - " }\n" + - " Inner a;\n" + - "}\n" + - "\n" + - "public class X extends Base {\n" + - " class DerivedInner extends Inner {\n" + - " }\n" + - " X() {\n" + - " a = new DerivedInner();\n" + - " }\n" + - "}\n" - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - variation - public void test0486() { - this.runConformTest( - new String[] { - "X.java", - "class Base {\n" + - " public class Inner {\n" + - " }\n" + - " Inner a;\n" + - "}\n" + - "\n" + - "public class X extends Base {\n" + - " class DerivedInner extends Inner {\n" + - " }\n" + - " X() {\n" + - " a = new DerivedInner();\n" + - " }\n" + - "}\n" - }, - ""); - } - public void test0487() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " void foo(List ls) {\n" + - " List l = ls;\n" + - " bar(l, \"\"); \n" + - " }\n" + - " void bar(List l, T t) {\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " bar(l, \"\"); \n" + - " ^^^\n" + - "The method bar(List, T) in the type X is not applicable for the arguments (List, String)\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - public void test0488() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f1 = new Foo();\n" + - " Foo f2 = new Foo();\n" + - " f1.bar = f2.bar;\n" + - " }\n" + - " static class Foo {\n" + - " Bar bar = new Bar();\n" + - " }\n" + - " static class Bar {\n" + - " T t;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " f1.bar = f2.bar;\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from X.Bar to X.Bar\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - public void test0489() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f1 = new Foo();\n" + - " f1.bar = f1.bar;\n" + - " }\n" + - " static class Foo {\n" + - " Bar bar = new Bar();\n" + - " }\n" + - " static class Bar {\n" + - " T t;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " f1.bar = f1.bar;\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from X.Bar to X.Bar\n" + - "----------\n"); - } - public void test0490() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " void foo(X lhs, X rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - " void bar(X> lhs, X> rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }}\n" + - "\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " lhs.t = rhs.t;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from capture#4-of ? to capture#3-of ?\n" + - "----------\n"); - } - - public void test0491() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T t;\n" + - " void foo(X lhs, X rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - " void bar(X> lhs, X> rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - " void baz(X lhs, X rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - " void baz2(X lhs, X rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - " void baz3(X lhs, X rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - " void baz4(X lhs, X rhs) {\n" + - " lhs = rhs;\n" + - " lhs.t = rhs.t;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " lhs.t = rhs.t;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from capture#4-of ? to capture#3-of ?\n" + - "----------\n" + - "2. ERROR in X.java (at line 12)\n" + - " lhs = rhs;\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n" + - "3. ERROR in X.java (at line 17)\n" + - " lhs.t = rhs.t;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from capture#14-of ? extends Number to capture#13-of ? extends Number\n" + - "----------\n" + - "4. ERROR in X.java (at line 20)\n" + - " lhs = rhs;\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n" + - "5. ERROR in X.java (at line 21)\n" + - " lhs.t = rhs.t;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from capture#18-of ? super Number to capture#17-of ? extends Number\n" + - "----------\n" + - "6. ERROR in X.java (at line 25)\n" + - " lhs.t = rhs.t;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from capture#22-of ? super Number to capture#21-of ? super Number\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81576 - public void test0492() { - this.runConformTest( - new String[] { - "SuperType.java",//==================================== - "public class SuperType {\n" + - " protected InnerType valueWrapper;\n" + - " protected class InnerType {\n" + - " private T value;\n" + - " protected InnerType(T value) {\n" + - " this.value = value;\n" + - " }\n" + - " }\n" + - " public SuperType(T value) {\n" + - " /*\n" + - " * This constructor exists only to show that the usage of the inner\n" + - " * class within its enclosing class makes no problems\n" + - " */\n" + - " this.valueWrapper = new InnerType(value);\n" + - " }\n" + - " protected SuperType() {\n" + - " // Provided for the convenience of subclasses\n" + - " }\n" + - "}\n", - "SubType.java",//==================================== - "public class SubType extends SuperType {\n" + - "\n" + - " public SubType(T value) {\n" + - "\n" + - " /* The constructor SuperType .InnerType(T) is undefined */\n" + - " InnerType localValueWrapper = new InnerType(value);\n" + - "\n" + - " /*\n" + - " * Type mismatch: cannot convert from SuperType .InnerType to\n" + - " * SuperType .InnerType\n" + - " * \n" + - " * Type safety: The expression of raw type SuperType.InnerType is\n" + - " * converted to SuperType .InnerType. References to generic type\n" + - " * SuperType .InnerType should be parametrized.\n" + - " */\n" + - " localValueWrapper = super.valueWrapper;\n" + - " }\n" + - "\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83611 - public void test0493() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public class M { M(Class templateClass) {} }\n" + - "}\n", - "Y.java", - "public class Y extends X {\n" + - " void test() { M m = new M(X.class); }\n" + - "}\n" - }, - "" - ); - this.runConformTest( - new String[] { - "Y.java", - "public class Y extends X {\n" + - " void test() { M m = new M(X.class); }\n" + - "}\n" - }, - "", - null, - false, - null - ); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83615 - public void test0494() { - this.runNegativeTest( - new String[] { - "X.java",//==================================== - "public class X {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " Number n= null;\n" + - " Integer i= null;\n" + - " new X().nextTry(i, n);\n" + - " new X().nextTry2(n, i);\n" + - " } \n" + - " \n" + - " void nextTry(I i, N n) {}\n" + - " \n" + - " void nextTry2(N n, I i) {} \n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " new X().nextTry(i, n);\n" + - " ^^^^^^^\n" + - "Bound mismatch: The generic method nextTry(I, N) of type X is not applicable for the arguments (Integer, Number). The inferred type Number is not a valid substitute for the bounded parameter \n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84422 - public void test0495() { - this.runConformTest( - new String[] { - "X.java",//==================================== - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " List l= null; \n" + - "\n" + - " void add(String s) {\n" + - " l.add(s);\n" + - " }\n" + - " \n" + - " void addAll(String[] ss) {\n" + - " l.addAll(Arrays.asList(ss));\n" + - " }\n" + - " \n" + - " String[] get() {\n" + - " return (String[])l.toArray(new String[l.size()]);\n" + - " }\n" + - "}\n" - }, - ""); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84593 - public void test0496() { - this.runConformTest( - new String[] { - "X.java",//==================================== - "class Super {\n" + - " class A { }\n" + - " void take(A o) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "class Sub extends Super {\n" + - " void test() {\n" + - " take(new A());\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new Sub().test();\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84593 - variation - uncheck warnings - public void test0497() { - this.runNegativeTest( - new String[] { - "X.java",//==================================== - "class Super {\n" + - " class A { }\n" + - " void take(A o) {\n" + - " }\n" + - "}\n" + - "class Sub extends Super {\n" + - " void test() {\n" + - " take(new A());\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new Sub().test();\n" + - " Zork z;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " take(new A());\n" + - " ^^^^^^^\n" + - "Type safety: The expression of type Super.A needs unchecked conversion to conform to Super.A\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " take(new A());\n" + - " ^\n" + - "Super.A is a raw type. References to generic type Super.A should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84743 - variation in -source 1.4 mode but 1.5 compliance (ignore covariance) -public void test0498(){ - Map customOptions = getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); - runNegativeTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "interface I {\n" + - " String foo();\n" + - "}\n" + - "interface J {\n" + - " Object foo();\n" + - "}\n" + - " \n" + - "public class X implements I {\n" + - " public String foo() {\n" + - " return \"\";\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " I i = new X();\n" + - " try {\n" + - " J j = (J) i;\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n" - }, - // compiler options - null /* no class libraries */, - customOptions /* custom options */, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 15)\n" + - " J j = (J) i;\n" + - " ^^^^^\n" + - "Cannot cast from I to J\n" + - "----------\n", - // javac options - RUN_JAVAC ? /* javac test options */ - new JavacTestOptions("-source 1.4") : - JavacTestOptions.DEFAULT ); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=85157 -public void test0499(){ - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " String[] tab1 = new String[0];\n" + - " Integer[] tab2 = new Integer[0];\n" + - " boolean cond = true;\n" + - " Integer[] var = cond ? tab1 : tab2;\n" + - " System.out.println(var);\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " Integer[] var = cond ? tab1 : tab2;\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object&Serializable&Comparable>[] to Integer[]\n" + - "----------\n"); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84251 -public void test0500(){ - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.Collection;\n" + - "\n" + - "interface Sink { \n" + - " void flush(T t);\n" + - "}\n" + - "class SimpleSinkImpl implements Sink {\n" + - " public void flush(T t) {}\n" + - "}\n" + - "public class X {\n" + - "\n" + - " private T writeAll(Collection coll, Sink snk) { \n" + - " T last = null;\n" + - " for (T t : coll) { \n" + - " last = t;\n" + - " snk.flush(last);\n" + - " }\n" + - " return last;\n" + - " }\n" + - "\n" + - " public void test01() {\n" + - " Sink s = new SimpleSinkImpl();\n" + - " Collection cs = new ArrayList();\n" + - " cs.add(\"hello!\");\n" + - " cs.add(\"goodbye\");\n" + - " cs.add(\"see you\");\n" + - " \n" + - " String str = this.writeAll(cs, s); \n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X test = new X();\n" + - " \n" + - " test.test01();\n" + - " }\n" + - "}\n" - }, - ""); -} - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation - public void test0501() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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" + - " System.out.print(x.t.ax);\n" + - " System.out.print(x.t.bx);\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " P ax;\n" + - "}\n" + - "\n" + - "class BX extends AX {\n" + - " Q bx;\n" + - "}\n", - }, - "nullnull"); - 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 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + - " 18 aload_1 [x]\n" + - " 19 getfield X.t : AX [16]\n" + - " 22 checkcast BX [26]\n" + - " 25 getfield BX.ax : java.lang.Object [37]\n" + - " 28 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [41]\n" + - " 31 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + - " 34 aload_1 [x]\n" + - " 35 getfield X.t : AX [16]\n" + - " 38 checkcast BX [26]\n" + - " 41 getfield BX.bx : java.lang.Object [47]\n" + - " 44 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [41]\n" + - " 47 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 7]\n" + - " [pc: 15, line: 8]\n" + - " [pc: 31, line: 9]\n" + - " [pc: 47, line: 10]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 48] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 15, pc: 48] local: x index: 1 type: X\n" + - " Local variable type table:\n" + - " [pc: 15, pc: 48] local: x index: 1 type: X\n"; - - 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); - } - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation - public void test0502() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "public class X {\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" + - " System.out.print(x.self().t.ax);\n" + - " System.out.print(x.self().t.bx);\n" + - " }\n" + - " X self() {\n" + - " return this;\n" + - " }\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " P ax;\n" + - "}\n" + - "\n" + - "class BX extends AX {\n" + - " Q bx;\n" + - "}\n", - }, - "nullnull"); - 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 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + - " 18 aload_1 [x]\n" + - " 19 invokevirtual X.self() : X [37]\n" + - " 22 getfield X.t : AX [16]\n" + - " 25 checkcast BX [26]\n" + - " 28 getfield BX.ax : java.lang.Object [41]\n" + - " 31 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + - " 34 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + - " 37 aload_1 [x]\n" + - " 38 invokevirtual X.self() : X [37]\n" + - " 41 getfield X.t : AX [16]\n" + - " 44 checkcast BX [26]\n" + - " 47 getfield BX.bx : java.lang.Object [51]\n" + - " 50 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + - " 53 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 7]\n" + - " [pc: 15, line: 8]\n" + - " [pc: 34, line: 9]\n" + - " [pc: 53, line: 10]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 54] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 15, pc: 54] local: x index: 1 type: X\n" + - " Local variable type table:\n" + - " [pc: 15, pc: 54] local: x index: 1 type: X\n"; - - 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); - } - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation - public void test0503() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "class XA {}\n" + - "interface XB {\n" + - " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + - "}\n" + - "class XAB extends XA implements XB {}\n" + - "\n" + - "public class X {\n" + - " E e;\n" + - " public static void main(String[] args) {\n" + - " System.out.print(new X().e.CONST);\n" + - " new X().foo();\n" + - " }\n" + - " public void foo() {\n" + - " System.out.print(this.e.CONST);\n" + - " }\n" + - "}\n", - }, - "SUCCESSSUCCESS"); - String expectedOutput = - "// Signature: Ljava/lang/Object;\n" + - "public class X {\n" + - " \n" + - " // Field descriptor #6 LXA;\n" + - " // Signature: TE;\n" + - " XA e;\n" + - " \n" + - " // Method descriptor #10 ()V\n" + - " // Stack: 1, Locals: 1\n" + - " public X();\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [12]\n" + - " 4 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 5] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 5] local: this index: 0 type: X\n" + - " \n" + - " // Method descriptor #21 ([Ljava/lang/String;)V\n" + - " // Stack: 3, Locals: 1\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + - " 3 new X [1]\n" + - " 6 dup\n" + - " 7 invokespecial X() [28]\n" + - " 10 getfield X.e : XA [29]\n" + - " 13 checkcast XAB [31]\n" + - " 16 pop\n" + - " 17 getstatic XAB.CONST : XB [33]\n" + - " 20 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + - " 23 new X [1]\n" + - " 26 dup\n" + - " 27 invokespecial X() [28]\n" + - " 30 invokevirtual X.foo() : void [43]\n" + - " 33 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 10]\n" + - " [pc: 23, line: 11]\n" + - " [pc: 33, line: 12]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + - " \n" + - " // Method descriptor #10 ()V\n" + - " // Stack: 2, Locals: 1\n" + - " public void foo();\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + - " 3 aload_0 [this]\n" + - " 4 getfield X.e : XA [29]\n" + - " 7 checkcast XB [48]\n" + - " 10 pop\n" + - " 11 getstatic XB.CONST : XB [50]\n" + - " 14 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + - " 17 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 14]\n" + - " [pc: 17, line: 15]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 18] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 18] local: this index: 0 type: X\n"; - - 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); - } - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation - public void test0504() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "class XA {}\n" + - "interface XB {\n" + - " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + - "}\n" + - "class XAB extends XA implements XB {}\n" + - "\n" + - "public class X {\n" + - " E e() { return null; }\n" + - " public static void main(String[] args) {\n" + - " System.out.print(new X().e().CONST);\n" + - " new X().foo();\n" + - " }\n" + - " public void foo() {\n" + - " System.out.print(this.e().CONST);\n" + - " }\n" + - "}\n", - }, - "SUCCESSSUCCESS"); - String expectedOutput = - "// Signature: Ljava/lang/Object;\n" + - "public class X {\n" + - " \n" + - " // Method descriptor #6 ()V\n" + - " // Stack: 1, Locals: 1\n" + - " public X();\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [8]\n" + - " 4 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 5] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 5] local: this index: 0 type: X\n" + - " \n" + - " // Method descriptor #17 ()LXA;\n" + - " // Signature: ()TE;\n" + - " // Stack: 1, Locals: 1\n" + - " XA e();\n" + - " 0 aconst_null\n" + - " 1 areturn\n" + - " Line numbers:\n" + - " [pc: 0, line: 8]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 2] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 2] local: this index: 0 type: X\n" + - " \n" + - " // Method descriptor #21 ([Ljava/lang/String;)V\n" + - " // Stack: 3, Locals: 1\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + - " 3 new X [1]\n" + - " 6 dup\n" + - " 7 invokespecial X() [28]\n" + - " 10 invokevirtual X.e() : XA [29]\n" + - " 13 checkcast XAB [31]\n" + - " 16 pop\n" + - " 17 getstatic XAB.CONST : XB [33]\n" + - " 20 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + - " 23 new X [1]\n" + - " 26 dup\n" + - " 27 invokespecial X() [28]\n" + - " 30 invokevirtual X.foo() : void [43]\n" + - " 33 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 10]\n" + - " [pc: 23, line: 11]\n" + - " [pc: 33, line: 12]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + - " \n" + - " // Method descriptor #6 ()V\n" + - " // Stack: 2, Locals: 1\n" + - " public void foo();\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + - " 3 aload_0 [this]\n" + - " 4 invokevirtual X.e() : XA [29]\n" + - " 7 checkcast XB [48]\n" + - " 10 pop\n" + - " 11 getstatic XB.CONST : XB [50]\n" + - " 14 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + - " 17 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 14]\n" + - " [pc: 17, line: 15]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 18] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 18] local: this index: 0 type: X\n"; - - 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); - } - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation - public void test0505() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "class XA {}\n" + - "interface XB {\n" + - " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + - "}\n" + - "class XAB extends XA implements XB {}\n" + - "\n" + - "public class X {\n" + - " E e;\n" + - " public static void main(String[] args) {\n" + - " new X().foo();\n" + - " }\n" + - " public void foo() {\n" + - " new Object() {\n" + - " void run() {\n" + - " System.out.print(e.CONST);\n" + - " }\n" + - " }.run();\n" + - " System.out.print(e.CONST);\n" + - " }\n" + - "}\n", - }, - "SUCCESSSUCCESS"); - String expectedOutput = - "// Signature: Ljava/lang/Object;\n" + - "public class X {\n" + - " \n" + - " // Field descriptor #6 LXA;\n" + - " // Signature: TE;\n" + - " XA e;\n" + - " \n" + - " // Method descriptor #10 ()V\n" + - " // Stack: 1, Locals: 1\n" + - " public X();\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [12]\n" + - " 4 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 5] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 5] local: this index: 0 type: X\n" + - " \n" + - " // Method descriptor #21 ([Ljava/lang/String;)V\n" + - " // Stack: 2, Locals: 1\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 new X [1]\n" + - " 3 dup\n" + - " 4 invokespecial X() [22]\n" + - " 7 invokevirtual X.foo() : void [23]\n" + - " 10 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 10]\n" + - " [pc: 10, line: 11]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 11] local: args index: 0 type: java.lang.String[]\n" + - " \n" + - " // Method descriptor #10 ()V\n" + - " // Stack: 3, Locals: 1\n" + - " public void foo();\n" + - " 0 new X$1 [28]\n" + - " 3 dup\n" + - " 4 aload_0 [this]\n" + - " 5 invokespecial X$1(X) [30]\n" + - " 8 invokevirtual X$1.run() : void [33]\n" + - " 11 getstatic java.lang.System.out : java.io.PrintStream [36]\n" + - " 14 aload_0 [this]\n" + - " 15 getfield X.e : XA [42]\n" + - " 18 checkcast XB [44]\n" + - " 21 pop\n" + - " 22 getstatic XB.CONST : XB [46]\n" + - " 25 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [50]\n" + - " 28 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 13]\n" + - " [pc: 8, line: 17]\n" + - " [pc: 11, line: 18]\n" + - " [pc: 28, line: 19]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 29] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 29] local: this index: 0 type: X\n"; - - 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); - } - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85477 - public void test0506() { - this.runNegativeTest( - new String[] { - "X.java",//==================================== - "import java.util.Collections;\n" + - "import java.util.Comparator;\n" + - "import java.util.List;\n" + - "\n" + - "public final class X {\n" + - " public void test(List list,final Comparator comparator, X x) {\n" + - " foo(list, comparator);\n" + - " bar(list, comparator);\n" + - " \n" + - " x.foo(list, comparator);\n" + - " x.bar(list, comparator);\n" + - " }\n" + - "\n" + - " void foo(List lt, Comparator ct) {\n" + - " }\n" + - " static void bar(List lt, Comparator ct) {\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " public void test(List list,final Comparator comparator, X x) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " public void test(List list,final Comparator comparator, X x) {\n" + - " ^^^^^^^^^^\n" + - "Comparator is a raw type. References to generic type Comparator should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " public void test(List list,final Comparator comparator, X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " foo(list, comparator);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation foo(List, Comparator) of the generic method foo(List, Comparator) of type X\n" + - "----------\n" + - "5. WARNING in X.java (at line 7)\n" + - " foo(list, comparator);\n" + - " ^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "6. WARNING in X.java (at line 7)\n" + - " foo(list, comparator);\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + - "----------\n" + - "7. WARNING in X.java (at line 8)\n" + - " bar(list, comparator);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(List, Comparator) of the generic method bar(List, Comparator) of type X\n" + - "----------\n" + - "8. WARNING in X.java (at line 8)\n" + - " bar(list, comparator);\n" + - " ^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "9. WARNING in X.java (at line 8)\n" + - " bar(list, comparator);\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + - "----------\n" + - "10. WARNING in X.java (at line 10)\n" + - " x.foo(list, comparator);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method foo(List, Comparator) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n" + - "11. WARNING in X.java (at line 11)\n" + - " x.bar(list, comparator);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The static method bar(List, Comparator) from the type X should be accessed in a static way\n" + - "----------\n" + - "12. WARNING in X.java (at line 11)\n" + - " x.bar(list, comparator);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(List, Comparator) of the generic method bar(List, Comparator) of type X\n" + - "----------\n" + - "13. WARNING in X.java (at line 11)\n" + - " x.bar(list, comparator);\n" + - " ^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "14. WARNING in X.java (at line 11)\n" + - " x.bar(list, comparator);\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + - "----------\n" + - "15. ERROR in X.java (at line 18)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // array bound for wildcard - public void test0507() { - this.runConformTest( - new String[] { - "X.java",//==================================== - "import java.io.Serializable;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void foo1(List l) {\n" + - " int i = l.get(0).length;\n" + - " }\n" + - " void foo2(List l) {\n" + - " Object o = l.get(0).toString();\n" + - " }\n" + - " void foo3(List l, Serializable s) {\n" + - " boolean b = true;\n" + - " Serializable s2 = b ? l.get(0) : s;\n" + - " }\n" + - "}\n" - }, - ""); - } - // array bound for wildcard - public void test0508() { - this.runNegativeTest( - new String[] { - "X.java",//==================================== - "import java.io.Serializable;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void foo1(List l) {\n" + - " int i = l.get(0).length;\n" + - " }\n" + - " void foo2(List l) {\n" + - " Object o = l.get(0).toString();\n" + - " }\n" + - " void foo3(List l, Serializable s) {\n" + - " boolean b = true;\n" + - " Serializable s2 = b ? l.get(0) : s;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " int i = l.get(0).length;\n" + - " ^^^^^^\n" + - "length cannot be resolved or is not a field\n" + - "----------\n" + - "2. ERROR in X.java (at line 13)\n" + - " Serializable s2 = b ? l.get(0) : s;\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to Serializable\n" + - "----------\n"); - } - // type parameter hiding - public void test0509() { - this.runNegativeTest( - new String[] { - "X.java",//==================================== - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List list = new ArrayList();\n" + - " list.add(new MyTigerSimpleObject(\"a\"));\n" + - " list.add(new MyTigerSimpleObject(\"b\"));\n" + - " \n" + - " for (MyTigerSimpleObject so : list)\n" + - " System.out.println(so.getSomeAttribute()); \n" + - " }\n" + - "}\n" + - "class MyTigerSimpleObject {\n" + - " MyTigerSimpleObject(String s) {}\n" + - " E getSomeAttribute() { return null; }\n" + - "}\n" + - "\n" + - "class TigerList extends ArrayList {\n" + - " public void listAll() {\n" + - " for (MyTigerSimpleObject so : this)\n" + - " System.out.println(so.getSomeAttribute());\n" + - " }\n" + - " \n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List list = new ArrayList();\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " List list = new ArrayList();\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " list.add(new MyTigerSimpleObject(\"a\"));\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " list.add(new MyTigerSimpleObject(\"b\"));\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 8)\n" + - " for (MyTigerSimpleObject so : list)\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 17)\n" + - " class TigerList extends ArrayList {\n" + - " ^^^^^^^^^\n" + - "The serializable class TigerList does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "7. WARNING in X.java (at line 17)\n" + - " class TigerList extends ArrayList {\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The type parameter MyTigerSimpleObject is hiding the type MyTigerSimpleObject\n" + - "----------\n" + - "8. ERROR in X.java (at line 20)\n" + - " System.out.println(so.getSomeAttribute());\n" + - " ^^^^^^^^^^^^^^^^\n" + - "The method getSomeAttribute() is undefined for the type MyTigerSimpleObject\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84355 - public void test0510() { - this.runConformTest( - new String[] { - "X.java",//==================================== - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " public X() {\n" + - " String[] strings = new String[]{\"test\"};\n" + - "\n" + - " // this fails\n" + - " Object obj = ClassB.doSomething((String) strings[0]);\n" + - "\n" + - " // this works fine\n" + - " String intermediate = ClassB.doSomething((String) strings[0]);\n" + - " Object obj1 = intermediate;\n" + - " }\n" + - "}\n" + - "\n" + - "class ClassB {\n" + - " public static T doSomething(String value) {\n" + - " return (T) value;\n" + - " }\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82407 - public void test0511() { - this.runConformTest( - new String[] { - "X.java",//==================================== - "import java.util.HashMap;\n" + - "\n" + - "public class X {\n" + - "\n" + - " static HashMap substitutionList(String s1, String s2) {\n" + - "\n" + - " HashMap subst = new HashMap();\n" + - "\n" + - " for (int i = 0; i < s1.length(); i++) {\n" + - " char key = s1.charAt(i);\n" + - " char value = s2.charAt(i);\n" + - " if (subst.containsKey(key)) {\n" + - " if (value != subst.get(key)) {\n" + - " return null;\n" + - " }\n" + - " } else if (subst.containsValue(value)) {\n" + - " return null;\n" + - " } else {\n" + - " subst.put(key, value);\n" + - " }\n" + - " }\n" + - "\n" + - " return subst;\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0512() { - this.runConformTest( - new String[] { - "X.java",//==================================== - "public class X { \n" + - " public static void main(String argv[]) {\n" + - " \n" + - " new X().new M(null) {\n" + - " void run() {\n" + - " Exception e = ex;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }.run();\n" + - " }\n" + - " class M {\n" + - " E ex;\n" + - " M(E ex) {\n" + - " this.ex = ex;\n" + - " }\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0513() { - this.runNegativeTest( - new String[] { - "X.java",//==================================== - "public class X { \n" + - " public static void main(String argv[]) {\n" + - " \n" + - " new X().new M(null) {\n" + - " void run() {\n" + - " Exception e = ex;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }.run();\n" + - " }\n" + - " class M {\n" + - " E ex;\n" + - " M(E ex) {\n" + - " this.ex = ex;\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " new X().new M(null) {\n" + - " void run() {\n" + - " Exception e = ex;\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }.run();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The constructor X.M(Throwable) belongs to the raw type X.M. References to generic type X.M should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " new X().new M(null) {\n" + - " ^\n" + - "X.M is a raw type. References to generic type X.M should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " new X().new M(null) {\n" + - " ^^^^^^^\n" + - "Type safety: The constructor X.M(Throwable) belongs to the raw type X.M. References to generic type X.M should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 6)\n" + - " Exception e = ex;\n" + - " ^^\n" + - "Type mismatch: cannot convert from Throwable to Exception\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82955 - public void test0514(){ - runConformTest( - new String[] { - "Test.java", - "public class Test {\n" + - " static T infer( T t1, T t2 ) { return null; }\n" + - " public static void main( String [] args ) {\n" + - " Base base = infer( new Sub1(), new Sub2() );\n" + - " // Note: Eclipse 3.1 says this is an error, but it\'s not\n" + - " Runnable runnable = infer( new Sub1(), new Sub2() );\n" + - " }\n" + - "}\n" + - "class Base { }\n" + - "class Sub1 extends Base implements Runnable { public void run() { } }\n" + - "class Sub2 extends Base implements Runnable { public void run() { } }\n" - } - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84348 - public void test0515(){ - runConformTest( - new String[] { - "Test.java", - "public class Test {\n" + - " public static void myMethod(final List fileList) {\n" + - " Collections.sort(fileList, new Comparator(){\n" + - " public int compare(File f1, File f2) { return 0; }\n" + - " });\n" + - " }\n" + - "}\n" + - "\n" + - "class List {}\n" + - "class File {}\n" + - "interface Comparator {}\n" + - "class Collections {\n" + - " static void sort(List list, Comparator c) {}\n" + - "}" - } - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 - public void test0516(){ - runConformTest( - new String[] { - "parser/AbstractParser.java", - "package parser;\n" + - "public abstract class AbstractParser implements ValueParser {\n" + - " public T parse( final String string ) {\n" + - " return valueOf(string); \n" + - " }\n" + - " protected abstract T valueOf(final String string); \n" + - "}\n" + - "interface ValueParser {\n" + - " T parse(final String string);\n" + - "}\n", - "parser/BooleanParser.java", - "package parser;\n" + - "public class BooleanParser extends AbstractParser {\n" + - " protected Boolean valueOf(final String string ) {\n" + - " return Boolean.valueOf(string); \n" + - " }\n" + - "}\n" - } - ); - runConformTest( - new String[] { - "test/BooleanParserTest.java", - "package test;\n" + - "import parser.BooleanParser;\n" + - "public class BooleanParserTest {\n" + - " static final boolean getBoolean(final String value) {\n" + - " return new BooleanParser().parse(value).booleanValue(); // The type Boolean is not visible\n" + - " }\n" + - "}\n" - }, - null, - null, - false, // do not flush output directory - null - ); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 - check no warning for using raw member - public void test0517(){ - runNegativeTest( - new String[] { - "X.java", - "class Base {\n" + - " class InnerBase {\n" + - " java.util.List list;\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "\n" + - "public class X extends Base {\n" + - " class InnerDerived extends InnerBase {\n" + - " void method() {\n" + - " list.add(\"Hi\"); // Warning on this method call\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85930 - check no warning for using raw member - public void test0518(){ - runNegativeTest( - new String[] { - "X.java", - "interface Callable {\n" + - " public enum Result {\n" + - " GOOD, BAD\n" + - " };\n" + - " public Result call(T arg);\n" + - "}\n" + - "\n" + - "public class X implements Callable {\n" + - " public Result call(String arg) {\n" + - " return Result.GOOD;\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85262 - public void test0519(){ - runConformTest( - new String[] { - "FooImpl.java", - "interface Bar> {} \n" + - " \n" + - "class BarImpl> implements Bar {} \n" + - " \n" + - "interface Foo> extends Bar {} \n" + - " \n" + - "public class FooImpl> extends BarImpl implements Foo {}\n" + - "\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85262 - variation - public void test0520(){ - runConformTest( - new String[] { - "Bar.java", - "public interface Bar> {} \n", - "BarImpl.java", - "public class BarImpl> implements Bar {} \n", - "Foo.java", - "public interface Foo> extends Bar {} \n", - }, - ""); - runConformTest( - new String[] { - "FooImpl.java", - "public class FooImpl> extends BarImpl implements Foo {}\n", - }, - "", - null, - false, // do not flush output directory - null); - } - public void test0521(){ - runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " static public void addAll(T a, T b) {\n" + - " a.addAll(b);\n" + - " }\n" + - " static public void main(String[] args) {\n" + - " Collection a = new ArrayList();\n" + - " Collection b = new ArrayList();\n" + - " b.add(\"string\");\n" + - " addAll(a, b);\n" + - " try {\n" + - " System.out.println(a.iterator().next().intValue()); // ClassCastException\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - // variation on test0521, check issuing of unchecked warning ** - public void test0522(){ - runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " static public void addAll(T a, T b) {\n" + - " a.addAll(b);\n" + - " }\n" + - " static public void main(String[] args) {\n" + - " Collection a = new ArrayList();\n" + - " Collection b = new ArrayList();\n" + - " b.add(\"string\");\n" + - " addAll(a, b);\n" + - " try {\n" + - " System.out.println(a.iterator().next().intValue()); // ClassCastException\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " static public void addAll(T a, T b) {\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " a.addAll(b);\n" + - " ^^^^^^^^^^^\n" + - "Type safety: The method addAll(Collection) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 18)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0523(){ - runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public X() {\n" + - " M m = new M();\n" + - " List ls = m.list(); // rawified even though wasn\'t using T parameter\n" + - " }\n" + - " Zork z;\n" + - " static class M {\n" + - " List list() {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " M m = new M();\n" + - " ^\n" + - "X.M is a raw type. References to generic type X.M should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " M m = new M();\n" + - " ^\n" + - "X.M is a raw type. References to generic type X.M should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " List ls = m.list(); // rawified even though wasn\'t using T parameter\n" + - " ^^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // ensure there is no unchecked warning ** - public void test0524(){ - runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "class MyList extends ArrayList {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List a = new MyList();\n" + - " List b = (MyList) a; \n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " class MyList extends ArrayList {\n" + - " ^^^^^^\n" + - "The serializable class MyList does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0525(){ - runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " List list = new ArrayList();\n" + - " String s = \"this shouldn\'t work\";\n" + - " list.add(s);\n" + - " List listInt = list;\n" + - " int i = listInt.get(0);\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - } - public void test0526(){ - runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Zork z;\n" + - " T f(Object o) {\n" + - " return (T) o; // OK\n" + - " }\n" + - "\n" + - " T g(Object o) {\n" + - " return (T) o; // bug???\n" + - " }\n" + - "\n" + - " T h(Object o) {\n" + - " return X.castTo(o); // workaround\n" + - " }\n" + - "\n" + - " private static T castTo(Object o) {\n" + - " return (T) o;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " return (T) o; // OK\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " return (T) o; // bug???\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "4. WARNING in X.java (at line 16)\n" + - " return (T) o;\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n"); - } - // should not produce unchecked errors ** - public void test0527(){ - runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T foo(U u, V v) {\n" + - " return this == null ? (T) u : (T)v;\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86217 - public void test0528() { - this.runConformTest( - new String[] { - "X.java", - "public class X extends Y {}\n" + - "class Y { static class M {} }\n", - }, - "" - ); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86463 - public void test0529() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void bar() {\n" + - " T t = new ArrayList(); // BUG!!!\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " public class X {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " T t = new ArrayList(); // BUG!!!\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from ArrayList to T\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " T t = new ArrayList(); // BUG!!!\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86463 - public void test0530() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "abstract class Foo\n" + - " {\n" + - " abstract void foo(T t);\n" + - " void foo2()\n" + - " {\n" + - " List l = new LinkedList();\n" + - " foo(l); // BUG!!!\n" + - " }\n" + - "}\n" + - "\n" + - "public class X extends Foo\n" + - "{\n" + - " void foo(ArrayList l)\n" + - " {\n" + - " System.out.println(l);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " abstract class Foo\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " List l = new LinkedList();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " List l = new LinkedList();\n" + - " ^^^^^^^^^^\n" + - "LinkedList is a raw type. References to generic type LinkedList should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " foo(l); // BUG!!!\n" + - " ^^^\n" + - "The method foo(T) in the type Foo is not applicable for the arguments (List)\n" + - "----------\n" + - "5. WARNING in X.java (at line 13)\n" + - " public class X extends Foo\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 15)\n" + - " void foo(ArrayList l)\n" + - " ^^^^^^^^^^^^^^^^\n" + - "The method foo(ArrayList) of type X should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "7. WARNING in X.java (at line 15)\n" + - " void foo(ArrayList l)\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86646 - public void test0531() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Vector;\n" + - "\n" + - "public class X {\n" + - " public T f1(T l) {\n" + - " Vector v = new Vector();\n" + - " v.add(l);\n" + - " return (T) v.get(0); // Expect warning here\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " return (T) v.get(0); // Expect warning here\n" + - " ^^^^^^^^^^^^\n" + - "Unnecessary cast from T to T\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 - public void test0532() { - this.runConformTest( - new String[] { - "p/X.java", - "package p;\n" + - "public class X extends Z {\n" + - " @Override public Boolean value() { return true; }\n" + - "}\n" + - "abstract class Z {\n" + - " public T foo() { return value(); }\n" + - " public abstract T value();\n" + - "}\n", - }, - "" - ); - this.runConformTest( - new String[] { - "Y.java", - "import p.X;\n" + - "public class Y { boolean test() { return new X().foo().booleanValue(); } }\n", - }, - "", - null, - false, // do not flush output - null - ); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - public void test0533() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.EnumSet;\n" + - "\n" + - "enum Foo {\n" + - " blargh, baz, boz;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Foo.class;\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Class c = Foo.class;\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^^^^\n" + - "Enum is a raw type. References to generic type Enum should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^^^^\n" + - "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + - "----------\n" + - "4. WARNING in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + - "----------\n" + - "5. WARNING in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet\n" + - "----------\n" + - "6. WARNING in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^\n" + - "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation - public void test0534() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.EnumSet;\n" + - "\n" + - "enum Foo {\n" + - " blargh, baz, boz;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Foo.class;\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " }\n" + - "}\n", - }, - "" - ); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation - public void test0535() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.EnumSet;\n" + - "\n" + - "enum Foo {\n" + - " blargh, baz, boz;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Foo.class;\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " }\n" + - "}\n", - }, - "" - ); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation - public void test0536() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.EnumSet;\n" + - "\n" + - "enum Foo {\n" + - " blargh, baz, boz;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Foo.class;\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " }\n" + - "}\n", - }, - "" - ); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation - public void test0537() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.EnumSet;\n" + - "\n" + - "enum Foo {\n" + - " blargh, baz, boz;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Foo.class;\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Class c = Foo.class;\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " EnumSet eSet = EnumSet.allOf(c);\n" + - " ^\n" + - "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + - "----------\n" + - "4. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation - public void test0538() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.EnumSet;\n" + - "\n" + - "enum Foo {\n" + - " blargh, baz, boz;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Foo.class;\n" + - " EnumSet> eSet = EnumSet.allOf(c);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Class c = Foo.class;\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " EnumSet> eSet = EnumSet.allOf(c);\n" + - " ^^^^\n" + - "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " EnumSet> eSet = EnumSet.allOf(c);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + - "----------\n" + - "4. WARNING in X.java (at line 10)\n" + - " EnumSet> eSet = EnumSet.allOf(c);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet>\n" + - "----------\n" + - "5. WARNING in X.java (at line 10)\n" + - " EnumSet> eSet = EnumSet.allOf(c);\n" + - " ^\n" + - "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation - public void test0539() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class B {\n" + - " public T willBe(Class c) {\n" + - " return (T)null;\n" + - " }\n" + - " }\n" + - " interface I1 {\n" + - " }\n" + - " interface I2 extends I1 {\n" + - " }\n" + - " \n" + - " public static void m1(String[] args) {\n" + - " B b = new B();\n" + - " I2 v = b.willBe(I2.class);\n" + - " }\n" + - " public static void m2(String[] args) {\n" + - " B b = new B();\n" + - " I2 v = b.willBe(I2.class);\n" + - " }\n" + - "\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " return (T)null;\n" + - " ^^^^^^^\n" + - "Unnecessary cast from null to T\n" + - "----------\n" + - "2. WARNING in X.java (at line 13)\n" + - " B b = new B();\n" + - " ^\n" + - "X.B is a raw type. References to generic type X.B should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 13)\n" + - " B b = new B();\n" + - " ^\n" + - "X.B is a raw type. References to generic type X.B should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 14)\n" + - " I2 v = b.willBe(I2.class);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method willBe(Class) belongs to the raw type X.B. References to generic type X.B should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 14)\n" + - " I2 v = b.willBe(I2.class);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.I1 to X.I2\n" + - "----------\n"); - } - // test paramtype argument compatibility - public void test0540() { - this.runNegativeTest( - new String[] { - "Baz.java", - "import java.util.*;\n" + - "interface Foo {}\n" + - "interface Bar extends Foo {\n" + - "}\n" + - "public class Baz {\n" + - " public R visit(Collection> trees, D d) {\n" + - " return null;\n" + - " }\n" + - " R test(Collection c, D d) {\n" + - " return visit(c, d);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in Baz.java (at line 3)\n" + - " interface Bar extends Foo {\n" + - " ^^^\n" + - "Foo is a raw type. References to generic type Foo should be parameterized\n" + - "----------\n" + - "2. ERROR in Baz.java (at line 10)\n" + - " return visit(c, d);\n" + - " ^^^^^\n" + - "The method visit(Collection>, D) in the type Baz is not applicable for the arguments (Collection, D)\n" + - "----------\n"); - } - public void test0541() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Map m = null;\n" + - " try {\n" + - " Map m2 = m.getClass().newInstance();\n" + - " } catch(Exception e) {\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0542() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static boolean isOK(T x) {\n" + - " return isOK(x);\n" + - " }\n" + - "\n" + - " static boolean isStillOK(T x) {\n" + - " return true && isOK(x);\n" + - " }\n" + - "\n" + - " static boolean isNoMoreOK(T x) {\n" + - " return true && isNoMoreOK(x);\n" + - " }\n" + - "\n" + - " static boolean isOKAgain(T x) {\n" + - " boolean res;\n" + - " return true && (res = isOKAgain(x));\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0543() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Object obj = null;\n" + - " List ls = (List) obj;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " List ls = (List) obj;\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0544() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Vector;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Vector a = new Vector();\n" + - " Vector b = new Vector();\n" + - " b.add(new Object());\n" + - " a = b;\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " Vector b = new Vector();\n" + - " ^^^^^^\n" + - "Vector is a raw type. References to generic type Vector should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " Vector b = new Vector();\n" + - " ^^^^^^\n" + - "Vector is a raw type. References to generic type Vector should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " b.add(new Object());\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " a = b;\n" + - " ^\n" + - "Type safety: The expression of type Vector needs unchecked conversion to conform to Vector\n" + - "----------\n" + - "5. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86898 - public void test0545() { - this.runNegativeTest( - new String[] { - "X.java", - "class B extends A {\n" + - " void m2() {\n" + - " m3((X2) m()); // A.m() --> X - cannot cast to X2\n" + - " }\n" + - " void m3(X2 i) {}\n" + - "}\n" + - "class A {\n" + - " X m() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "class X2 extends X {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " void foo(X lhs, X rhs) {\n" + - " lhs = rhs; // cannot convert\n" + - " }\n" + - " void bar(X2 lhs, X rhs) {\n" + - " lhs = rhs; // cannot convert\n" + - " }\n" + - "}\n" + - "class C {\n" + - " void foo(X xo) {}\n" + - " void bar(X xs) {}\n" + - "}\n" + - "class D extends C {\n" + - " void foo(X xs) {}\n" + - " void bar(X xo) {}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 18)\n" + - " lhs = rhs; // cannot convert\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 21)\n" + - " lhs = rhs; // cannot convert\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X to X2\n" + - "----------\n" + - "3. ERROR in X.java (at line 29)\n" + - " void foo(X xs) {}\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(X) of type D has the same erasure as foo(X) of type C but does not override it\n" + - "----------\n" + - "4. ERROR in X.java (at line 30)\n" + - " void bar(X xo) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method bar(X) of type D has the same erasure as bar(X) of type C but does not override it\n" + - "----------\n"); - } - // ensure no unsafe cast warning ** - public void test0546() { - this.runNegativeTest( - new String[] { - "X.java", - "class StringList extends java.util.LinkedList {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " java.util.List a = new StringList();\n" + - " java.util.List b = (StringList) a; // warned but safe.\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " class StringList extends java.util.LinkedList {\n" + - " ^^^^^^^^^^\n" + - "The serializable class StringList does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0547() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public TreeMap essai(K type) {\n" + - " TreeMap treeMap = new TreeMap();\n" + - " return treeMap;\n" + - " }\n" + - " public static void main(String args[]) {\n" + - " X x = new X();\n" + - " TreeMap treeMap = x.essai(null);\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - public void test0548() { - this.runNegativeTest( - new String[] { - "X.java", - "interface DA {\n" + - "}\n" + - "interface DB extends DA {\n" + - "}\n" + - "interface DC extends DA {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Object o = (DC) (DA) null;\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Object o = (DC) (DA) null;\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from DA to DC\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " Object o = (DC) (DA) null;\n" + - " ^^^^^^^^^^^^\n" + - "Unnecessary cast from null to DA\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // ** - public void test0549() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " boolean DEBUG = this instanceof Special;\n" + - "\n" + - " public static class Special extends X {\n" + - " }\n" + - "}\n", - }, - ""); - } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 - public void test0550() { - this.runNegativeTest( - new String[] { - "X.java", - "class A {}\n" + - "class B extends A {}\n" + - "\n" + - "public class X {\n" + - " public void foo(X param) {\n" + - " X foo = (X)param;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X foo = (X)param;\n" + - " ^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - // ensure no unchecked warning - public void test0551() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T cond1(boolean z, U x1, V x2) {\n" + - " return (z? (T) x1: x2);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " T cond1(boolean z, U x1, V x2) {\n" + - " ^\n" + - "The parameter z is hiding a field from type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0552() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " Comparable x;\n" + - "\n" + - " void put(Comparable c) {\n" + - " this.x = c;\n" + - " }\n" + - "\n" + - " Comparable get() {\n" + - " return x;\n" + - " }\n" + - "\n" + - " void test() {\n" + - " X ci = new X();\n" + - " ci.put(new Integer(3));\n" + - " Integer i = (Integer) ci.get();\n" + - " }\n" + - "\n" + - "}\n", - }, - ""); - } - public void test0553() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String args[]) throws Exception {\n" + - " doIt();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void doIt() {\n" + - " Holder association = new Holder(new Integer(0));\n" + - " Integer sizeHolder = (Integer)(association.getValue()); //Cast to Integer is redundant!!!\n" + - " System.out.print(sizeHolder.intValue());\n" + - " }\n" + - " static class Holder {\n" + - " V value;\n" + - " Holder(V value) {\n" + - " this.value = value;\n" + - " }\n" + - " V getValue() {\n" + - " return value;\n" + - " }\n" + - " }\n" + - "}\n" , - }, - "0SUCCESS"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86898 - variation - public void test0554() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.*;\n" + - " public class X {\n" + - " public static void main(String[] args) {\n" + - " X xo = null;\n" + - " X xs = null;\n" + - " X2 x2 = null;\n" + - " \n" + - " Object o1 = (X) xo;\n" + - " Object o2 = (X) xs;\n" + - " Object o3 = (X2) xo;\n" + - " Object o4 = (X) x2;\n" + - " Object o5 = (X3) xo;\n" + - " }\n" + - "}\n" + - "class X2 extends X {\n" + - "}\n" + - "class X3 extends X {\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " Object o1 = (X) xo;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to X\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " Object o1 = (X) xo;\n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X to X\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " Object o2 = (X) xs;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X to X\n" + - "----------\n" + - "4. WARNING in X.java (at line 10)\n" + - " Object o3 = (X2) xo;\n" + - " ^^^^^^^\n" + - "Unnecessary cast from X to X2\n" + - "----------\n" + - "5. WARNING in X.java (at line 11)\n" + - " Object o4 = (X) x2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X2 to X\n" + - "----------\n" + - "6. WARNING in X.java (at line 12)\n" + - " Object o5 = (X3) xo;\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to X3\n" + - "----------\n" + - "7. WARNING in X.java (at line 12)\n" + - " Object o5 = (X3) xo;\n" + - " ^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X to X3\n" + - "----------\n" + - "8. ERROR in X.java (at line 18)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0555() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.List;\n" + - " public class X {\n" + - " U u;\n" + - " void foo(X xn, X xu) {\n" + - " xn = xu;\n" + - " xu = xn;\n" + - " xu.u = xn.u; // ko\n" + - " xn.u = xu.u; // ko\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " xu = xn;\n" + - " ^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " xu.u = xn.u; // ko\n" + - " ^^^^\n" + - "Type mismatch: cannot convert from capture#6-of ? extends Number to capture#5-of ? extends U\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " xn.u = xu.u; // ko\n" + - " ^^^^\n" + - "Type mismatch: cannot convert from capture#8-of ? extends U to capture#7-of ? extends Number\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87273 - public void test0556() { - this.runConformTest( - new String[] { - "X.java", - "interface Foo {\n" + - " Object get();\n" + - "}\n" + - "\n" + - "interface MyList extends Foo {\n" + - " public F get();\n" + - "}\n" + - "\n" + - "class MyListImpl implements MyList {\n" + - " public G get() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "interface StringList extends MyList {\n" + - "}\n" + - "\n" + - "class StringListImpl extends MyListImpl implements StringList {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f = new StringListImpl();\n" + - " f.get();\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83002 - public void test0557() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static void foo(T t) throws T {\n" + // ensure exception is properly encoded (...^ex) - " }\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "Y.java", - "import java.io.*;\n" + - "public class Y {\n" + - " void foo() {\n" + - " try {\n" + - " X.foo(new IOException());\n" + - " } catch(IOException e){\n" + - " }\n" + - " }\n" + - "}\n", - }, - "", - null, - false, - null); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83002 - public void test0558() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static void foo(T t, U u) throws T, U {\n" + // ensure exception is properly encoded (...^ex) - " }\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "Y.java", - "import java.io.*;\n" + - "public class Y {\n" + - " void foo() {\n" + - " try {\n" + - " X.foo(new IOException(), new ClassNotFoundException());\n" + - " } catch(IOException e){\n" + - " } catch(ClassNotFoundException e){\n" + - " }\n" + - " }\n" + - "}\n", - }, - "", - null, - false, - null); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86902 - // ** - public void test0559() { - this.runNegativeTest( - new String[] { - "X.java", - "class Cell {\n" + - " T t;\n" + - " public void setT(T t) {\n" + - " this.t= t;\n" + - " }\n" + - " public T getT() {\n" + - " return t;\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Zork z;\n" + - " public static void main(String[] args) {\n" + - " Cell c= new Cell();\n" + - " c.setT(Boolean.FALSE); // other: warning: [unchecked] unchecked\n" + - " // call to setT(T) as a member of the raw type p.Cell\n" + - " c.t= Boolean.TRUE; // other: warning: [unchecked] unchecked call\n" + - " // to setT(T) as a member of the raw type p.Cell\n" + - " boolean b1= (Boolean) c.getT();\n" + - " boolean b2= (Boolean) c.t;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " Cell c= new Cell();\n" + - " ^^^^\n" + - "Cell is a raw type. References to generic type Cell should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 14)\n" + - " Cell c= new Cell();\n" + - " ^^^^\n" + - "Cell is a raw type. References to generic type Cell should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 15)\n" + - " c.setT(Boolean.FALSE); // other: warning: [unchecked] unchecked\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method setT(Object) belongs to the raw type Cell. References to generic type Cell should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 17)\n" + - " c.t= Boolean.TRUE; // other: warning: [unchecked] unchecked call\n" + - " ^\n" + - "Type safety: The field t from the raw type Cell is assigned a value of type Boolean. References to generic type Cell should be parameterized\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85924 - public void test0560() { - this.runConformTest( - new String[] { - "X.java", - "interface IController> {\n" + - " public U getView() ;\n" + - "}\n" + - "interface IView {\n" + - "}\n" + - "class MatGroup {\n" + - " public abstract static class View implements IView {\n" + - " public void setTempAppearance() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " \n" + - " public abstract static class Ctrl implements IController {\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String []args) {\n" + - " MatGroup.Ctrlchildren[] = { \n" + - " new MatGroup.Ctrl(){\n" + - " public MatGroup.View getView() { return new MatGroup.View(){}; } \n" + - " }} ;\n" + - " for(MatGroup.Ctrl glmat: children) {\n" + - " glmat.getView().setTempAppearance() ;\n" + - " }\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87956 - public void test0561() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(A a) {}\n" + - " Object foo(A a) { return null; }\n" + - " void test(A a) { foo(a); }\n" + - "}\n" + - "class A {}\n", - }, - "" - ); - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " Number foo(A a) { return null; }\n" + - " Integer foo(A a) { return null; }\n" + - " void test(A a) { foo(a); }\n" + - "}\n" + - "class A {}\n", - }, - "" - ); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - public void test0562() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "interface Inter {}\n" + - "public class X> extends ArrayList implements Inter {\n" + - " public final void foo(U u) {\n" + - " X.bar(this, u);\n" + - " }\n" + - " public static final void bar(Collection> c, Q q) {}\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - variation - public void test0563() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "interface Inter {}\n" + - "public class X> extends ArrayList implements Inter {\n" + - " public final void foo(U u) {\n" + - " X.bar(this, u);\n" + - " }\n" + - " public static final void bar(Collection c, Q q) {}\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - variation - public void test0564() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "interface Inter {}\n" + - "public class X> extends ArrayList implements Inter {\n" + - " public final void foo(U u) {\n" + - " X.bar(this, u);\n" + - " }\n" + - " public static final void bar(Collection> c, Q q) {}\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87995 - check no warning - public void test0565() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "interface IFoo {\n" + - " public T get(Class clazz);\n" + - " Zork z;\n" + - "}\n" + - "\n" + - "class Bar implements IFoo {\n" + - " public Integer get(Class arg0) {\n" + - " return new Integer(3);\n" + - " }\n" + - "}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0566() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void bar2() {\n" + - " List le = new ArrayList(5);\n" + - " le = fill(le, new X2());\n" + - " }\n" + - " List fill(List lt, T t) { return null; }\n" + - "}\n" + - "class X1 {}\n" + - "class X2 extends X1 {\n" + - " void foo(){}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " le = fill(le, new X2());\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89454 - public void test0567() { - this.runConformTest( - new String[] { - "Thrower.java", - "public interface Thrower {\n" + - " public void throwIt() throws E;\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "GenericsTest.java", - "public class GenericsTest {\n" + - " public static void main(String[] args) throws MyException {\n" + - " Thrower thrower = new Thrower() {\n" + - " public void throwIt() throws MyException {\n" + - " throw new MyException();\n" + - " }\n" + - " };\n" + - " try {\n" + - " thrower.throwIt();\n" + - " } catch(Exception e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n" + - "class MyException extends Exception {\n" + - "}\n", - }, - "SUCCESS", - null, - false, - null); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89448 - public void test0568() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public static void main(String[] args) {\n" + - "\n" + - " ArrayList> n = new ArrayList>();\n" + - " ArrayList arr = new ArrayList();\n" + - " arr.add(new Long(5));\n" + - " n.add(arr);\n" + - " \n" + - " List> m = n; // Whoa!\n" + - " \n" + - " for(Long l : m.get(0)) {\n" + - " System.out.println(l);\n" + - " }\n" + - " }\n" + - "\n" + - "}\n", - }, - "5"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89778 - public void test0569() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X\n" + - "{\n" + - " protected static void foo() throws T, Exce {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " protected static void foo() throws T, Exce {\n" + - " ^^^^\n" + - "Exce cannot be resolved to a type\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90147 - public void test0570() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public class InnerClass implements Comparable {\n" + - " public int compareTo(T other) {\n" + - " return -1;\n" + - " }\n" + - " }\n" + - " \n" + - " public void foo() {\n" + - " InnerClass a = new InnerClass();\n" + - " InnerClass b = new InnerClass();\n" + - " // The following line does not compile (anymore):\n" + - " a.compareTo(b);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " a.compareTo(b);\n" + - " ^^^^^^^^^\n" + - "The method compareTo(T) in the type X.InnerClass is not applicable for the arguments (X.InnerClass)\n" + - "----------\n"); - } - public void test0571() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "interface IFoo {\n" + - " void foo();\n" + - "}\n" + - "class Box {\n" + - " T value() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "interface IBar {\n" + - " void bar();\n" + - "}\n" + - "\n" + - "public class X {\n" + - " void test01(Box box) {\n" + - " box.value().foo();\n" + - " }\n" + - " void test02(Box box) {\n" + - " box.value().foo();\n" + - " box.value().bar();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - // compiler options - null /* no class libraries */, - null /* no custom options */, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90430 - public void test0572() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public > void doWithEnumClass(Class enumClass) {\n" + - " }\n" + - "\n" + - " public void f() {\n" + - " Class cl = null; // Returned by Class.forName(\"xyz\");\n" + - " doWithEnumClass((Class) cl);\n" + - " }\n" + - "}\n", - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90430 - check unchecked warnings - public void test0573() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public > void doWithEnumClass(Class enumClass) {\n" + - " Zork z;\n" + - " }\n" + - "\n" + - " public void f() {\n" + - " Class cl = null; // Returned by Class.forName(\"xyz\");\n" + - " doWithEnumClass((Class) cl);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " doWithEnumClass((Class) cl);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation doWithEnumClass(Class) of the generic method doWithEnumClass(Class) of type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " doWithEnumClass((Class) cl);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Class to Class\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " doWithEnumClass((Class) cl);\n" + - " ^^^^\n" + - "Enum is a raw type. References to generic type Enum should be parameterized\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 - variation - public void test0574() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " class C2 {\n" + - " T foo(Object o) { return null; } // ok\n" + - " T foo(Object o) { return null; } // ok\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().new C2().foo((List) null);\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " T foo(Object o) { return null; } // ok\n" + - " ^^^^^^^\n" + - "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " T foo(Object o) { return null; } // ok\n" + - " ^^^^^^\n" + - "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " new X().new C2().foo((List) null);\n" + - " ^^^\n" + - "The method foo(Object) is ambiguous for the type X.C2\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with field ref - public void test0575() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f1 = new Foo();\n" + - " (f1).bar = (f1).bar;\n" + - " }\n" + - " static class Foo {\n" + - " Bar bar = new Bar();\n" + - " }\n" + - " static class Bar {\n" + - " T t;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " (f1).bar = (f1).bar;\n" + - " ^^^^^^^^\n" + - "Type mismatch: cannot convert from X.Bar to X.Bar\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with single ref - public void test0576() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f1 = new Foo();\n" + - " Foo f2 = new Foo();\n" + - " f1 = f1;\n" + - " f1 = f2;\n" + - " }\n" + - " static class Foo {\n" + - " }\n" + - "}\n" - }, - ""); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with qualified name ref - public void test0577() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f1 = new Foo();\n" + - " (f1).bar = f1.bar;\n" + - " }\n" + - " static class Foo {\n" + - " Bar bar = new Bar();\n" + - " }\n" + - " static class Bar {\n" + - " T t;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " (f1).bar = f1.bar;\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from X.Bar to X.Bar\n" + - "----------\n"); - } - // check array bound for wildcard - public void test0578() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(Box box) {\n" + - " int[] ints = box.get();\n" + - " }\n" + - "}\n" + - "class Box {\n" + - " T get() { return null; }\n" + - "}\n" - }, - ""); - } - // check array bound for wildcard - public void test0579() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(Box box) {\n" + - " int[] ints = box.get();\n" + - " }\n" + - "}\n" + - "class Box {\n" + - " T get() { return null; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " int[] ints = box.get();\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? super int[] to int[]\n" + - "----------\n"); - } - // check array bound for wildcard - public void test0580() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(Box box) {\n" + - " int[] ints = box.get();\n" + - " }\n" + - "}\n" + - "class Box {\n" + - " T get() { return null; }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " int[] ints = box.get();\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? to int[]\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation - public void test0581() { - this.runNegativeTest( - new String[] { - "X.java", - "class X {" + - " public static void main(String[] args) {\n" + - " Foo f1 = new Foo();\n" + - " f1.bar = f1.bar;\n" + - " }\n" + - " }\n" + - "class Foo {\n" + - " Bar bar = new Bar();\n" + - "}\n" + - "class Bar {\n" + - " T t;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " f1.bar = f1.bar;\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from Bar to Bar\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - public void test0582() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "class X {\n" + - " void foo(List l1) {\n" + - " C1 c1 = (C1)l1.get(0);\n" + - " }\n" + - "}\n" + - "interface I1{}\n" + - "class C1{}\n" - }, - ""); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91021 - public void test0583() { - this.runNegativeTest( - new String[] { - "X.java", - "class D {\n" + - " public D (D anotherD) {\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static class C {\n" + - " public C(C anotherC) {\n" + - " }\n" + - " }\n" + - "\n" + - " public void mD(D d) {\n" + - " //the following line is OK (no warning reported)\n" + - " new D(d);\n" + - " }\n" + - " \n" + - " public void mC(C c) {\n" + - " /* type safety warning\n" + - " * (The expression of type X.C\n" + - " * needs unchecked conversion to conform to\n" + - " * XSB.C)\n" + - " */\n" + - " new C(c);\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 25)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91017 - public void test0584() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List stringList = new ArrayList();\n" + - " stringList.add(\"foo\");\n" + - " List intList = new ArrayList();\n" + - " intList.add(1);\n" + - "\n" + - " List untypedList = stringList;\n" + - " List untypedList2 = intList;\n" + - "\n" + - " //correctly flagged as error: untypedList.add(new Object());\n" + - " //ditto: untypedList.add(untypedList2.get(0));\n" + - "\n" + - " //but this is not flagged at all by eclipse:\n" + - " untypedList.addAll(untypedList2);\n" + - "\n" + - " for(String s : stringList){\n" + - " //next line generates runtime ClassCastException\n" + - " Logger.log(\"Test_Lists.main: s: \" + s);\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 18)\n" + - " untypedList.addAll(untypedList2);\n" + - " ^^^^^^\n" + - "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + - "----------\n" + - "2. ERROR in X.java (at line 22)\n" + - " Logger.log(\"Test_Lists.main: s: \" + s);\n" + - " ^^^^^^\n" + - "Logger cannot be resolved\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90881 - public void test0585() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Outer.Comparator i = new Outer.Comparator() {\n" + - "\n" + - " public boolean equals(String a, String b) {\n" + - " return false;\n" + - " }\n" + - "\n" + - " public int hashCode(String a) {\n" + - " return 0;\n" + - " }\n" + - " };\n" + - "\n" + - " }\n" + - "}\n" + - "\n" + - "class Outer {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Outer.Comparator i = new Outer.Comparator() {\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Outer.Comparator cannot be resolved to a type\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Outer.Comparator i = new Outer.Comparator() {\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Outer.Comparator cannot be resolved to a type\n" + - "----------\n"); - } - - // ** - // note: the test does not show the needed unchecked warning, since it is - // a conform test - public void test0586() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class BB { }\n" + - " static class BD extends BB { }\n" + - " void f() {\n" + - " BB bb = null;\n" + - " Object o = (BD) bb;\n" + - " }\n" + - "}\n", - }, - ""); - } - - public void test0587() { - this.runConformTest( - new String[] { - "X.java", - "interface DA {\n" + - "}\n" + - "interface DB extends DA {\n" + - "}\n" + - "interface DC extends DA {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Object o = (DC) (DA) null;\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90433 - // ** - public void test0588() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " public void f() {\n" + - " Class> cc = Long.class;\n" + - " Class currentClass = null;\n" + - " boolean b = currentClass == Long.class;\n" + - " boolean c = X.class == Long.class;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " boolean c = X.class == Long.class;\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Incompatible operand types Class and Class\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - public void test0589() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void addAll(List target, List source) {\n" + - " target.addAll(source);\n" + - " }\n" + - "\n" + - " public static void main(String... args) {\n" + - " List ints = new ArrayList();\n" + - " ints.add(3);\n" + - "\n" + - " List floats = new ArrayList();\n" + - " floats.add(3f);\n" + - "\n" + - " new X().addAll(ints, floats);\n" + - "\n" + - " for (Integer integer : ints) {\n" + - " System.out.println(integer.intValue());\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " target.addAll(source);\n" + - " ^^^^^^\n" + - "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation - public void test0590() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void assignAll(Class sup, Class ext) {\n" + - " Class superSup = sup.getSuperclass();\n" + - " Class superExt = ext.getSuperclass();\n" + - " Class superSup2 = ext.getSuperclass();\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Class superSup2 = ext.getSuperclass();\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation - public void test0591() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public Values foo(Box box) {\n" + - " return selectedValues(box.getValues());\n" + - " }\n" + - " public static Values selectedValues(Values v) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - ""); - } - public void test0592() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List l;\n" + - " void m() {\n" + - " m2(l);\n" + - " }\n" + - " void m2(List l2) {\n" + - " l2.add(l2.remove(0));\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0593() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + - " List> classes2 = Arrays.asList(String.class, Boolean.class);\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List>> to List>\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " List> classes2 = Arrays.asList(String.class, Boolean.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class> is created for a varargs parameter\n" + - "----------\n"); - } - public void test0594() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.*;\n" + - "import static java.util.Map.*;\n" + - "\n" + - "abstract class MyIterator implements Iterator {\n" + - " Set iteratedSet;\n" + - "}\n" + - "public class X {\n" + - " \n" + - " void foo() {\n" + - " Map map;\n" + - " Iterator> it = map.entrySet().iterator();\n" + - "\n" + - " Entry unrelatedEntry;\n" + - " MyIterator> mit = (MyIterator>) it;\n" + - " mit.iteratedSet.add(unrelatedEntry);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " Iterator> it = map.entrySet().iterator();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Iterator> to Iterator>\n" + - "----------\n"); - } - public void test0595() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.*;\n" + - "import static java.util.Map.*;\n" + - "\n" + - "abstract class MyIterator implements Iterator {\n" + - " Set iteratedSet;\n" + - "}\n" + - "public class X {\n" + - " \n" + - " void bar() {\n" + - " Map map;\n" + - " Iterator> it = map.entrySet().iterator();\n" + - "\n" + - " Entry unrelatedEntry;\n" + - " MyIterator> mit = (MyIterator>) it;\n" + - " mit.iteratedSet.add(unrelatedEntry);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " Iterator> it = map.entrySet().iterator();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Iterator> to Iterator>\n" + - "----------\n"); - } - public void test0596() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Set unmodifiableSet(Set set) {\n" + - " return set;\n" + - " }\n" + - " public void foo(Set s) {\n" + - " Set s2 = unmodifiableSet(s);\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0597() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Pair m() { \n" + - " return null; \n" + - " }\n" + - " void foo(X x) {\n" + - " x.m().first = x.m().second;\n" + - " }\n" + - "}\n" + - " \n" + - "class Pair {\n" + - " E first;\n" + - " F second;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " x.m().first = x.m().second;\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#2-of ? to capture#1-of ?\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - public void test0598() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "class X implements Comparable {\n" + - "\n" + - " public int compareTo(Object o) {\n" + - " return 0;\n" + - " }\n" + - "\n" + - "}\n" + - "\n" + - "class Y {\n" + - " public static void main(String[] args) {\n" + - " List lx = null;\n" + - " Collections.sort(lx);\n" + - " }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - variation - public void test0599() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X implements Comparable {\n" + - " public static void main(String[] args) {\n" + - " Zork z;\n" + - " \n" + - " List lx = null;\n" + - " sort1(lx);\n" + - " sort2(lx);\n" + - " sort3(lx);\n" + - " sort4(lx);\n" + - " sort5(lx);\n" + - " }\n" + - " public int compareTo(Object o) {\n" + - " return 0;\n" + - " }\n" + - " static > void sort1(List list) {}\n" + - " static > void sort2(List list) {}\n" + - " static > void sort3(List list) {}\n" + - " static > void sort4(List list) {}\n" + - " static void sort5(List list) {}\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public class X implements Comparable {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " sort1(lx);\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort1(List) of the generic method sort1(List) of type X\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " sort2(lx);\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort2(List) of the generic method sort2(List) of type X\n" + - "----------\n" + - "5. WARNING in X.java (at line 11)\n" + - " sort4(lx);\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort4(List) of the generic method sort4(List) of type X\n" + - "----------\n" + - "6. WARNING in X.java (at line 21)\n" + - " static void sort5(List list) {}\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - variation - public void test0600() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X implements Comparable {\n" + - " public static void main(String[] args) {\n" + - " Zork z;\n" + - " \n" + - " List le = null;\n" + - " sort6(le);\n" + - " sort7(le);\n" + - " sort8(le);\n" + - " sort9(le);\n" + - " sort10(le);\n" + - " }\n" + - " public int compareTo(Object o) {\n" + - " return 0;\n" + - " }\n" + - " static > void sort6(List list) {}\n" + - " static > void sort7(List list) {}\n" + - " static > void sort8(List list) {}\n" + - " static > void sort9(List list) {}\n" + - " static void sort10(List list) {}\n" + - "}\n" + - "class MyEnum> {}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public class X implements Comparable {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " List le = null;\n" + - " ^^^^^^\n" + - "MyEnum is a raw type. References to generic type MyEnum should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " sort6(le);\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort6(List) of the generic method sort6(List) of type X\n" + - "----------\n" + - "5. WARNING in X.java (at line 9)\n" + - " sort7(le);\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort7(List) of the generic method sort7(List) of type X\n" + - "----------\n" + - "6. WARNING in X.java (at line 11)\n" + - " sort9(le);\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort9(List) of the generic method sort9(List) of type X\n" + - "----------\n" + - "7. WARNING in X.java (at line 21)\n" + - " static void sort10(List list) {}\n" + - " ^^^^^^\n" + - "MyEnum is a raw type. References to generic type MyEnum should be parameterized\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation - public void test0601() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public Values foo(Box box) {\n" + - " return selectedValues(box.getValues());\n" + - " }\n" + - " public static Values selectedValues(Values v) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " return selectedValues(box.getValues());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Values to Values\n" + - "----------\n"); - } - public void test0602() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void foo(Box box) {\n" + - " box.getValues()[0] = box.getValues()[1];\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values[] getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " box.getValues()[0] = box.getValues()[1];\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Values to Values\n" + - "----------\n"); - } - public void test0603() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void foo(Box[] boxes) {\n" + - " boxes[0] = boxes[1];\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values[] getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - ""); - } - // capture on array ref - public void test0604() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void foo(Box[] boxes) {\n" + - " bar(boxes[0], boxes[1]);\n" + - " }\n" + - " void bar(V v1, V v2) {}\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values[] getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - ""); - } - // capture on array ref - public void test0605() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void foo(Box box) {\n" + - " box.getValues()[1] = box.getValues()[2];\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values[] getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " box.getValues()[1] = box.getValues()[2];\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Values to Values\n" + - "----------\n"); - } - public void test0606() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void foo(Box box) {\n" + - " box.getValues()[1] = (Values) box.getValues()[2];\n" + - " }\n" + - " void bar(V v1, V v2) {}\n" + - "}\n" + - "\n" + - "abstract class Box {\n" + - " abstract Values[] getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " box.getValues()[1] = (Values) box.getValues()[2];\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Values to Values\n" + - "----------\n"); - } - public void test0607() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void test01() {\n" + - " List> lObj = new ArrayList> ();\n" + - " Collections.sort (lObj); \n" + - " }\n" + - " void test02() {\n" + - " List lComp = new ArrayList ();\n" + - " Collections.sort (lComp); \n" + - " }\n" + - " void test03() {\n" + - " List> lStr = new ArrayList> ();\n" + - " Collections.sort (lStr);\n" + - " }\n" + - " }\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " List lComp = new ArrayList ();\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " List lComp = new ArrayList ();\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " Collections.sort (lComp); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort(List) of the generic method sort(List) of type Collections\n" + - "----------\n" + - "4. ERROR in X.java (at line 15)\n" + - " Collections.sort (lStr);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method sort(List) of type Collections is not applicable for the arguments (List>). The inferred type Comparable is not a valid substitute for the bounded parameter >\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84284 - check warnings - public void test0608() { - this.runNegativeTest( - new String[] { - "Ball.java", - "import java.util.*;\n" + - "class Ball implements Comparable {\n" + - "\n" + - " public int compareTo(Object o) {\n" + - " return 0;\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " LinkedList foo = new LinkedList();\n" + - " Collections.sort(foo);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in Ball.java (at line 2)\n" + - " class Ball implements Comparable {\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "2. WARNING in Ball.java (at line 10)\n" + - " Collections.sort(foo);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation sort(List) of the generic method sort(List) of type Collections\n" + - "----------\n" + - "3. ERROR in Ball.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81831 - public void test0609() { - this.runConformTest( - new String[] { - "I.java", - "interface I> {}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89940 - public void test0610() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void foo(List objects, List raw) {\n" + - "\n" + - " List numbers;\n" + - " List ext;\n" + - " \n" + - " numbers= (List) objects; // correct - cast error\n" + - " ext= (List) objects; // wrong, should fail\n" + - "\n" + - " ext= raw; // correct - raw conversion warning issued\n" + - " numbers= raw; // correct - raw conversion warning issued\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " void foo(List objects, List raw) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " numbers= (List) objects; // correct - cast error\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " ext= (List) objects; // wrong, should fail\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " ext= raw; // correct - raw conversion warning issued\n" + - " ^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 13)\n" + - " numbers= raw; // correct - raw conversion warning issued\n" + - " ^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91696 - public void test0611() { - this.runConformTest( - new String[] { - "C.java", - "import java.io.Serializable;\n" + - "\n" + - "interface A, S extends A.BS> {\n" + - " public interface BS extends Serializable {\n" + - " }\n" + - " public interface BK extends Serializable {\n" + - " public void put(SS a);\n" + - " }\n" + - "\n" + - " public P getP();\n" + - "}\n" + - "\n" + - "class P, S extends A.BS> {\n" + - " K k;\n" + - " S s;\n" + - "\n" + - " public void put() {\n" + - " k.put(s);\n" + - " }\n" + - "}\n" + - "\n" + - "public class C implements A {\n" + - " public static class K implements A.BK {\n" + - " public void put(S a) {\n" + - " }\n" + - " }\n" + - " protected static class S implements A.BS {\n" + - " }\n" + - "\n" + - " public P getP() {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0612() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "class MPair {}\n" + - "\n" + - "public class X {\n" + - " private static class Bucket extends LinkedList> {}\n" + - " private Bucket[] buckets = new X.Bucket[100];\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " private static class Bucket extends LinkedList> {}\n" + - " ^\n" + - "Cannot make a static reference to the non-static type K\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " private static class Bucket extends LinkedList> {}\n" + - " ^\n" + - "Cannot make a static reference to the non-static type V\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " private Bucket[] buckets = new X.Bucket[100];\n" + - " ^^^^^^^\n" + - "The field X.buckets is never read locally\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - public void test0613() { - this.runNegativeTest( - new String[] { - "Map.java", - "package xy;\n" + - "import xy.Map.Entry;\n" + - "\n" + - "class Map {\n" + - " class Entry { }\n" + - "}\n" + - "class User {\n" + - " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + - " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + - " void b(Entry e) { } // OK\n" + - " void d(Map.Entry e) { } // OK\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Map.java (at line 8)\n" + - " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + - " ^^^^^\n" + - "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "2. ERROR in Map.java (at line 9)\n" + - " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + - " ^^^^^^^^^\n" + - "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "3. WARNING in Map.java (at line 10)\n" + - " void b(Entry e) { } // OK\n" + - " ^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation - public void test0614() { - this.runNegativeTest( - new String[] { - "X1.java", - "class X1 {\n" + - " static class X2 {\n" + - " class X3 {\n" + - " }\n" + - " }\n" + - "}\n" + - "class Y1 {\n" + - " class Y2 extends X1.X2 {\n" + - " void foo() {\n" + - " X3 x;\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X1.java (at line 13)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation - public void test0615() { - this.runNegativeTest( - new String[] { - "X1.java", - "class X1 {\n" + - " static class X2 {\n" + - " class X3 {\n" + - " }\n" + - " }\n" + - "}\n" + - "class Y1 {\n" + - " class Y2 extends X1.X2 {\n" + - " void foo() {\n" + - " X3 x;\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X1.java (at line 8)\n" + - " class Y2 extends X1.X2 {\n" + - " ^^^^^\n" + - "X1.X2 is a raw type. References to generic type X1.X2 should be parameterized\n" + - "----------\n" + - "2. ERROR in X1.java (at line 10)\n" + - " X3 x;\n" + - " ^^\n" + - "The member type X1.X2.X3 must be qualified with a parameterized type, since it is not static\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation - public void test0616() { - this.runNegativeTest( - new String[] { - "Map.java", - "package xy;\n" + - "import xy.Map.Entry;\n" + - "\n" + - "class Map {\n" + - " class Entry { }\n" + - "}\n" + - "class User extends Map {\n" + - " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + - " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + - " void b(Entry e) { } // OK\n" + - " void d(Map.Entry e) { } // OK\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Map.java (at line 9)\n" + - " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + - " ^^^^^^^^^\n" + - "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "2. WARNING in Map.java (at line 10)\n" + - " void b(Entry e) { } // OK\n" + - " ^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n"); - } -public void test0617() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void foo() {\n" + - " String s = null;\n" + - " ZZZ1.ZZZ2.ZZZ3 var = null;\n" + - " s = var;\n" + - " }\n" + - "}\n" + - "\n" + - "class ZZZ1 {\n" + - " class ZZZ2 {\n" + - " class ZZZ3 {}\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " s = var;\n" + - " ^^^\n" + - "Type mismatch: cannot convert from ZZZ1.ZZZ2.ZZZ3 to String\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation - public void test0618() { - this.runNegativeTest( - new String[] { - "Map.java", - "class Map {\n" + - " class Entry { }\n" + - " class Foo {\n" + - " Entry entry;\n" + - " static void foo(Entry e) { } // invalid static ref\n" + - " }\n" + - " static class Bar {\n" + - " Entry entry; // invalid static ref\n" + - " }\n" + - " void a(Entry e) { } // OK\n" + - " void c(Map.Entry e) { } // illegal \n" + - " void b(Entry e) { } // OK\n" + - " void d(Map.Entry e) { } // OK\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Map.java (at line 5)\n" + - " static void foo(Entry e) { } // invalid static ref\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "The method foo cannot be declared static; static methods can only be declared in a static or top level type\n" + - "----------\n" + - "2. ERROR in Map.java (at line 5)\n" + - " static void foo(Entry e) { } // invalid static ref\n" + - " ^^^^^\n" + - "Cannot make a static reference to the non-static type Entry\n" + - "----------\n" + - "3. ERROR in Map.java (at line 8)\n" + - " Entry entry; // invalid static ref\n" + - " ^^^^^\n" + - "Cannot make a static reference to the non-static type Entry\n" + - "----------\n" + - "4. ERROR in Map.java (at line 11)\n" + - " void c(Map.Entry e) { } // illegal \n" + - " ^^^^^^^^^\n" + - "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "5. WARNING in Map.java (at line 12)\n" + - " void b(Entry e) { } // OK\n" + - " ^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89440 - public void test0619() { - this.runConformTest( - new String[] { - "X.java", - "interface ISample {\n" + - " public static enum Stuff {\n" + - " FIRST, SECOND, THIRD\n" + - " };\n" + - "}\n" + - "\n" + - "class SampleClass {\n" + - " public void doSomething(ISample.Stuff thing) {\n" + - "\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public void doSomething() {\n" + - " SampleClass sample = new SampleClass();\n" + - " sample.doSomething(ISample.Stuff.FIRST);\n" + - " }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - public void test0620() { - this.runNegativeTest( - new String[] { - "Outer.java", - "public class Outer {\n" + - " class Inner { }\n" + - " \n" + - " static void test(Inner i) { }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Outer.java (at line 4)\n" + - " static void test(Inner i) { }\n" + - " ^^^^^\n" + - "Cannot make a static reference to the non-static type Inner\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551- variation - public void test0621() { - this.runConformTest( - new String[] { - "Outer.java", - "public class Outer {\n" + - " class Inner { }\n" + - " \n" + - " static void test(Inner i) { }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - variation - public void test0622() { - this.runConformTest( - new String[] { - "Outer.java", - "public class Outer {\n" + - " static class Inner { }\n" + - " \n" + - " static void test(Inner i) { }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - variation - public void test0623() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Outer {\n" + - " class Inner { }\n" + - " static void test(Inner i) { }\n" + - " }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83034 - public void test0624() { - this.runConformTest( - new String[] { - "X.java", - " interface IFoo> {\n" + - " V bar(int i);\n" + - "}\n" + - "\n" + - "public class X> {\n" + - " \n" + - " public boolean foo(X x) {\n" + - " return false;\n" + - " }\n" + - " public boolean baz(IFoo f) {\n" + - " return foo(f.bar(0));\n" + - " }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83034 - variation - public void test0625() { - this.runConformTest( - new String[] { - "Foo.java", - "public class Foo {\n" + - " public enum Mode {\n" + - " A\n" + - " };\n" + - " public void test(Mode mode) {\n" + - " }\n" + - "} \n", - }, - ""); - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " enum Keys {\n" + - " B\n" + - " };\n" + - " public void test() {\n" + - " Foo foo = new Foo();\n" + - " foo.test(Foo.Mode.A); // error\n" + - " }\n" + - "} \n", - }, - "", - null, - false, - null); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92037 - public void test0626() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " private static class A {\n" + - "\n" + - " }\n" + - "\n" + - " private static class B {\n" + - "\n" + - " }\n" + - "\n" + - " private static class AA extends A {\n" + - "\n" + - " }\n" + - "\n" + - " private static class C extends B {\n" + - "\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " B b = new B();\n" + - " System.out.println(b instanceof C);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " private static class B {\n" + - " ^\n" + - "The type parameter A is hiding the type X.A\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " private static class AA extends A {\n" + - " ^^\n" + - "Access to enclosing constructor X.A() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "3. WARNING in X.java (at line 15)\n" + - " private static class C extends B {\n" + - " ^\n" + - "Access to enclosing constructor X.B() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "4. ERROR in X.java (at line 21)\n" + - " System.out.println(b instanceof C);\n" + - " ^^^^^^^^^^^^^^\n" + - "Incompatible conditional operand types X.B and X.C\n" + - "----------\n"); - } - public void test0627() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " List foo(List l1, List l2) {\n" + - " return l1;\n" + - " }\n" + - " void bar(List l1, List l2) {\n" + - " String s = foo(l1, l2);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " String s = foo(l1, l2);\n" + - " ^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to String\n" + - "----------\n"); - } - // check capture for conditional operator - public void test0628() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " List foo(List l1, List l2) {\n" + - " return l1;\n" + - " }\n" + - " void bar(List l1, List l2) {\n" + - " List l3 = null;\n" + - " String s = l1 != null ? foo(l1, l2) : l3;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " String s = l1 != null ? foo(l1, l2) : l3;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to String\n" + - "----------\n"); - } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=92556 - public void test0629() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public abstract class Context {\n" + - " private Strategy> strategy;\n" + - " public void setStrategy(Strategy> strategy) {\n" + - " this.strategy = strategy;\n" + - " }\n" + - " // m?thode qui utilise la strat?gie\n" + - " public N call() throws Exception {\n" + - " return this.strategy.call(this);\n" + - " }\n" + - " }\n" + - " public interface Strategy> {\n" + - " public abstract N call(C context);\n" + - " }\n" + - "\n" + - "} \n", - }, - ""); - } - public void test0630() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "@SuppressWarnings(\"null\")\n" + - "public class X {\n" + - "\n" + - " void test0() {\n" + - " List arrays= new ArrayList();\n" + - " Number[] a= null;\n" + - " arrays.add(null);\n" + - " arrays.add(a); // Error: The method add(capture-of ? super Number[]) in the type List is not applicable for the arguments (Number[])\n" + - " }\n" + - "\n" + - " void test01() {\n" + - " List arrays= new ArrayList();\n" + - " Number[] a= null;\n" + - " arrays.add(null);\n" + - " arrays.add(a); // Error: The method add(capture-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + - " }\n" + - " \n" + - " void test02() {\n" + - " List nums= null;\n" + - " Number n= null;\n" + - " nums.add(null);\n" + - " nums.add(n);\n" + - " }\n" + - "\n" + - " void test3() {\n" + - " List> nums= null;\n" + - " List n= null;\n" + - " nums.add(null);\n" + - " nums.add(n);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 18)\n" + - " arrays.add(a); // Error: The method add(capture-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + - " ^^^\n" + - "The method add(capture#4-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93044 - public void test0631() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.annotation.RetentionPolicy;\n" + - "\n" + - "public class X\n" + - "{\n" + - " public static void main(String[] args)\n" + - " {\n" + - " Class> c = RetentionPolicy.class;\n" + - " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + - " ^^^^^^^\n" + - "Bound mismatch: The generic method valueOf(Class, String) of type Enum is not applicable for the arguments (Class>, String). The inferred type capture#1-of ? extends Enum is not a valid substitute for the bounded parameter >\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982 - public void test0632() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Vector;\n" + - "\n" + - "@SuppressWarnings(\"null\")\n" + - "public class X {\n" + - " void test01() {\n" + - " Vector lhs = null;\n" + - " Vector rhs = null;\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - " void test02() {\n" + - " Vector lhs = null;\n" + - " Vector rhs = null;\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - " void test3() {\n" + - " Vector lhs = null;\n" + - " Vector rhs = null;\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - " void test4() {\n" + - " Vector lhs = null;\n" + - " Vector rhs = null;\n" + - " lhs.add(rhs.get(0));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#3-of ? extends Object[]) in the type Vector is not applicable for the arguments (capture#4-of ? extends Object[])\n" + - "----------\n" + - "2. ERROR in X.java (at line 18)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#5-of ? super Object[]) in the type Vector is not applicable for the arguments (capture#6-of ? super Object[])\n" + - "----------\n" + - "3. ERROR in X.java (at line 23)\n" + - " lhs.add(rhs.get(0));\n" + - " ^^^\n" + - "The method add(capture#7-of ? extends Object[]) in the type Vector is not applicable for the arguments (capture#8-of ? super Object[])\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982 - variation - public void test0633() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.util.Vector;\n" + - "\n" + - "public class X {\n" + - " void test1() {\n" + - " Vector lhs = null;\n" + - " Vector rhs = null;\n" + - " lhs.add(rhs.get(0)); \n" + - " foo(rhs.get(0)); // ok #foo(Object[])\n" + - " }\n" + - " void foo(Object[] objs) {\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90775 - public void test0634() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.reflect.Array;\n" + - "\n" + - "public class X {\n" + - "\n" + - " T[] theArray;\n" + - "\n" + - " public X(Class clazz) {\n" + - " theArray = (T[]) Array.newInstance(clazz, 10); // Compiler warning\n" + - " }\n" + - "\n" + - " public T get(int i) {\n" + - " return theArray[i];\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X t = new X(Integer.class);\n" + - " // GenericsArray1 t = new GenericsArray1( int.class );\n" + - " Object[] o = t.theArray;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " theArray = (T[]) Array.newInstance(clazz, 10); // Compiler warning\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to T[]\n" + - "----------\n" + - "2. ERROR in X.java (at line 20)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93298 - public void test0635() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "public class X {\n" + - " public static class Indexed {\n" + - " public Iterator foo() {\n" + - " return new IndexedIter();\n" + - " }\n" + - " class IndexedIter implements Iterator {\n" + - " public boolean hasNext() {\n" + - " return false;\n" + - " }\n" + - " public U next() {\n" + - " return null;\n" + - " }\n" + - " public void remove() {\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=78084 - public void test0636() { - this.runNegativeTest( - new String[] { - "X.java", - "public abstract class X {\n" + - " public final T element() {\n" + - " T result = (T) customElement(); // reports unnecessary cast\n" + - " return result;\n" + - " }\n" + - " protected abstract Object customElement();\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " T result = (T) customElement(); // reports unnecessary cast\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84968 - public void test0637() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static final class Ex1 extends Exception {\n" + - " private static final long serialVersionUID = 1;\n" + - " }\n" + - "\n" + - " private void a1() {\n" + - " try {\n" + - " a1_1();\n" + - " } catch (Ex1 si) {\n" + - " assert si != null;\n" + - " }\n" + - " }\n" + - "\n" + - " protected Object a1_1() throws Ex1 {\n" + - " return null;\n" + - " }\n" + - "\n" + - " private void a2() {\n" + - " try {\n" + - " a2_1();\n" + - " } catch (Ex2 si) {\n" + - " assert si != null;\n" + - " }\n" + - " }\n" + - "\n" + - " protected Object a2_1() throws Ex2 {\n" + - " return null;\n" + - " }\n" + - "\n" + - " public final static class Ex3 extends Exception {\n" + - " private static final long serialVersionUID = 1;\n" + - " }\n" + - "\n" + - " private void a3() {\n" + - " try {\n" + - " a3_1();\n" + - " } catch (Ex3 si) {\n" + - " assert si != null;\n" + - " }\n" + - " }\n" + - "\n" + - " protected Object a3_1() throws Ex3 {\n" + - " return null;\n" + - " }\n" + - "\n" + - "}\n" + - "\n" + - "final class Ex2 extends Exception {\n" + - " private static final long serialVersionUID = 1;\n" + - "}\n", - }, - ""); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93478 - public void test0638() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.concurrent.BlockingQueue;\n" + - "\n" + - "public class X {\n" + - " static interface IMX {\n" + - " void call(L a, S b);\n" + - " }\n" + - " static interface Y {\n" + - " void addX(final IMX a);\n" + - " void removeX(final IMX a);\n" + - " }\n" + - " static final class Pair {\n" + - " T first;\n" + - "\n" + - " V second;\n" + - " }\n" + - " static class Bar

{\n" + - " Bar(final BlockingQueue

a) {\n" + - "\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "final class Foo extends X.Bar> implements X.IMX {\n" + - " Foo(final BlockingQueue> in) {\n" + - " super(in);\n" + - " }\n" + - " public void call(L a, S b) {\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0639() { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.annotation.Annotation;\n" + - "import java.lang.reflect.*;\n" + - "\n" + - "@interface MyAnnotation {\n" + - "}\n" + - "public class X {\n" + - " void test() throws Exception {\n" + - " Class type = X.class;\n" + - " Method method = type.getMethod(\"test\");\n" + - " Constructor constructor = type.getConstructor();\n" + - " Field field = type.getField(\"field\");\n" + - " Package packge = type.getPackage();\n" + - " MyAnnotation typeAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation methodAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation constrAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation fieldAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation packgeAnnot = getAnnotation(MyAnnotation.class);\n" + - " }\n" + - "\n" + - " int field;\n" + - " \n" + - " U getAnnotation(Class annotatedType) {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0640() { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.annotation.Annotation;\n" + - "import java.lang.reflect.*;\n" + - "\n" + - "@interface MyAnnotation {\n" + - "}\n" + - "public class X {\n" + - " void test() throws Exception {\n" + - " Class type = X.class;\n" + - " Method method = type.getMethod(\"test\");\n" + - " Constructor constructor = type.getConstructor();\n" + - " Field field = type.getField(\"field\");\n" + - " Package packge = type.getPackage();\n" + - " MyAnnotation typeAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation methodAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation constrAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation fieldAnnot = getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation packgeAnnot = getAnnotation(MyAnnotation.class);\n" + - " }\n" + - "\n" + - " int field;\n" + - " \n" + - " U getAnnotation(Class annotatedType) {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0641() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.reflect.*;\n" + - "\n" + - "@interface MyAnnotation {\n" + - "}\n" + - "@SuppressWarnings(\"all\")\n" + - "public class X {\n" + - " void test() throws Exception {\n" + - " Class type = X.class;\n" + - " Method method = type.getMethod(\"test\");\n" + - " Constructor constructor = type.getConstructor();\n" + - " Field field = type.getField(\"field\");\n" + - " Package packge = type.getPackage();\n" + - " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation methodAnnot = method.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation fieldAnnot = field.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation packgeAnnot = packge.getAnnotation(MyAnnotation.class);\n" + - " }\n" + - "\n" + - " int field;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + - "----------\n" + - "2. ERROR in X.java (at line 15)\n" + - " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + - "----------\n"); - } - public void test0642() { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.reflect.*;\n" + - "\n" + - "@interface MyAnnotation {\n" + - "}\n" + - "@SuppressWarnings(\"all\")\n" + - "public class X {\n" + - " void test() throws Exception {\n" + - " Class type = X.class;\n" + - " Method method = type.getMethod(\"test\");\n" + - " Constructor constructor = type.getConstructor();\n" + - " Field field = type.getField(\"field\");\n" + - " Package packge = type.getPackage();\n" + - " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation methodAnnot = method.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation fieldAnnot = field.getAnnotation(MyAnnotation.class);\n" + - " MyAnnotation packgeAnnot = packge.getAnnotation(MyAnnotation.class);\n" + - " }\n" + - "\n" + - " int field;\n" + - "}\n", - }, - ""); - } - public void test0643() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " static U foo(U u) {\n" + - " return u;\n" + - " }\n" + - " \n" + - " void bar(X x) {\n" + - " String str = x.foo(\"hello\");\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0644() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " U foo(U u) {\n" + - " return u;\n" + - " }\n" + - " \n" + - " void bar(X x) {\n" + - " String str = x.foo(\"hello\");\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " void bar(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " String str = x.foo(\"hello\");\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " String str = x.foo(\"hello\");\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to String\n" + - "----------\n"); - } - public void test0645() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.annotation.Annotation;\n" + - "\n" + - "@interface MyAnnotation {\n" + - "}\n" + - "\n" + - "class X {\n" + - " void bar(XClass arg) {\n" + - " XClass xc = new XClass();\n" + - " String str = xc.getConstructor().getAnnotation(arg);\n" + - " }\n" + - "}\n" + - "\n" + - "class XClass {\n" + - " XConstructor getConstructor() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "class XConstructor {\n" + - " W getAnnotation(XClass cl) {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " XClass xc = new XClass();\n" + - " ^^^^^^\n" + - "XClass is a raw type. References to generic type XClass should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " XClass xc = new XClass();\n" + - " ^^^^^^\n" + - "XClass is a raw type. References to generic type XClass should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " String str = xc.getConstructor().getAnnotation(arg);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method getAnnotation(XClass) belongs to the raw type XConstructor. References to generic type XConstructor should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " String str = xc.getConstructor().getAnnotation(arg);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to String\n" + - "----------\n"); - } - public void test0646() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " X x = inner.setOuterT(new X());\n" + - " \n" + - " Outer.Inner innerS = inner;\n" + - " }\n" + - "}\n" + - "\n" + - "class Outer {\n" + - " T t;\n" + - " class Inner {\n" + - " T setOuterT(T t1) {\n" + - " t = t1;\n" + - " return t;\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " ^^^^^^^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " ^^^^^\n" + - "Outer is a raw type. References to generic type Outer should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " ^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 4)\n" + - " X x = inner.setOuterT(new X());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method setOuterT(Object) belongs to the raw type Outer.Inner. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 4)\n" + - " X x = inner.setOuterT(new X());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to X\n" + - "----------\n" + - "6. WARNING in X.java (at line 6)\n" + - " Outer.Inner innerS = inner;\n" + - " ^^^^^\n" + - "Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer.Inner\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - public void test0647() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " X x = inner.set(new X());\n" + - " \n" + - " Outer.Inner innerS = inner;\n" + - " }\n" + - "}\n" + - "\n" + - "class Outer {\n" + - " T t;\n" + - " static class Inner {\n" + - " U set(U u) {\n" + - " return u;\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " ^^^^^^^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " ^^^^^\n" + - "Outer is a raw type. References to generic type Outer should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Outer().new Inner();\n" + - " ^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 4)\n" + - " X x = inner.set(new X());\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method set(Object) belongs to the raw type Outer.Inner. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 4)\n" + - " X x = inner.set(new X());\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to X\n" + - "----------\n" + - "6. ERROR in X.java (at line 6)\n" + - " Outer.Inner innerS = inner;\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The member type Outer.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Outer\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - variation - public void test0648() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " Outer.Inner inner = new Sub().get();\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "class Outer {\n" + - " class Inner {\n" + - " }\n" + - "}\n" + - "class Sub extends Outer {\n" + - " Inner get() { return null; }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Sub().get();\n" + - " ^^^^^^^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " class Sub extends Outer {\n" + - " ^^^^^\n" + - "Outer is a raw type. References to generic type Outer should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " Inner get() { return null; }\n" + - " ^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n"); - } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - variation - public void test0649() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " Outer.Inner inner = new Sub().get();\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "class Outer {\n" + - " class Inner {\n" + - " }\n" + - "}\n" + - "class Sub extends Outer {\n" + - " Inner get() { return null; }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " Outer.Inner inner = new Sub().get();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer.Inner\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " class Sub extends Outer {\n" + - " ^^^^^\n" + - "Outer is a raw type. References to generic type Outer should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " Inner get() { return null; }\n" + - " ^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n"); - } - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89440 - public void test0650() { - this.runConformTest( - new String[] { - "p/A.java", - "package p;\n" + - "\n" + - "public interface A {\n" + - " public static enum Stuff {\n" + - " FIRST, SECOND, THIRD\n" + - " };\n" + - "}", - }, - ""); - this.runConformTest( - new String[] { - "q/SampleClass2.java", - "package q;\n" + - "\n" + - "import p.A.Stuff;\n" + - "\n" + - "public class SampleClass2 {\n" + - " public void doSomething(Stuff thing) {\n" + - " \n" + - " }\n" + - "}" - }, - "", - null, - false, - null); - this.runConformTest( - new String[] { - "q/SampleClass3.java", - "package q;\n" + - "\n" + - "import p.A;\n" + - "\n" + - "public class SampleClass3 {\n" + - " public void doSomething() {\n" + - " SampleClass2 sample = new SampleClass2();\n" + - " sample.doSomething(A.Stuff.FIRST);\n" + - " }\n" + - "}", - }, - "", - null, - false, - null); - } - public void test0651() { - runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " int field;\n" + - " static int FIELD;\n" + - "\n" + - " {\n" + - " field = 1;\n" + - " }\n" + - " static {\n" + - " FIELD = 1;\n" + - " }\n" + - "\n" + - " public Values foo(Box box) {\n" + - " return selectedValues(box.getValues()); // 1\n" + - " }\n" + - " public static Values selectedValues(Values v) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "abstract class Box { // Added bound for V\n" + - " abstract Values getValues();\n" + - "}\n" + - "abstract class Values {\n" + - "}\n", - }, - JavacTestOptions.EclipseHasABug.EclipseBug236217); - } - public void test0652() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Collection c = new HashSet();\n" + - " Set s = (Set)c;\n" + - " }\n" + - "}\n", - }, - ""); - } - public void test0653() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " static public void workaround(T a, T b) {\n" + - " a.addAll(b);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " static public void workaround(T a, T b) {\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " a.addAll(b);\n" + - " ^^^^^^^^^^^\n" + - "Type safety: The method addAll(Collection) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } - public void test0654() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Map myMap = new HashMap();\n" + - " myMap.put(\"key1\", \"1\");\n" + - "\n" + - " for (Map.Entry e : myMap.entrySet())\n" + - " System.out.println(\"Key = \" + e.getKey() + \" Value = \" + e.getValue());\n" + - " Set set = myMap.entrySet();\n" + - " for (Map.Entry e : set)\n" + - " System.out.println(\"Key = \" + e.getKey() + \" Value = \" + e.getValue());\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " Map myMap = new HashMap();\n" + - " ^^^\n" + - "Map is a raw type. References to generic type Map should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " Map myMap = new HashMap();\n" + - " ^^^^^^^\n" + - "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " myMap.put(\"key1\", \"1\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " for (Map.Entry e : myMap.entrySet())\n" + - " ^^^^^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 8)\n" + - " for (Map.Entry e : myMap.entrySet())\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from element type Object to Map.Entry\n" + - "----------\n" + - "6. WARNING in X.java (at line 10)\n" + - " Set set = myMap.entrySet();\n" + - " ^^^^^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 10)\n" + - " Set set = myMap.entrySet();\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Set needs unchecked conversion to conform to Set\n" + - "----------\n" + - "8. WARNING in X.java (at line 11)\n" + - " for (Map.Entry e : set)\n" + - " ^^^^^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n"); - } -// ** -public void test0655() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class BB { }\n" + - " static class BD extends BB { }\n" + - " void f() {\n" + - " BB bb = null;\n" + - " Object o = (BD) bb;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " Object o = (BD) bb;\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X.BB to X.BD\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " Object o = (BD) bb;\n" + - " ^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X.BB to X.BD\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test0656() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " protected Vector v = null;\n" + - "\n" + - " public void f() {\n" + - " ((String) (v.elementAt(0))).charAt(0);\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); -} -public void test0657() { - this.runConformTest( - new String[] { - "X.java", - "public class X{\n" + - " \n" + - " private static class GenericWrapper {\n" + - " private Elem theObject;\n" + - " public GenericWrapper(Elem arg) {\n" + - " theObject = arg;\n" + - " }\n" + - " public GenericWrapper (GenericWrapper other) {\n" + - " this.theObject = other.theObject;\n" + - " }\n" + - " public String toString() {\n" + - " return theObject.toString();\n" + - " }\n" + - " }\n" + - " private static GenericWrapper method (Object wrappedString) {\n" + - " return (GenericWrapper) wrappedString;\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.print(method(new GenericWrapper(\"abc\")));\n" + - " System.out.println(method(new GenericWrapper(new Exception())));\n" + - " }\n" + - "}\n", - }, - "abcjava.lang.Exception"); -} -public void test0658() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X{\n" + - " \n" + - " private static class GenericWrapper {\n" + - " Zork z;\n" + - " private Elem theObject;\n" + - " public GenericWrapper(Elem arg) {\n" + - " theObject = arg;\n" + - " }\n" + - " public GenericWrapper (GenericWrapper other) {\n" + - " this.theObject = other.theObject;\n" + - " }\n" + - " public String toString() {\n" + - " return theObject.toString();\n" + - " }\n" + - " }\n" + - " private static GenericWrapper method (Object wrappedString) {\n" + - " return (GenericWrapper) wrappedString;\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.print(method(new GenericWrapper(\"abc\")));\n" + - " System.out.println(method(new GenericWrapper(new Exception())));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 12)\n" + - " public String toString() {\n" + - " ^^^^^^^^^^\n" + - "The method toString() of type X.GenericWrapper should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "3. WARNING in X.java (at line 17)\n" + - " return (GenericWrapper) wrappedString;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to X.GenericWrapper\n" + - "----------\n"); -} -public void test0659() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.ref.*;\n" + - "\n" + - "@SuppressWarnings(\"unused\")\n" + - "public class X extends WeakReference {\n" + - " Zork z;\n" + - " static ReferenceQueue queue = new ReferenceQueue();\n" + - "\n" + - " private K key;\n" + - "\n" + - " public X(K key, V value, ReferenceQueue queue) {\n" + - " super(value, queue);\n" + - " }\n" + - "\n" + - " public K getKey() {\n" + - " return key;\n" + - " }\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"key:\" + key;\n" + - " }\n" + - "\n" + - " public static void main(String[] arg) throws Exception {\n" + - " X ref = new X(\"Dummy Key\", new Integer(5), queue);\n" + - " new Thread() {\n" + - " @Override\n" + - " public void run() {\n" + - " for (;;) {\n" + - " // force ref to be cleared\n" + - " System.gc();\n" + - " }\n" + - " }\n" + - " }.start();\n" + - "\n" + - " X fromQueue = (X) queue.remove();\n" + - " System.out.println(fromQueue);\n" + - " System.exit(0);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 34)\n" + - " X fromQueue = (X) queue.remove();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Reference to X\n" + - "----------\n"); -} -public void test0660() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " boolean run(X x) {\n" + - " return false;\n" + - " }\n" + - " void run(Class ct) {\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " boolean b = new X().run(new X(){});\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 -public void test0661() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " public X() {\n" + - " S a = (S)(Integer)3;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " S a = (S)(Integer)3;\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Integer to S\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation -public void test0662() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " public X() {\n" + - " S a = (S)(Integer)3; // this should fail\n" + - " }\n" + - " Zork z;\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " S a = (S)(Integer)3; // this should fail\n" + - " ^^^^^^^^^^^^^\n" + - "Cannot cast from Integer to S\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation -public void test0663() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " Object foo(Comparable c) {\n" + - " return (Comparable) c;\n" + - " }\n" + - " void foo(List lv) {\n" + - " List l = (List) lv;\n" + - " }\n" + - " void foo2(List> lv) {\n" + - " List l = (List>) lv;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " return (Comparable) c;\n" + - " ^\n" + - "S cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " List l = (List) lv;\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " List l = (List) lv;\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to List\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " List l = (List) lv;\n" + - " ^^^^^^^^^^^^\n" + - "Unnecessary cast from List to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 11)\n" + - " List l = (List>) lv;\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 11)\n" + - " List l = (List>) lv;\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List> to List>\n" + - "----------\n" + - "7. WARNING in X.java (at line 11)\n" + - " List l = (List>) lv;\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from List> to List>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation -public void test0664() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " public X(X2 x2) {\n" + - " S a = (S)x2;\n" + - " }\n" + - "}\n" + - "abstract class X2 implements Comparable {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " S a = (S)x2;\n" + - " ^^^^^\n" + - "Cannot cast from X2 to S\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation -public void test0665() { - this.runNegativeTest( - new String[] { - "Test.java", - "public class Test {\n" + - " void foo() {\n" + - " A a = new A();\n" + - " Comparable c = (Comparable) a; // Fails as expected\n" + - " Comparable c2 = (Comparable) a; // Should fail?\n" + - " }\n" + - "\n" + - "}\n" + - "\n" + - "final class A implements Comparable {\n" + - " public int compareTo(A o) {\n" + - " return 0;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Test.java (at line 4)\n" + - " Comparable c = (Comparable) a; // Fails as expected\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from A to Comparable\n" + - "----------\n" + - "2. WARNING in Test.java (at line 5)\n" + - " Comparable c2 = (Comparable) a; // Should fail?\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from A to Comparable\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89940 -public void test0666() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void foo(List objects, List raw) {\n" + - "\n" + - " List numbers;\n" + - " List ext;\n" + - " \n" + - " numbers= (List) objects; // correct - cast error\n" + - " ext= (List) objects; // wrong, should fail\n" + - "\n" + - " ext= raw; // correct - raw conversion warning issued\n" + - " numbers= raw; // correct - raw conversion warning issued\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " void foo(List objects, List raw) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " numbers= (List) objects; // correct - cast error\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " ext= (List) objects; // wrong, should fail\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " ext= raw; // correct - raw conversion warning issued\n" + - " ^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 13)\n" + - " numbers= raw; // correct - raw conversion warning issued\n" + - " ^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); -} -public void _test0667() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void foo(List l) { }\n" + - " \n" + - " public static void foo2(List l) { }\n" + - " \n" + - " public static void foo3(List l) { }\n" + - " \n" + - " public static void bar(List l) { }\n" + - " \n" + - " public static void bar2(List l) { }\n" + - " \n" + - " public static void bar3(List l) { }\n" + - " \n" + - " public static void bar4(List l) { }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " { // can be { Object, Object[] }\n" + - " List l = new ArrayList();\n" + - " l.add(l.get(0)); // illegal [01]\n" + - " l.add((Object) null); // illegal [02]\n" + - " l.add((Integer) null); // illegal [03]\n" + - " l.add((Object []) null); // illegal [04]\n" + - " l.add((Integer []) null); // illegal [05]\n" + - " l.add((Integer [][]) null); // illegal [06]\n" + - " \n" + - " foo(l); // List - legal [07]\n" + - " foo2(l); // List - illegal [08]\n" + - " foo3(l); // List - illegal [09]\n" + - " bar(l); // List - illegal [10]\n" + - " bar2(l); // List - illegal [11]\n" + - " bar3(l); // List - legal [12]\n" + - " bar4(l); // List - legal [13]\n" + - " }\n" + - " { // can be Object[] or (? extends Object)[]\n" + - " List l = new ArrayList();\n" + - " l.add(l.get(0)); // legal [14]\n" + - " l.add((Object) null); // illegal [15]\n" + - " l.add((Integer) null); // illegal [16]\n" + - " l.add((Object []) null); // legal [17]\n" + - " l.add((Integer []) null); // legal [18]\n" + - " l.add((Integer [][]) null); // legal [19]\n" + - " \n" + - " foo(l); // List - legal [20]\n" + - " foo2(l); // List - legal [21]\n" + - " foo3(l); // List - legal [22]\n" + - " bar(l); // List - illegal [23]\n" + - " bar2(l); // List - illegal [24]\n" + - " bar3(l); // List - legal [25]\n" + - " bar4(l); // List - legal [26]\n" + - " }\n" + - " { // Only allows wildcards, Object is illegal.\n" + - " List l = new ArrayList();\n" + - " l.add(l.get(0)); // illegal [27]\n" + - " l.add((Object) null); // illegal [28]\n" + - " l.add((Integer) null); // illegal [29]\n" + - " l.add((Object []) null); // illegal [30]\n" + - " l.add((Integer []) null); // illegal [31]\n" + - " l.add((Integer [][]) null); // illegal [32]\n" + - " \n" + - " foo(l); // List - illegal [33]\n" + - " foo2(l); // List - illegal [34]\n" + - " foo3(l); // List - legal [35]\n" + - " bar(l); // List - illegal [36]\n" + - " bar2(l); // List - illegal [37]\n" + - " bar3(l); // List - legal [38]\n" + - " bar4(l); // List - legal [39]\n" + - " }\n" + - " { // can add non-arrays but can only match ? super Object, ? super Object[], or ? extends Object, but not Object \n" + - " List l = new ArrayList();\n" + - " l.add(l.get(0)); // legal [40]\n" + - " l.add((Object) null); // legal [41]\n" + - " l.add((Integer) null); // legal [42]\n" + - " l.add((Object []) null); // illegal [43]\n" + - " l.add((Integer []) null); // illegal [44]\n" + - " l.add((Integer [][]) null); // illegal [45]\n" + - " \n" + - " foo(l); // legal [46]\n" + - " foo2(l); // illegal [47]\n" + - " foo3(l); // illegal [48]\n" + - " bar(l); // legal [49]\n" + - " bar2(l); // illegal [50]\n" + - " bar3(l); // legal [51]\n" + - " bar4(l); // legal [52]\n" + - " }\n" + - " { // can add array but cannot call a method which expects an array. 100% !\n" + - " List l = new ArrayList();\n" + - " l.get(0).toString();\n" + - " l.add(l.get(0)); // legal [53]\n" + - " l.add((Object) null); // legal [54]\n" + - " l.add((Integer) null); // legal [55]\n" + - " l.add((Object []) null); // legal [56]\n" + - " l.add((Integer []) null); // legal [57]\n" + - " l.add((Integer [][]) null); // legal [58]\n" + - " \n" + - " foo(l); // legal [59]\n" + - " foo2(l); // illegal [60]\n" + - " foo3(l); // illegal [61]\n" + - " bar(l); // legal [62]\n" + - " bar2(l); // legal [63]\n" + - " bar3(l); // legal [64]\n" + - " bar4(l); // legal [65]\n" + - " }\n" + - " { // cannot add any type but can match ? or ? extends Object.\n" + - " List l = new ArrayList();\n" + - " l.add(l.get(0)); // illegal [66]\n" + - " l.add((Object) null); // illegal [67]\n" + - " l.add((Integer) null); // illegal [68]\n" + - " l.add((Object []) null); // illegal [69]\n" + - " l.add((Integer []) null); // illegal [70]\n" + - " l.add((Integer [][]) null); // illegal [71]\n" + - " \n" + - " foo(l); // List - illegal [72]\n" + - " foo2(l); // List - illegal [73]\n" + - " foo3(l); // List - illegal [74]\n" + - " bar(l); // List - illegal [75]\n" + - " bar2(l); // List - illegal [76]\n" + - " bar3(l); // List - legal [77]\n" + - " bar4(l); // List - legal [78]\n" + - " }\n" + - " { // same as ? extends Object.\n" + - " List l = new ArrayList();\n" + - " l.add(l.get(0)); // illegal [79]\n" + - " l.add((Object) null); // illegal [80]\n" + - " l.add((Integer) null); // illegal [81]\n" + - " l.add((Object []) null); // illegal [82]\n" + - " l.add((Integer []) null); // illegal [83]\n" + - " l.add((Integer [][]) null); // illegal [84]\n" + - " \n" + - " foo(l); // List - illegal [85]\n" + - " foo2(l); // List - illegal [86]\n" + - " foo3(l); // List - illegal [87]\n" + - " bar(l); // List - illegal [88]\n" + - " bar2(l); // List - illegal [89]\n" + - " bar3(l); // List - legal [90]\n" + - " bar4(l); // List - legal [91]\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 21)\n" + - " l.add(l.get(0)); // illegal [01]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (capture-of ? super Object[])\n" + - "----------\n" + - "2. ERROR in X.java (at line 22)\n" + - " l.add((Object) null); // illegal [02]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Object)\n" + - "----------\n" + - "3. ERROR in X.java (at line 23)\n" + - " l.add((Integer) null); // illegal [03]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer)\n" + - "----------\n" + - "4. ERROR in X.java (at line 24)\n" + - " l.add((Object []) null); // illegal [04]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Object[])\n" + - "----------\n" + - "5. ERROR in X.java (at line 25)\n" + - " l.add((Integer []) null); // illegal [05]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer[])\n" + - "----------\n" + - "6. ERROR in X.java (at line 26)\n" + - " l.add((Integer [][]) null); // illegal [06]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer[][])\n" + - "----------\n" + - "7. ERROR in X.java (at line 28)\n" + - " foo(l); // List - legal [07]\n" + - " ^^^\n" + - "The method foo(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "8. ERROR in X.java (at line 29)\n" + - " foo2(l); // List - illegal [08]\n" + - " ^^^^\n" + - "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "9. ERROR in X.java (at line 30)\n" + - " foo3(l); // List - illegal [09]\n" + - " ^^^^\n" + - "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "10. ERROR in X.java (at line 31)\n" + - " bar(l); // List - illegal [10]\n" + - " ^^^\n" + - "The method bar(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "11. ERROR in X.java (at line 32)\n" + - " bar2(l); // List - illegal [11]\n" + - " ^^^^\n" + - "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "12. ERROR in X.java (at line 39)\n" + - " l.add((Object) null); // illegal [15]\n" + - " ^^^\n" + - "The method add(Object[]) in the type List is not applicable for the arguments (Object)\n" + - "----------\n" + - "13. ERROR in X.java (at line 40)\n" + - " l.add((Integer) null); // illegal [16]\n" + - " ^^^\n" + - "The method add(Object[]) in the type List is not applicable for the arguments (Integer)\n" + - "----------\n" + - "14. ERROR in X.java (at line 48)\n" + - " bar(l); // List - illegal [23]\n" + - " ^^^\n" + - "The method bar(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "15. ERROR in X.java (at line 49)\n" + - " bar2(l); // List - illegal [24]\n" + - " ^^^^\n" + - "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "16. ERROR in X.java (at line 55)\n" + - " l.add(l.get(0)); // illegal [27]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (capture-of ? extends Object[])\n" + - "----------\n" + - "17. ERROR in X.java (at line 56)\n" + - " l.add((Object) null); // illegal [28]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Object)\n" + - "----------\n" + - "18. ERROR in X.java (at line 57)\n" + - " l.add((Integer) null); // illegal [29]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer)\n" + - "----------\n" + - "19. ERROR in X.java (at line 58)\n" + - " l.add((Object []) null); // illegal [30]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Object[])\n" + - "----------\n" + - "20. ERROR in X.java (at line 59)\n" + - " l.add((Integer []) null); // illegal [31]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer[])\n" + - "----------\n" + - "21. ERROR in X.java (at line 60)\n" + - " l.add((Integer [][]) null); // illegal [32]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer[][])\n" + - "----------\n" + - "22. ERROR in X.java (at line 62)\n" + - " foo(l); // List - illegal [33]\n" + - " ^^^\n" + - "The method foo(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "23. ERROR in X.java (at line 63)\n" + - " foo2(l); // List - illegal [34]\n" + - " ^^^^\n" + - "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "24. ERROR in X.java (at line 65)\n" + - " bar(l); // List - illegal [36]\n" + - " ^^^\n" + - "The method bar(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "25. ERROR in X.java (at line 66)\n" + - " bar2(l); // List - illegal [37]\n" + - " ^^^^\n" + - "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "26. ERROR in X.java (at line 75)\n" + - " l.add((Object []) null); // illegal [43]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Object[])\n" + - "----------\n" + - "27. ERROR in X.java (at line 76)\n" + - " l.add((Integer []) null); // illegal [44]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Integer[])\n" + - "----------\n" + - "28. ERROR in X.java (at line 77)\n" + - " l.add((Integer [][]) null); // illegal [45]\n" + - " ^^^\n" + - "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Integer[][])\n" + - "----------\n" + - "29. ERROR in X.java (at line 79)\n" + - " foo(l); // legal [46]\n" + - " ^^^\n" + - "The method foo(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "30. ERROR in X.java (at line 80)\n" + - " foo2(l); // illegal [47]\n" + - " ^^^^\n" + - "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "31. ERROR in X.java (at line 81)\n" + - " foo3(l); // illegal [48]\n" + - " ^^^^\n" + - "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "32. ERROR in X.java (at line 83)\n" + - " bar2(l); // illegal [50]\n" + - " ^^^^\n" + - "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "33. ERROR in X.java (at line 98)\n" + - " foo2(l); // illegal [60]\n" + - " ^^^^\n" + - "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "34. ERROR in X.java (at line 99)\n" + - " foo3(l); // illegal [61]\n" + - " ^^^^\n" + - "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "35. ERROR in X.java (at line 107)\n" + - " l.add(l.get(0)); // illegal [66]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (capture-of ? extends Object)\n" + - "----------\n" + - "36. ERROR in X.java (at line 108)\n" + - " l.add((Object) null); // illegal [67]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Object)\n" + - "----------\n" + - "37. ERROR in X.java (at line 109)\n" + - " l.add((Integer) null); // illegal [68]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer)\n" + - "----------\n" + - "38. ERROR in X.java (at line 110)\n" + - " l.add((Object []) null); // illegal [69]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Object[])\n" + - "----------\n" + - "39. ERROR in X.java (at line 111)\n" + - " l.add((Integer []) null); // illegal [70]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer[])\n" + - "----------\n" + - "40. ERROR in X.java (at line 112)\n" + - " l.add((Integer [][]) null); // illegal [71]\n" + - " ^^^\n" + - "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer[][])\n" + - "----------\n" + - "41. ERROR in X.java (at line 114)\n" + - " foo(l); // List - illegal [72]\n" + - " ^^^\n" + - "The method foo(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "42. ERROR in X.java (at line 115)\n" + - " foo2(l); // List - illegal [73]\n" + - " ^^^^\n" + - "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "43. ERROR in X.java (at line 116)\n" + - " foo3(l); // List - illegal [74]\n" + - " ^^^^\n" + - "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "44. ERROR in X.java (at line 117)\n" + - " bar(l); // List - illegal [75]\n" + - " ^^^\n" + - "The method bar(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "45. ERROR in X.java (at line 118)\n" + - " bar2(l); // List - illegal [76]\n" + - " ^^^^\n" + - "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "46. ERROR in X.java (at line 124)\n" + - " l.add(l.get(0)); // illegal [79]\n" + - " ^^^\n" + - "The method add(capture-of ?) in the type List is not applicable for the arguments (capture-of ?)\n" + - "----------\n" + - "47. ERROR in X.java (at line 125)\n" + - " l.add((Object) null); // illegal [80]\n" + - " ^^^\n" + - "The method add(capture-of ?) in the type List is not applicable for the arguments (Object)\n" + - "----------\n" + - "48. ERROR in X.java (at line 126)\n" + - " l.add((Integer) null); // illegal [81]\n" + - " ^^^\n" + - "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer)\n" + - "----------\n" + - "49. ERROR in X.java (at line 127)\n" + - " l.add((Object []) null); // illegal [82]\n" + - " ^^^\n" + - "The method add(capture-of ?) in the type List is not applicable for the arguments (Object[])\n" + - "----------\n" + - "50. ERROR in X.java (at line 128)\n" + - " l.add((Integer []) null); // illegal [83]\n" + - " ^^^\n" + - "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer[])\n" + - "----------\n" + - "51. ERROR in X.java (at line 129)\n" + - " l.add((Integer [][]) null); // illegal [84]\n" + - " ^^^\n" + - "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer[][])\n" + - "----------\n" + - "52. ERROR in X.java (at line 131)\n" + - " foo(l); // List - illegal [85]\n" + - " ^^^\n" + - "The method foo(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "53. ERROR in X.java (at line 132)\n" + - " foo2(l); // List - illegal [86]\n" + - " ^^^^\n" + - "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "54. ERROR in X.java (at line 133)\n" + - " foo3(l); // List - illegal [87]\n" + - " ^^^^\n" + - "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "55. ERROR in X.java (at line 134)\n" + - " bar(l); // List - illegal [88]\n" + - " ^^^\n" + - "The method bar(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n" + - "56. ERROR in X.java (at line 135)\n" + - " bar2(l); // List - illegal [89]\n" + - " ^^^^\n" + - "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + - "----------\n"); -} -public void test0668() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.List;\n" + - " \n" + - "public class X {\n" + - " void foo(List l) {\n" + - " l.add(new Object[0]);\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95289 -public void test0669() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - "private static int indexOf(final T[] array,final T elem) {\n" + - " return 0;\n" + - "}\n" + - "public static void meth(AContainer ac, AInfo[] aiArray) {\n" + - " for(AInfo ai: aiArray) {\n" + - " int index1 = indexOf(ac.getAs(),ai.a);\n" + - " int index2 = indexOf(ac.getAs(),ai); // ai.class!=ai.a.class!!!\n" + - " }\n" + - "}\n" + - "}\n" + - "\n" + - "class AContainer {\n" + - " public A[] getAs(){ return null; }\n" + - "}\n" + - "\n" + - "class AInfo {\n" + - " public A a;\n" + - "}\n" + - "\n" + - "class A {\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 (ensure not even a warning) -public void test0670() { - runConformTest( - true, - new String[] { - "X.java", - "import java.util.Map;\n" + - "\n" + - "interface MethodProperty> {\n" + - " public void copyFrom(ActualType other);\n" + - "}\n" + - "\n" + - "class MethodPropertyDatabase> {\n" + - " Map propertyMap;\n" + - " \n" + - " void read(String fileName) {\n" + - " }\n" + - "}\n" + - "\n" + - "class FooProperty implements MethodProperty {\n" + - " String value;\n" + - "\n" + - " public void copyFrom(FooProperty other) {\n" + - " this.value = other.value;\n" + - " }\n" + - "}\n" + - "\n" + - "class FooPropertyDatabase extends MethodPropertyDatabase {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " FooPropertyDatabase fooDatabase;\n" + - " \n" + - " public void readDatabase() {\n" + - " FooPropertyDatabase database = new FooPropertyDatabase();\n" + - " \n" + - " fooDatabase = readDatabase(database, \"foodatabase.db\"); // Bug reported on this line\n" + - " }\n" + - " \n" + - " private<\n" + - " Property extends MethodProperty,\n" + - " DatabaseType extends MethodPropertyDatabase\n" + - " > DatabaseType readDatabase(DatabaseType database, String fileName) {\n" + - " database.read(fileName);\n" + - " return database;\n" + - " }\n" + - " \n" + - "}\n", - }, - "", - null, - null, - JavacTestOptions.EclipseJustification.EclipseBug95021); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 - variation: ensure not even a warning -public void test0671() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "\n" + - "interface MethodProperty> {\n" + - " public void copyFrom(ActualType other);\n" + - "}\n" + - "\n" + - "class MethodPropertyDatabase> {\n" + - " Map propertyMap;\n" + - " \n" + - " void read(String fileName) {\n" + - " }\n" + - "}\n" + - "\n" + - "class FooProperty implements MethodProperty {\n" + - " String value;\n" + - "\n" + - " public void copyFrom(FooProperty other) {\n" + - " this.value = other.value;\n" + - " }\n" + - "}\n" + - "\n" + - "class FooPropertyDatabase extends MethodPropertyDatabase {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Zork z;\n" + - " FooPropertyDatabase fooDatabase;\n" + - " \n" + - " public void readDatabase() {\n" + - " FooPropertyDatabase database = new FooPropertyDatabase();\n" + - " \n" + - " fooDatabase = readDatabase(database, \"foodatabase.db\"); // Bug reported on this line\n" + - " }\n" + - " \n" + - " private<\n" + - " Property extends MethodProperty,\n" + - " DatabaseType extends MethodPropertyDatabase\n" + - " > DatabaseType readDatabase(DatabaseType database, String fileName) {\n" + - " database.read(fileName);\n" + - " return database;\n" + - " }\n" + - " \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 26)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 - variation: ensure not even a warning -public void test0672() { - this.runNegativeTest( - new String[] { - "X.java", - "interface Foo> {\n" + - "}\n" + - "\n" + - "class Bar {\n" + - "}\n" + - "\n" + - "\n" + - "public class X {\n" + - " Zork z;\n" + - " void readDatabase() {\n" + - " Bar bar = new Bar();\n" + - " read(bar, \"sadasd\");\n" + - " }\n" + - " \n" + - "

, D extends Bar

> \n" + - " D read(D d, String s) {\n" + - " return d;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " Bar bar = new Bar();\n" + - " ^^^\n" + - "Foo is a raw type. References to generic type Foo should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " Bar bar = new Bar();\n" + - " ^^^\n" + - "Foo is a raw type. References to generic type Foo should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " read(bar, \"sadasd\");\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation read(Bar, String) of the generic method read(D, String) of type X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 -public void test0673() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "class Key> {\n" + - "}\n" + - "\n" + - "class State {\n" + - "}\n" + - "\n" + - "class Type> {\n" + - "}\n" + - "\n" + - "class Store, C extends Key, D extends State> {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " List, ? extends State>> stores;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation -public void test0674() { - this.runConformTest( - new String[] { - "X.java", - "class Key> {}\n" + - "class Store> {}\n" + - "\n" + - "public class X> {\n" + - " Store> store;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation -public void test0675() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "class Key> {}\n" + - "class Store> {}\n" + - "\n" + - "public class X {\n" + - " Store> store1;\n" + - " Store> store2;\n" + - "}\n", - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 5)\n" + - " Store> store1;\n" + - " ^\n" + - "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//check fault tolerance, in spite of bound mismatch, still pass param type for further resolving message send -public void test0676() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T get() { return null; }\n" + - " \n" + - " void foo(X xs) {\n" + - " xs.get().printStackTrace();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " void foo(X xs) {\n" + - " ^^^^^^\n" + - "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " xs.get().printStackTrace();\n" + - " ^^^^^^^^^^^^^^^\n" + - "The method printStackTrace() is undefined for the type String\n" + - "----------\n"); -} -public void test0677() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " {\n" + - " ArrayList arrayList = new ArrayList(); // compile error\n" + - " Number number = arrayList.get(0);\n" + - " }\n" + - " {\n" + - " ArrayList arrayList = new ArrayList(); //correct\n" + - " Number number = arrayList.get(0);\n" + - " }\n" + - " {\n" + - " ArrayList arrayList = new ArrayList();\n" + - " Object number = arrayList.get(0); //returns java.lang.Object\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " ArrayList arrayList = new ArrayList(); // compile error\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from ArrayList to ArrayList\n" + - "----------\n"); -} -public void test0678() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " \n" + - " X right1;\n" + - " X wrong1;\n" + - " X right2;\n" + - " \n" + - " static class Y implements Serializable {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " public class X {\n" + - " ^^^^^^^^^^^^\n" + - "Cannot specify any additional bound Serializable when first bound is a type parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " X wrong1;\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type Serializable is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " static class Y implements Serializable {\n" + - " ^\n" + - "The serializable class Y does not declare a static final serialVersionUID field of type long\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation -public void test0679() { - this.runConformTest( - new String[] { - "X.java", - "class Key> {}\n" + - "class Store> {}\n" + - "\n" + - "public class X> {\n" + - " Store> store;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation -public void test0680() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "class Key, G extends Key, H extends State> {}\n" + - "class State {}\n" + - "class Type, V extends Key, W extends State> {}\n" + - "class Store, C extends Key, D extends State> {}\n" + - "\n" + - "public class X> {\n" + - " List, ? extends State>> stores;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation -public void test0681() { - this.runConformTest( - new String[] { - "X.java", - "class Key> {\n" + - "}\n" + - "class Store> {\n" + - "}\n" + - "class X {\n" + - " Store store1;\n" + - " Store> store2;\n" + - "\n" + - " class StoreHolder > {\n" + - " Store store;\n" + - " }\n" + - "}\n" + - "class Y> {\n" + - " Y y;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95963 -public void test0682() { - this.runNegativeTest( - new String[] { - "X.java", - "class X extends A {}\n" + - "class A {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " class X extends A {}\n" + - " ^^^\n" + - "X.M cannot be resolved to a type\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96085 -public void test0683() { - this.runConformTest( - new String[] { - "P.java", - "public interface P {\n" + - " interface A {}\n" + - "}\n", - "P2.java", - "public class P2 implements P.A {\n" + - " P2(P.A problem) {}\n" + - "}\n", - "P3.java", - "public class P3 {\n" + - " void test() {P.A o = new P2((P.A) null);}\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "P3.java", - "class P3 {\n" + - " void test() {P.A o = new P2((P.A) null);}\n" + - "}\n", - }, - "", - null, - false, - null); -} -public void test0684() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " U foo(U u1, U u2) {\n" + - " return u1;\n" + - " }\n" + - " void bar(X x1, X x2) {\n" + - " X x = foo(x1, x2);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X x = foo(x1, x2);\n" + - " ^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n"); -} -public void test0685() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " U foo(U u1, U u2) {\n" + - " return u1;\n" + - " }\n" + - " void bar(X x1, X x2) {\n" + - " X x = foo(x1, x2);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X x = foo(x1, x2);\n" + - " ^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n"); -} -// check wildcard bounds wrt variable boundCheck -public void test0686() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "class Other> {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Other> other1;\n" + - " Other> other2; \n" + - " Other> other3; \n" + - " Other> other7 = other1;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " Other> other2; \n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Other> other3; \n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n"); -} -// check wildcard bounds wrt variable boundCheck -public void test0687() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "class Other> {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Other> other2;\n" + - " Other> other3;\n" + - " Other> other4;\n" + - " Other> other5;\n" + - " Other> other6;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " Other> other3;\n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Other> other4;\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " Other> other5;\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n" + - "4. ERROR in X.java (at line 10)\n" + - " Other> other6;\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n"); -} -// check wildcard bounds wrt variable boundCheck -public void test0688() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "class Other> {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Other> other5;\n" + - "}\n", - }, - ""); -} -// check wildcard bounds wrt variable boundCheck -public void test0689() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "class Other> {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " Other> other5;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " Other> other5;\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + - "----------\n"); -} -// check assignment rules across param types with wildcards -public void test0690() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " void foo(List lr, List la) {\n" + - " lr = la;\n" + - " la = lr;\n" + - " }\n" + - "} \n" + - "\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " lr = la;\n" + - " ^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); -} -// check that final class bound is more restrictive -public void test0691() { - this.runNegativeTest( - new String[] { - "XX.java", - "public class XX {\n" + - " void foo(XX lhs, XX rhs) {\n" + - " lhs = rhs;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in XX.java (at line 2)\n" + - " void foo(XX lhs, XX rhs) {\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends String is not a valid substitute for the bounded parameter of the type XX\n" + - "----------\n"); -} -// check wildcard bounds wrt variable boundCheck -public void test0692() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X> {\n" + - " \n" + - " void foo(X> x) {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " void foo(X> x) {\n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n"); -} -// bound checks -public void test0693() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " X> x1;\n" + - " X x2;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " X> x1;\n" + - " ^\n" + - "Bound mismatch: The type X is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " X> x1;\n" + - " ^^^^^^\n" + - "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\n" + - " X x2;\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends String is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n"); -} -// bound checks -public void test0694() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " X>> x1;\n" + - " X>> x2;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " X>> x1;\n" + - " ^\n" + - "Bound mismatch: The type X> is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " X>> x1;\n" + - " ^\n" + - "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 2)\n" + - " X>> x1;\n" + - " ^^^^^^\n" + - "Bound mismatch: The type String is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n" + - "4. ERROR in X.java (at line 3)\n" + - " X>> x2;\n" + - " ^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends X> is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n" + - "5. ERROR in X.java (at line 3)\n" + - " X>> x2;\n" + - " ^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n" + - "6. ERROR in X.java (at line 3)\n" + - " X>> x2;\n" + - " ^^^^^^\n" + - "Bound mismatch: The type String is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n"); -} -// bound checks -public void test0695() { - this.runConformTest( - new String[] { - "I.java", - "interface I> {\n" + - "}\n", - }, - ""); -} -public void test0696() { - this.runNegativeTest( - new String[] { - "X.java", - "class Key> {}\n" + - "class Store> {}\n" + - "\n" + - "public class X {\n" + - " Store> store = new Store>();\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Store> store = new Store>();\n" + - " ^\n" + - "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Store> store = new Store>();\n" + - " ^^^\n" + - "Bound mismatch: The type Key is not a valid substitute for the bounded parameter > of the type Store\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " Store> store = new Store>();\n" + - " ^\n" + - "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + - "----------\n"); -} -public void test0697() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X> {\n" + - " V v;\n" + - " \n" + - " void foo(X x1, X x2) {\n" + - " String s =x1.v.get(0);\n" + - " Object o = x2.v.get(0);\n" + - " \n" + - " }\n" + - "}\n", - }, - ""); -} -public void test0698() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X, V extends List> {\n" + - " \n" + - " X x;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " X x;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super Exception is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " X x;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? super Exception is not a valid substitute for the bounded parameter > of the type X\n" + - "----------\n"); -} -public void test0699() { - this.runNegativeTest( - new String[] { - "X2.java", - "import java.util.List;\n" + - "class Other2> {\n" + - "}\n" + - "\n" + - "class X2 {\n" + - " Other2> other1;\n" + - " Other2> other2; \n" + - " Other2> other3; \n" + - " Other2> other7 = other1;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X2.java (at line 6)\n" + - " Other2> other1;\n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + - "----------\n" + - "2. ERROR in X2.java (at line 7)\n" + - " Other2> other2; \n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + - "----------\n" + - "3. ERROR in X2.java (at line 8)\n" + - " Other2> other3; \n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96646 -public void test0700() { - this.runConformTest( - new String[] { - "X.java", - "abstract class BaseFactory {\n" + - " public T create() throws Exception {\n" + - " return getType().newInstance();\n" + - " }\n" + - " public abstract Class getType();\n" + - "}\n" + - "interface StringFactory {\n" + - " public String create() throws Exception;\n" + - "}\n" + - "public class X extends BaseFactory implements StringFactory {\n" + - " @Override\n" + - " public Class getType() {\n" + - " return String.class;\n" + - " }\n" + - " public static void main(String[] args) throws Exception {\n" + - " String emptyString = new X().create();\n" + - " System.out.printf(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 -public void test0701() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Arrays;\n" + - "import java.util.List;\n" + - "\n" + - "class Deejay {\n" + - " class Counter {}\n" + - "\n" + - " Counter songCounter = new Counter();\n" + - " Counter genreCounter = new Counter();\n" + - "\n" + - " List> list1 = Arrays.asList(songCounter, genreCounter);\n" + - " List> list2 = Arrays.asList(songCounter, genreCounter);\n" + - " List> list3 = Arrays.>asList(songCounter, genreCounter);\n" + - " List> list4 = Arrays.asList(new Counter[] {songCounter, genreCounter});\n" + - " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + - "}\n" + - "class Genre {}\n" + - "class Song {}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " List> list1 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " List> list2 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + - "----------\n" + - "3. WARNING in X.java (at line 14)\n" + - " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 14)\n" + - " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation -public void test0702() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X implements Runnable {\n" + - " \n" + - " void foo0(X> lhs, X> rhs) {\n" + - " lhs = rhs; // 0\n" + - " }\n" + - " void foo1(X> lhs, X> rhs) {\n" + - " lhs = rhs; // 1\n" + // TODO (philippe) should be ok using capture rules for equivalence - " }\n" + - " void foo2(X> lhs, X> rhs) {\n" + - " lhs = rhs; // 2\n" + - " }\n" + - " void foo3(X> lhs, X> rhs) {\n" + - " lhs = rhs; // 3\n" + - " }\n" + - " void foo4(X> lhs, X> rhs) {\n" + - " lhs = rhs; // 4\n" + - " }\n" + - " void foo5(X> lhs, X> rhs) {\n" + - " lhs = rhs; // 5\n" + - " }\n" + - " void foo6(X>>>> lhs, X>>>> rhs) {\n" + - " lhs = rhs; // 6\n" + - " } \n" + - " public void run() {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " lhs = rhs; // 1\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X> to X>\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " lhs = rhs; // 2\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X> to X>\n" + - "----------\n" + - "3. ERROR in X.java (at line 13)\n" + - " lhs = rhs; // 3\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X> to X>\n" + - "----------\n" + - "4. ERROR in X.java (at line 19)\n" + - " lhs = rhs; // 5\n" + - " ^^^\n" + - "Type mismatch: cannot convert from X> to X>\n" + - "----------\n"); -} -public void test0703() { - this.runConformTest( - new String[] { - "X.java", - "public class X> {}\n" + - "class Y extends X {\n" + - " X p = (Y)null;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97800 -public void test0704() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List l = (List)Collections.emptyList();\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " List l = (List)Collections.emptyList();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97480 -public void test0705() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " void f(Object o){\n" + - " ((Map.Entry)o).setValue(\"bug\");\n" + - " \n" + - " Map.Entry me= (Map.Entry)o; \n" + - " me.setValue(\"ok\");\n" + - " \n" + - " ((Vector)o).add(\"ok\");\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " ((Map.Entry)o).setValue(\"bug\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method setValue(Object) belongs to the raw type Map.Entry. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " ((Map.Entry)o).setValue(\"bug\");\n" + - " ^^^^^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " Map.Entry me= (Map.Entry)o; \n" + - " ^^^^^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " Map.Entry me= (Map.Entry)o; \n" + - " ^^^^^^^^^\n" + - "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 8)\n" + - " me.setValue(\"ok\");\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method setValue(Object) belongs to the raw type Map.Entry. References to generic type Map.Entry should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 10)\n" + - " ((Vector)o).add(\"ok\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 10)\n" + - " ((Vector)o).add(\"ok\");\n" + - " ^^^^^^\n" + - "Vector is a raw type. References to generic type Vector should be parameterized\n" + - "----------\n" + - "8. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 -public void test0706() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " BB bb = new BB();\n" + - " bb.test();\n" + - " ((AA) bb).test();\n" + - " }\n" + - "}\n" + - "class AA { AA test() {return null;} }\n" + - "class BB extends AA { BB test() {return null;} }\n" + - "class CC {}\n", - }, - ""); - return; - } - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " BB bb = new BB();\n" + - " bb.test();\n" + - " ((AA) bb).test();\n" + - " }\n" + - "}\n" + - "class AA { AA test() {return null;} }\n" + - "class BB extends AA { BB test() {return null;} }\n" + - "class CC {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\r\n" + - " bb.test();\r\n" + - " ^^^^\n" + - "The method test() is ambiguous for the type BB\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 -public void test0706a() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " BB bb = new BB();\n" + - " AA res1 = bb.test();\n" + - " AA res3 = bb.test();\n" + - " }\n" + - "}\n" + - "class AA { AA test() {return null;} }\n" + - "class BB extends AA { BB test() {return null;} }\n" + - "class CC {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " AA res1 = bb.test();\n" + - " ^^^^\n" + - "The method test() is ambiguous for the type BB\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " AA res3 = bb.test();\n" + - " ^^\n" + - "AA is a raw type. References to generic type AA should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " AA res3 = bb.test();\n" + - " ^^^^\n" + - "The method test() is ambiguous for the type BB\n" + - "----------\n" - // 4: reference to test is ambiguous, both method test() in AA and method test() in BB match - // 5: reference to test is ambiguous, both method test() in AA and method test() in BB match - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 -public void test0706b() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " BB bb = new BB();\n" + - " AA res = bb.test();\n" + - " BB res2 = bb.test();\n" + - " }\n" + - "}\n" + - "class AA { AA test() {return null;} }\n" + - "class BB extends AA { BB test() {return null;} }\n" + - "class CC {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " AA res = bb.test();\n" + - " ^^^^\n" + - "The method test() is ambiguous for the type BB\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " BB res2 = bb.test();\n" + - " ^^^^\n" + - "The method test() is ambiguous for the type BB\n" + - "----------\n" - // 4: reference to test is ambiguous, both method test() in AA and method test() in BB match - // 4: incompatible types on the assignment - // 5: reference to test is ambiguous, both method test() in AA and method test() in BB match - // 5: incompatible types on the assignment - ); - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " BB bb = new BB();\n" + - " AA res = bb.test();\n" + - " BB res2 = bb.test();\n" + - " }\n" + - "}\n" + - "class AA { AA test() {return null;} }\n" + - "class BB extends AA { }\n" + - "class CC {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " AA res = bb.test();\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from AA to AA\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " BB res2 = bb.test();\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from AA to BB\n" + - "----------\n" - // incompatible types on both assignments - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98079 -public void test0707() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " B b() {\n" + - " return a();\n" + - " }\n" + - " \n" + - " B a() {\n" + - " return null;\n" + - " }\n" + - " \n" + - " static class B { }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95684 -public void test0708() { - this.runConformTest( - new String[] { - "UserClass.java", - "public class UserClass {\n" + - " protected class DataHolder {}\n" + - " protected void loadHook(DataHolder data) {}\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "ChildClass.java", - "public class ChildClass extends UserClass {\n" + - " @Override protected void loadHook(DataHolder data) {}\n" + - "}\n", - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95684 - variation -public void test0709() { - this.runConformTest( - new String[] { - "UserClass.java", - "public class UserClass {\n" + - " protected class DataHolder {}\n" + - " protected void loadHook(DataHolder[] data) {}\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "ChildClass.java", - "public class ChildClass extends UserClass {\n" + - " @Override protected void loadHook(DataHolder[] data) {}\n" + - "}\n", - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96713 -public void test0710() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static > P createDataObject(V value) {\n" + - " return null;\n" + - " }\n" + - " public static void testCreateDataObject(Object v) {\n" + - " Persistent d = createDataObject(v);\n" + - " }\n" + - "\n" + - " private interface Persistent {\n" + - " public V getValueObject();\n" + - " }\n" + - "}\n", - }, - ""); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97108 -public void test0711(){ - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.HashMap;\n" + - "import java.util.List;\n" + - "import java.util.Map;\n" + - "\n" + - "public class X {\n" + - " static private Map m1 = new HashMap();\n" + - " private List m2 = new ArrayList();\n" + - " static protected XX foo()\n" + - " {\n" + - " return null;\n" + - " }\n" + - " static public abstract class XX\n" + - " {\n" + - " }\n" + - "}\n", - }, - ""); - - this.runConformTest( - new String[] { - "Y.java", - "public class Y extends X \n" + - "{ \n" + - "}\n" - }, - "", - null, - false, - null); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97108 -// The case that works -public void test0712(){ - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.HashMap;\n" + - "import java.util.List;\n" + - "import java.util.Map;\n" + - "\n" + - "public class X {\n" + - " static private Map m1 = new HashMap();\n" + - " private List> m2 = new ArrayList>();\n" + - " static protected XX foo()\n" + - " {\n" + - " return null;\n" + - " }\n" + - " static public abstract class XX\n" + - " {\n" + - " }\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "Y.java", - "public class Y extends X \n" + - "{ \n" + - "}\n" - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96713 -public void test0713() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " int i = 0;\n" + - " interface Y {\n" + - " java.util.List lt = null;\n" + - " int j = i;\n" + - " void m1(T t); \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " java.util.List lt = null;\n" + - " ^\n" + - "Cannot make a static reference to the non-static type T\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " int j = i;\n" + - " ^\n" + - "Cannot make a static reference to the non-static field i\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " void m1(T t); \n" + - " ^\n" + - "Cannot make a static reference to the non-static type T\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98232 -public void test0714() { - this.runConformTest( - new String[] { - "B.java", - "import java.util.Map;\n" + - "import java.util.Set;\n" + - "import java.util.SortedSet;\n" + - "\n" + - "public class B {\n" + - " static Set foo(SortedSet set) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n", - }, - ""); - this.runConformTest( - new String[] { - "A.java", - "public class A {\n" + - " A() {\n" + - " B.foo(null);\n" + - " }\n" + - "}\n" - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98393 -public void test0715() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " Comparable c = (java.util.List)bar(5, 5.0);\n" + - " }\n" + - " \n" + - " T bar(T t1, T t2) { return t1; }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Comparable c = (java.util.List)bar(5, 5.0);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to Comparable\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " Comparable c = (java.util.List)bar(5, 5.0);\n" + - " ^^^^^^^^^^^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98396 -// ** -public void test0716() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " void foo(T t) {\n" + - " Comparable ci = (Comparable) t; \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Comparable ci = (Comparable) t; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from T to Comparable\n" + - "----------\n"); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=98396 - variation -public void test0717() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X & List> {\n" + - " void foo(T t) {\n" + - " Comparable ci = (Comparable) t; \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Comparable ci = (Comparable) t; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from T to Comparable\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98478 -public void test0718() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Collections;\n" + - "import java.util.Set;\n" + - "import java.util.TreeSet;\n" + - "\n" + - "public class X {\n" + - " \n" + - " public interface Base {\n" + - " }\n" + - " \n" + - " abstract class Action {\n" + - " }\n" + - "\n" + - " public class ActionImpl extends Action implements Comparable {\n" + - " public int compareTo(ActionImpl o) {\n" + - " return 0;\n" + - " }\n" + - " }\n" + - "\n" + - " public void test() {\n" + - " Set set = new TreeSet();\n" + - " Collections.max(set);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 13)\n" + - " public class ActionImpl extends Action implements Comparable {\n" + - " ^^^^^^^^^^\n" + - "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " public int compareTo(ActionImpl o) {\n" + - " ^^^^^^^^^^\n" + - "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 20)\n" + - " Set set = new TreeSet();\n" + - " ^^^^^^^^^^\n" + - "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 20)\n" + - " Set set = new TreeSet();\n" + - " ^^^^^^^^^^\n" + - "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 21)\n" + - " Collections.max(set);\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation max(Collection) of the generic method max(Collection) of type Collections\n" + - "----------\n" + - "6. ERROR in X.java (at line 23)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 -public void test0719() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "import java.util.ListIterator;\n" + - "\n" + - "interface IntegerIterator extends Iterator {}\n" + - "interface IntegerListIterator extends ListIterator, IntegerIterator {}\n" + - "\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " interface IntegerIterator extends Iterator {}\n" + - " ^^^^^^^^\n" + - "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " interface IntegerListIterator extends ListIterator, IntegerIterator {}\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The interface Iterator cannot be implemented more than once with different arguments: Iterator and Iterator\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 - variation -public void test0720() { - this.runNegativeTest( - new String[] { - "X.java", - "interface Foo {}\n" + - "interface Bar extends Foo {}\n" + - "interface Baz extends Bar, Foo {}\n" + - "\n" + - "class XSuper implements Foo {}\n" + - "class XSub extends XSuper implements Foo {}\n" + - "\n" + - "public class X implements Bar, Foo {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " interface Baz extends Bar, Foo {}\n" + - " ^^^\n" + - "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " interface Baz extends Bar, Foo {}\n" + - " ^^^\n" + - "Foo is a raw type. References to generic type Foo should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " class XSuper implements Foo {}\n" + - " ^^^\n" + - "Foo is a raw type. References to generic type Foo should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 6)\n" + - " class XSub extends XSuper implements Foo {}\n" + - " ^^^^\n" + - "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + - "----------\n" + - "5. ERROR in X.java (at line 8)\n" + - " public class X implements Bar, Foo {}\n" + - " ^\n" + - "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + - "----------\n" + - "6. WARNING in X.java (at line 8)\n" + - " public class X implements Bar, Foo {}\n" + - " ^^^\n" + - "Foo is a raw type. References to generic type Foo should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98561 -public void test0721() { - this.runConformTest( - new String[] { - "Foo.java", - "public class Foo\n" + - "{\n" + - " protected abstract class InnerFoo\n" + - " {\n" + - " protected abstract void doSomething();\n" + - " }\n" + - " \n" + - " protected void run( InnerFoo innerFoo )\n" + - " {\n" + - " innerFoo.doSomething();\n" + - " }\n" + - "}", - }, - ""); - this.runConformTest( - new String[] { - "Bar.java", - "public class Bar extends Foo\n" + - "{\n" + - " public void go()\n" + - " {\n" + - " InnerFoo inner = new InnerFoo()\n" + - " {\n" + - " protected void doSomething()\n" + - " {\n" + - " System.out.println( \"hello\" );\n" + - " }\n" + - " };\n" + - " run( inner );\n" + - " }\n" + - "}" - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 - variation -public void test0722() { - this.runNegativeTest( - new String[] { - "X.java", - "interface I1 {\n" + - "}\n" + - "\n" + - "interface I2 extends I1 {\n" + - "}\n" + - "\n" + - "public class X implements I1, I2 {\n" + - "}\n", - }, - ""); -} -public void test0723() { - this.runConformTest( - new String[] { - "X.java", - "interface IA {}\n" + - "interface IB extends IA {}\n" + - "class A implements IA {}\n" + - "class B implements IB {}\n" + - "\n" + - "public class X {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " A x = new A();\n" + - " B y = new B();\n" + - " print(x);\n" + - " print(y);\n" + - " }\n" + - " public static > void print(T a) {\n" + - " System.out.print(\"A\");\n" + - " }\n" + - " public static > void print(T a) {\n" + - " System.out.println(\"B\");\n" + - " }\n" + - "}\n", - }, - "AB"); -} -public void test0724() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.HashMap;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " HashMap subst = new HashMap();\n" + - " subst.put((byte)1, (byte)1);\n" + - " if (1 + subst.get((byte)1) > 0.f) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " } \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 -public void test0725() { - this.runNegativeTest( - new String[] { - "X.java", - "class AbsC {\n" + - " public T[] resize(T[] src, T[] dest) {\n" + - " return dest;\n" + - " }\n" + - "}\n" + - "\n" + - "class ConrC extends AbsC {\n" + - " T[][] data;\n" + - " protected void allocateChunkSlots(int maxChunkNo) {\n" + - " data = resize(data, new Object[maxChunkNo][]);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " data = resize(data, new Object[maxChunkNo][]);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object[][] to T[][]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 -public void test0726() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo() {\n" + - " \n" + - " Controller ctrl = null;\n" + - " foobar(ctrl.getView().getContent()); \n" + - " } \n" + - " \n" + - " static void foobar(X x) {\n" + - " }\n" + - "}\n" + - "interface Controller> {\n" + - " public T getView() ;\n" + - "}\n" + - "interface View {\n" + - " public U getContent();\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 - variation -public void test0727() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " void foo() {\n" + - " \n" + - " Controller ctrl = null;\n" + - " foobar(ctrl.getView().getContent()); \n" + - " } \n" + - " \n" + - " static void foobar(X x) {\n" + - " }\n" + - "}\n" + - "interface Controller> {\n" + - " public T getView() ;\n" + - "}\n" + - "interface View> {\n" + - " public U getContent();\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 - variation -public void test0728() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " \n" + - " Controller ctrl = null;\n" + - " foobar(ctrl.getView().getContent()); \n" + - " } \n" + - " \n" + - " static void foobar(X x) {\n" + - " }\n" + - "}\n" + - "interface Controller> {\n" + - " public T getView() ;\n" + - "}\n" + - "interface View> {\n" + - " public U getContent();\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " foobar(ctrl.getView().getContent()); \n" + - " ^^^^^^\n" + - "The method foobar(X) in the type X is not applicable for the arguments (capture#2-of ?)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96586 -public void test0729() { - this.runConformTest( - new String[] { - "X.java", - "public class X implements I {}\n" + - "interface I {}\n" + - "class Y extends X implements I {}\n" - }, - ""); - this.runNegativeTest( - new String[] { - "X.java", - "public class X implements I {}\n" + - "interface I> {}\n" + - "class Y extends X implements I {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " class Y extends X implements I {}\n" + - " ^\n" + - "The interface I cannot be implemented more than once with different arguments: I and I\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " class Y extends X implements I {}\n" + - " ^\n" + - "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type I\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=90437 -public void test0730() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " Zork z;\n" + - " public interface SuperInterface {\n" + - " }\n" + - "\n" + - " public interface SubInterface extends SuperInterface {\n" + - " public String getString();\n" + - " }\n" + - "\n" + - " private SuperInterface< ? extends SuperInterface> x = null;\n" + - "\n" + - " public void f() {\n" + - " ((SubInterface) this.x).getString();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " private SuperInterface< ? extends SuperInterface> x = null;\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " ((SubInterface) this.x).getString();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X.SuperInterface to X.SubInterface\n" + - "----------\n" ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97440 -public void test0731() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " X parent;\n" + - " X current;\n" + - "\n" + - " X parent2;\n" + - " X current2;\n" + - "\n" + - " void foo() {\n" + - " current = current.parent;\n" + - " }\n" + - "\n" + - " void bar() {\n" + - " current2 = current2.parent2;\n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 -public void test0732() { - this.runNegativeTest( - new String[] { - "X.java", - "interface B {}\n" + - "interface C extends B{}\n" + - "interface D extends B{}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " D d = null;\n" + - " C c = (C)d; // illegal\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " C c = (C)d; // illegal\n" + - " ^^^^\n" + - "Cannot cast from D to C\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0733() { - this.runConformTest( - new String[] { - "X.java", - "interface B {}\n" + - "interface C extends B{}\n" + - "interface D extends B{}\n" + - "\n" + - "\n" + - "public class X {\n" + - " Object foo(C c) {\n" + - " return (D) c;\n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0734() { - this.runConformTest( - new String[] { - "X.java", - "interface B {}\n" + - "interface C extends B{}\n" + - "interface D extends B{}\n" + - "\n" + - "\n" + - "public class X {\n" + - " Object foo(C c, D d) {\n" + - " return c != null ? c : d; \n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0735() { - this.runConformTest( - new String[] { - "X.java", - "interface B {}\n" + - "interface C extends B{}\n" + - "interface D extends B{}\n" + - "\n" + - "\n" + - "public class X {\n" + - " Object foo(C c, D d) {\n" + - " return c != null ? c : d; \n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0736() { - this.runNegativeTest( - new String[] { - "X.java", - "interface B {}\n" + - "interface C extends B{}\n" + - "interface D extends B{}\n" + - "\n" + - "\n" + - "public class X {\n" + - " void bar(C c) {\n" + - " D d = (D) c;\n" + - " foo(d, c);\n" + - " }\n" + - " void foo(U u1, U u2) {\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " D d = (D) c;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from C to D\n" + - "----------\n"); -} -public void test0737() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "class Sup {\n" + - "}\n" + - "\n" + - "class Sub1 extends Sup {\n" + - "}\n" + - "\n" + - "class Sub2 extends Sup {\n" + - "\n" + - "}\n" + - "abstract class X {\n" + - " abstract S method(A la, B lb);\n" + - "\n" + - " void m2() {\n" + - " Sup Sup = method(new Sub1(), new Sub2());// <-- compiles?? ( A=Sub1, B=Sub2, S=Sup)\n" + - " Object obj = method(1, \"32\");// <--doesn\'t compile?? ( A=Integer, B=String, S=Object)\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0738() { - this.runNegativeTest( - new String[] { - "X.java", - "interface B {}\n" + - "class C implements B{}\n" + - "interface D extends B{}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " D d = null;\n" + - " C c = (C)d; // illegal\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " C c = (C)d; // illegal\n" + - " ^^^^\n" + - "Cannot cast from D to C\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0739() { - this.runNegativeTest( - new String[] { - "X.java", - "interface B {}\n" + - "interface C extends B{}\n" + - "class D implements B{}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " D d = null;\n" + - " C c = (C)d; // illegal\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " C c = (C)d; // illegal\n" + - " ^^^^\n" + - "Cannot cast from D to C\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0740() { - this.runNegativeTest( - new String[] { - "X.java", - "interface B {}\n" + - "final class C implements B{}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " B d = null;\n" + - " C c = (C)d; // illegal\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " C c = (C)d; // illegal\n" + - " ^^^^\n" + - "Cannot cast from B to C\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation -public void test0741() { - this.runNegativeTest( - new String[] { - "X.java", - "interface B {}\n" + - "final class D implements B{}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " D d = null;\n" + - " B c = (B)d; // illegal\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " B c = (B)d; // illegal\n" + - " ^^^^^^^^^^^^\n" + - "Cannot cast from D to B\n" + - "----------\n"); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=98538 -// ** -public void test0742() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - " public class X {\n" + - " \n" + - " static abstract class SelfType>{\n" + - " }\n" + - " \n" + - " static class SuperType extends SelfType{\n" + - " }\n" + - " \n" + - " static class SubType extends SuperType{}\n" + - " \n" + - " static > List makeSingletonList(T t){\n" + - " return Collections.singletonList(t);\n" + - " }\n" + - " \n" + - " static ,S extends T> List makeSingletonList2(S s){\n" + - " return Collections.singletonList((T)s); // #0\n" + - " }\n" + - " \n" + - " public static void main(String[] args){\n" + - " makeSingletonList(new SuperType()); // #1 - OK\n" + - " List lsup = makeSingletonList(new SuperType()); // #2 - OK\n" + - " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + - " makeSingletonList(new SubType()); // #4 - ERROR\n" + - " makeSingletonList2(new SubType()); // #5 - ERROR\n" + - " lsup = makeSingletonList2(new SubType()); // #6 - OK\n" + - " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + - " makeSingletonList2(new SuperType()); // #8 - OK\n" + - " lsup = makeSingletonList2(new SuperType()); // #9 - OK\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 24)\n" + - " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "2. ERROR in X.java (at line 25)\n" + - " makeSingletonList(new SubType()); // #4 - ERROR\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "3. ERROR in X.java (at line 26)\n" + - " makeSingletonList2(new SubType()); // #5 - ERROR\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "4. ERROR in X.java (at line 28)\n" + - " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99553 -public void test0743() { - this.runNegativeTest( - new String[] { - "X.java", - "interface TestGeneric2 {\n" + - " Nested getNested2(); // super\n" + - "\n" + - " class Nested implements TestGeneric2 {\n" + - " public Nested getNested2() { // sub\n" + - " return this;//2\n" + - " }\n" + - " }\n" + - "}\n" + - " \n" + - "class TestGeneric3 {\n" + - " Nested getNested3() { return null; } // super\n" + - "\n" + - " class Nested extends TestGeneric3 {\n" + - " @Override public Nested getNested3() { // sub\n" + - " return this;//3\n" + - " }\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " return this;//3\n" + - " ^^^^\n" + - "Type mismatch: cannot convert from TestGeneric3.Nested to TestGeneric3.Nested\n" + - "----------\n"); -} -public void test0744() { - this.runNegativeTest( - new String[] { - "java/util/X.java", - "package java.util;\n" + - "\n" + - "import java.io.*;\n" + - "\n" + - "class Super {\n" + - " static class Entry {\n" + - " Entry(int i, U u, V v, Entry entry) {}\n" + - " void recordAccess(Super s) {\n" + - " }\n" + - " }\n" + - "}\n"+ - "public abstract class X extends Super {\n" + - "\n" + - " Entry h;\n" + - "\n" + - " private static class Entry extends Super.Entry {\n" + - "\n" + - " Entry() {\n" + - " super(0, null, null, null);\n" + - " }\n" + - "\n" + - " void ab(Entry e) {\n" + - " }\n" + - "\n" + - " @Override void recordAccess(Super m) {\n" + - " X x = (X) m;\n" + - " ab(x.h);\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in java\\util\\X.java (at line 30)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99922 -public void test0745() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void test() {\n" + - " java.util.Arrays.asList(3, 3.1);\n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99922 - variation -public void test0746() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void test() {\n" + - " String s = java.util.Arrays.asList(3, 3.1);\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " String s = java.util.Arrays.asList(3, 3.1);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Number&Comparable is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " String s = java.util.Arrays.asList(3, 3.1);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99983 -public void test0747() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " interface I {}\n" + - " class Y {\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " class Y {\n" + - " ^\n" + - "Cannot specify any additional bound X.I when first bound is a type parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100007 -public void test0748() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static interface Factory {\n" + - " public U create(Class cl);\n" + - " }\n" + - " \n" + - " static class BytesFactory implements Factory {\n" + - " public byte[] create(Class cl) {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + - " static class BytesFactory implements Factory {\r\n" + - " ^^^^^^^^^^^^\n" + - "The type X.BytesFactory must implement the inherited abstract method X.Factory.create(Class)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100149 -public void test0749() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X> {\n" + - " T get() { return null; }\n" + - " void foo(X x) {\n" + - " String s = x.get();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " void foo(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " String s = x.get();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from X to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100149 - variation -public void test0750() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X> {\n" + - " T get() { return null; }\n" + - " void foo(X x) {\n" + - " List l = x.get();\n" + - " }\n" + - " Zork z ;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " void foo(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " List l = x.get();\n" + - " ^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " Zork z ;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100153 -public void test0751() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X> {\n" + - " \n" + - " void foo(X x) {\n" + - " X x2 = x;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X x2 = x;\n" + - " ^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n"); -} -public void test0752() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " X> parent;\n" + - " X> current;\n" + - " void foo() {\n" + - " current = current.parent;\n" + - " }\n" + - "}\n" + - "\n" + - "interface I {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " current = current.parent;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X>> to X>\n" + - "----------\n"); -} -public void test0753() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " X> parent;\n" + - " X> current;\n" + - " void foo() {\n" + - " current = current.parent;\n" + - " }\n" + - "}\n" + - "\n" + - "interface I {\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X> parent;\n" + - " ^^^^^^^^^\n" + - "Bound mismatch: The type ? super I is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " X> current;\n" + - " ^^^^^^^^^\n" + - "Bound mismatch: The type ? super I is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " current = current.parent;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X>> to X>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99578 -public void test0754() { - this.runNegativeTest( - new String[] { - "X.java", - "class bugSuper {\n" + - " public T getData(){\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "class bugElement {\n" + - "}\n" + - "\n" + - "class bugClass extends bugSuper{\n" + - "}\n" + - "\n" + - "public class X{\n" + - " public void method(bugClass bc){\n" + - " bugElement be = bc.getData(); //<< here\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 14)\n" + - " public void method(bugClass bc){\n" + - " ^^^^^^^^\n" + - "bugClass is a raw type. References to generic type bugClass should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 15)\n" + - " bugElement be = bc.getData(); //<< here\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to bugElement\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99999 -public void test0755() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static class B {}\n" + - " public static void main (String... args) {\n" + - " X.B[] b = new X.B[1];\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X.B[] b = new X.B[1];\n" + - " ^^^^^^^^\n" + - "The member type X.B cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " X.B[] b = new X.B[1];\n" + - " ^^^^^^\n" + - "The member type X.B cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99999 - variation -public void test0756() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " public class B {}\n" + - " public static void main (String... args) {\n" + - " X.B[] b = new X.B[1];\n" + - " }\n" + - "}", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100147 -public void test0757() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class EntryMap {\n" + - " class Entry {\n" + - " }\n" + - " }\n" + - "\n" + - " EntryMap.Entry internalGet(Object key) {\n" + - " return null;\n" + - " }\n" + - " \n" + - " void foo(Object key) {\n" + - " EntryMap.Entry entry = internalGet(key);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " EntryMap.Entry internalGet(Object key) {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 12)\n" + - " EntryMap.Entry entry = internalGet(key);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X.EntryMap.Entry needs unchecked conversion to conform to X.EntryMap.Entry\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100147 - variation -public void test0758() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class EntryMap {\n" + - " class Entry {\n" + - " }\n" + - " }\n" + - "\n" + - " EntryMap.Entry internalGet(Object key) {\n" + - " return null;\n" + - " }\n" + - " \n" + - " void foo(Object key) {\n" + - " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " EntryMap.Entry internalGet(Object key) {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 12)\n" + - " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X.EntryMap.Entry to X.EntryMap.Entry\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X.EntryMap.Entry needs unchecked conversion to conform to X.EntryMap.Entry\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + - " ^^^^^^^^^^^^^^\n" + - "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 14)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100128 -public void test0759() { - this.runConformTest( - new String[] { - "X.java", - "public class X\n" + - "{\n" + - " E[] m;\n" + - " public X()\n" + - " {\n" + - " X x = null;\n" + - " System.out.println(x.m.length);\n" + - " }\n" + - "}\n", - }, - ""); -} -public void test0760() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static X make() {\n" + - " return null;\n" + - " }\n" + - " public static T itself(T t) {\n" + - " return t;\n" + - " }\n" + - "\n" + - " void foo() {\n" + - " X x1 = make();\n" + - " X x2 = itself(x1);\n" + - " }\n" + - " void bar() {\n" + - " X x2 = itself(make());\n" + - " }\n" + - " void baz() {\n" + - " X x2 = itself((X)make());\n" + - " } \n" + - "} \n", - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " X x2 = itself(make());\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 19)\n" + - " X x2 = itself((X)make());\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100421 -public void test0761() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public abstract class ClassA {\n" + - " public abstract B method(A param);\n" + - " }\n" + - "\n" + - " public class ClassB {\n" + - " // the following field declaration causes an error\n" + - " ClassA classA;\n" + - "\n" + - " public D method(D d) {\n" + - " return classA.method(d);\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100421 - variation -public void test0762() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public abstract class ClassA {\n" + - " public abstract B method(A param);\n" + - " }\n" + - "\n" + - " public class ClassB {\n" + - " // the following field declaration causes an error\n" + - " ClassA classA;\n" + - "\n" + - " public D method(D d) {\n" + - " return classA.method(d);\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100519 -public void test0763() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static class InnerClass {\n" + - " public InnerClass() {\n" + - " System.out.println(\"class : \" + InnerClass.this);\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100527 -public void test0764() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - " \n" + - "interface IIfClosure {}\n" + - " \n" + - "public class X {\n" + - " public X(String label, HashMap bindings) {\n" + - " this(label, bindings, (List)Collections.emptyList());\n" + - " }\n" + - " \n" + - " public X(String label, HashMap bindings, Collection coll) {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " this(label, bindings, (List)Collections.emptyList());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 -public void test0765() { - this.runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " static T f1() throws Exception{\n" + - " return null;\n" + - " }\n" + - " static U f2() throws Exception {\n" + - " return f1();\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBug6302954 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 -public void test0766() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "interface Cloneable> {\n" + - " public T clone();\n" + - "}\n" + - "\n" + - "interface CloneableMap> extends Map, Cloneable> {\n" + - "}\n" + - "\n" + - "interface C> extends Cloneable {\n" + - "}\n" + - "public class X {\n" + - " void foo() {\n" + - " CloneableMap> map = null;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " CloneableMap> map = null;\n" + - " ^\n" + - "Bound mismatch: The type C is not a valid substitute for the bounded parameter > of the type CloneableMap\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 - variation -public void test0767() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "interface Cloneable> {\n" + - " public T clone();\n" + - "}\n" + - "\n" + - "interface CloneableMap> extends Map, Cloneable> {\n" + - "}\n" + - "\n" + - "interface C extends Cloneable {\n" + - "}\n" + - "public class X {\n" + - " void foo() {\n" + - " CloneableMap map = null;\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100619 -public void test0768() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T foo1() { return null; }\n" + - " , U extends Z & T> T foo2() { return null; }\n" + - " , U extends T & Z> T foo3() { return null; }\n" + - " , U extends W & Z> T foo4() { return null; }\n" + - "}\n" + - "\n" + - "interface Y {\n" + - "}\n" + - "\n" + - "interface Z extends Y {}\n" + - "interface W extends Y {}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " T foo1() { return null; }\n" + - " ^\n" + - "The type T is not an interface; it cannot be specified as a bounded parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " , U extends Z & T> T foo2() { return null; }\n" + - " ^\n" + - "The type T is not an interface; it cannot be specified as a bounded parameter\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " , U extends T & Z> T foo3() { return null; }\n" + - " ^\n" + - "Cannot specify any additional bound Z when first bound is a type parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 4)\n" + - " , U extends T & Z> T foo3() { return null; }\n" + - " ^\n" + - "The interface Y cannot be implemented more than once with different arguments: Y and Y\n" + - "----------\n" + - "5. ERROR in X.java (at line 5)\n" + - " , U extends W & Z> T foo4() { return null; }\n" + - " ^\n" + - "The interface Y cannot be implemented more than once with different arguments: Y and Y\n" + - "----------\n"); -} -public void test0769() { - this.runConformTest( - new String[] { - "X.java", - "class XSuper {\n" + - " T value;\n" + - "}\n" + - "public class X extends XSuper{\n" + - " public void a() {\n" + - " value += 1;\n" + - " value = value + 1;\n" + - " System.out.println(value);\n" + - " }\n" + - "\n" + - " public static void main(final String[] args) {\n" + - " X x = new X();\n" + - " x.value = \"[\";\n" + - " x.a();\n" + - " }\n" + - "}\n", - }, - "[11"); -} -public void test0770() { - this.runConformTest( - new String[] { - "X.java", - "class XSuper {\n" + - " T value;\n" + - "}\n" + - "public class X extends XSuper{\n" + - " public void a() {\n" + - " this.value += 1;\n" + - " this.value = this.value + 1;\n" + - " System.out.println(this.value);\n" + - " }\n" + - "\n" + - " public static void main(final String[] args) {\n" + - " X x = new X();\n" + - " x.value = \"[\";\n" + - " x.a();\n" + - " }\n" + - "}\n", - }, - "[11"); -} -public void test0771() { - this.runConformTest( - new String[] { - "X.java", - "class XSuper {\n" + - " T value;\n" + - "}\n" + - "public class X extends XSuper{\n" + - " public static void a(X x) {\n" + - " x.value += 1;\n" + - " x.value = x.value + 1;\n" + - " System.out.println(x.value);\n" + - " }\n" + - "\n" + - " public static void main(final String[] args) {\n" + - " X x = new X();\n" + - " x.value = \"[\";\n" + - " a(x);\n" + - " }\n" + - "}\n", - }, - "[11"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794 -public void test0772() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "interface Foo {\n" + - " public T getIt();\n" + - "}\n" + - "\n" + - "class FooImpl implements Foo {\n" + - " public String getIt() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public void doIt() {\n" + - " Object s = new FooImpl().getIt();\n" + - " }\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public void doIt() {\n" + - " Object s = new FooImpl().getIt();\n" + - " }\n" + - "}\n", - }, - "", - null, - false, - null); - String expectedOutput = - " // Method descriptor #18 ()Ljava/lang/Object;\n" + - " // Stack: 1, Locals: 1\n" + - " public bridge synthetic java.lang.Object getIt();\n" + - " 0 aload_0\n" + - " 1 invokevirtual FooImpl.getIt() : java.lang.String [19]\n" + - " 4 areturn\n" + - " Line numbers:\n" + - " [pc: 0, line: 1]\n"; - - File f = new File(OUTPUT_DIR + File.separator + "FooImpl.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794 - variation -public void test0773() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "interface Foo {\n" + - " public T getIt() throws T;\n" + - "}\n" + - "\n" + - "class FooImpl implements Foo {\n" + - " public NullPointerException getIt() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public void doIt() {\n" + - " Object s = new FooImpl().getIt();\n" + - " }\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public void doIt() {\n" + - " Object s = new FooImpl().getIt();\n" + - " }\n" + - "}\n", - }, - "", - null, - false, - null); - String expectedOutput = - " // Method descriptor #18 ()Ljava/lang/Exception;\n" + - " // Stack: 1, Locals: 1\n" + - " public bridge synthetic java.lang.Exception getIt() throws java.lang.Exception;\n" + - " 0 aload_0\n" + - " 1 invokevirtual FooImpl.getIt() : java.lang.NullPointerException [22]\n" + - " 4 areturn\n" + - " Line numbers:\n" + - " [pc: 0, line: 1]\n"; - - File f = new File(OUTPUT_DIR + File.separator + "FooImpl.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98532 -public void test0774() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class StaticInnerNoParam {\n" + - " T x;\n" + - " }\n" + - " class NonStaticInnerParam {} \n" + - " static class StaticInnerParam { }\n" + - " void foo(T t) {}\n" + - " static void bar(T t) {}\n" + - " X(T t) {}\n" + - " \n" + - " class U {}\n" + - " void foo2(U t) {}\n" + - " static void bar2(U t) {}\n" + - " class NonStaticInnerParam2 {} \n" + - " static class StaticInnerParam2 {} \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " T x;\n" + - " ^\n" + - "Cannot make a static reference to the non-static type T\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " class NonStaticInnerParam {} \n" + - " ^\n" + - "The type parameter T is hiding the type T\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " void foo(T t) {}\n" + - " ^\n" + - "The type parameter T is hiding the type T\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " X(T t) {}\n" + - " ^\n" + - "The type parameter T is hiding the type T\n" + - "----------\n" + - "5. WARNING in X.java (at line 12)\n" + - " void foo2(U t) {}\n" + - " ^\n" + - "The type parameter U is hiding the type X.U\n" + - "----------\n" + - "6. WARNING in X.java (at line 13)\n" + - " static void bar2(U t) {}\n" + - " ^\n" + - "The type parameter U is hiding the type X.U\n" + - "----------\n" + - "7. WARNING in X.java (at line 14)\n" + - " class NonStaticInnerParam2 {} \n" + - " ^\n" + - "The type parameter U is hiding the type X.U\n" + - "----------\n" + - "8. WARNING in X.java (at line 15)\n" + - " static class StaticInnerParam2 {} \n" + - " ^\n" + - "The type parameter U is hiding the type X.U\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100153 -public void test0775() { - this.runConformTest( - new String[] { - "X.java", - "public class X> {\n" + - " void foo1(X x) {}\n" + - " void foo2(X x) {}\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103023 -public void test0776() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X> {\n" + - "\n" + - " abstract class Foo implements I> {}\n" + - "\n" + - " abstract class Bar implements I> {}\n" + - "\n" + - " public void bar(List> f, List> b) {\n" + - " foo(f, b);\n" + - " }\n" + - "\n" + - " void foo(List f, List b) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void main(String... args) {\n" + - " new X().bar(null, null);\n" + - " }\n" + - "}\n" + - "interface I {}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103472 -public void test0777() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public interface B {\n" + - " public T a();\n" + - " }\n" + - "\n" + - " public interface C extends B {\n" + - " }\n" + - "\n" + - " public class D implements B {\n" + - " public Integer a() {\n" + - " return 0;\n" + - " }\n" + - " }\n" + - "\n" + - " // Illegal\n" + - " public class E implements B, C {\n" + - " public Integer a() {\n" + - " return 0;\n" + - " }\n" + - " }\n" + - "\n" + - " // why is this allowed?\n" + - " public class F extends D implements C {\n" + - " public Integer a() {\n" + - " return 0;\n" + - " }\n" + - " }\n" + - "\n" + - " public interface G {\n" + - " public void a(T pArg);\n" + - " }\n" + - "\n" + - " public interface H extends G {\n" + - " public Object b();\n" + - " }\n" + - "\n" + - " public class I implements G {\n" + - " public void a(Integer pInt) {\n" + - " }\n" + - " }\n" + - "\n" + - " // Illegal. Huh?\n" + - " public class J extends I implements G {\n" + - " public Integer a() {\n" + - " return 0;\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " public interface C extends B {\n" + - " ^\n" + - "X.B is a raw type. References to generic type X.B should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " public class E implements B, C {\n" + - " ^\n" + - "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + - "----------\n" + - "3. ERROR in X.java (at line 23)\n" + - " public class F extends D implements C {\n" + - " ^\n" + - "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + - "----------\n" + - "4. WARNING in X.java (at line 24)\n" + - " public Integer a() {\n" + - " ^^^\n" + - "The method a() of type X.F should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "5. WARNING in X.java (at line 33)\n" + - " public interface H extends G {\n" + - " ^\n" + - "X.G is a raw type. References to generic type X.G should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 43)\n" + - " public class J extends I implements G {\n" + - " ^\n" + - "The interface G cannot be implemented more than once with different arguments: X.G and X.G\n" + - "----------\n" + - "7. WARNING in X.java (at line 43)\n" + - " public class J extends I implements G {\n" + - " ^\n" + - "X.G is a raw type. References to generic type X.G should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103472 - variation -public void test0778() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " interface B {}\n" + - "\n" + - " interface C extends B {}\n" + - "\n" + - " class D implements B {}\n" + - "\n" + - " class F extends D implements C {}\n" + - " \n" + - " class V {}\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " interface C extends B {}\n" + - " ^\n" + - "X.B is a raw type. References to generic type X.B should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " class F extends D implements C {}\n" + - " ^\n" + - "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " class V {}\n" + - " ^\n" + - "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103227 -public void test0779() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.util.AbstractList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " private static class Entry {\n" + - " public void doIt(final List args) {\n" + - " List list = new AbstractList() {\n" + - " @Override public int size() { return 0; }\n" + - " @Override public String get(int i) { return args.get(i); }\n" + - " };\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new Entry().doIt(null);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - - String expectedOutput = - " // Method descriptor #31 (I)Ljava/lang/Object;\n" + - " // Stack: 2, Locals: 2\n" + - " public bridge synthetic java.lang.Object get(int arg0);\n" + - " 0 aload_0\n" + - " 1 iload_1\n" + - " 2 invokevirtual X$Entry$1.get(int) : java.lang.String [36]\n" + - " 5 areturn\n" + - " Line numbers:\n" + - " [pc: 0, line: 1]\n"; - - // check no unnecessary checkcast on bridge method for X$1 - File f = new File(OUTPUT_DIR + File.separator + "X$Entry$1.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103227 - variation -public void test0780() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " long foo(List list) {\n" + - " return list.get(0);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " List list = new ArrayList();\n" + - " list.add(123L);\n" + - " System.out.println(new X().foo(list));\n" + - " }\n" + - "}\n", - }, - "123"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104109 -public void test0781() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public static > Foo doIt(T t) {\n" + - " return null;\n" + - " }\n" + - " \n" + - " interface Foo {\n" + - " boolean ok(E e);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " public static > Foo doIt(T t) {\n" + - " ^^^^^^^^^^\n" + - "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104082 -public void test0782() { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.reflect.*;\n" + - "import java.util.*;\n" + - "\n" + - "interface StoredObject {\n" + - " String getUid();\n" + - " String getName();\n" + - " String getDescription();\n" + - "}\n" + - "\n" + - "interface GraphDiagramNode // extends Comparable\n" + - "{\n" + - "}\n" + - "\n" + - "public class X implements GraphDiagramNode {\n" + - " private final JccsGraphDiagramModel model;\n" + - " private final X parent;\n" + - " private final ObjectType object;\n" + - "\n" + - " public class JccsGraphDiagramModel {\n" + - " }\n" + - "\n" + - " public interface GraphDiagramModel {\n" + - " }\n" + - "\n" + - " public class Dependency {\n" + - "\n" + - " }\n" + - "\n" + - " public X(JccsGraphDiagramModel argModel, X argParent, ObjectType argObject) {\n" + - " model = argModel;\n" + - " parent = argParent;\n" + - " object = argObject;\n" + - " }\n" + - "\n" + - " protected Collection> createChildren(\n" + - " Iterator argData, Class> argChildNodeClass,\n" + - " Class argInterface) {\n" + - " Collection> output = new LinkedList>();\n" + - "\n" + - " try {\n" + - " while (argData.hasNext()) {\n" + - " ChildType next = argData.next();\n" + - " Constructor> constructor = argChildNodeClass.getConstructor(\n" + - " JccsGraphDiagramModel.class, getClass(), argInterface);\n" + - "\n" + - " output.add(constructor.newInstance(model, this, next));\n" + - " }\n" + - " } catch (Exception x) {\n" + - " x.printStackTrace();\n" + - " }\n" + - "\n" + - " return output;\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104167 -public void test0783() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " private static class B{\n" + - " private int foo; //incorrectly identified as unused\n" + - " }\n" + - " void bar(B b){\n" + - " if (b.foo == 0)\n" + - " return;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104082 - variation -public void test0784() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " X parent;\n" + - "\n" + - " public X(X parent) {\n" + - " this.parent = parent;\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 -public void test0785() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " > T getLonger(T t1, T t2) {\n" + - " return t1.size() > t2.size() ? t1 : t2;\n" + - " }\n" + - " \n" + - " void m(HashSet list, ArrayList set) {\n" + - " getLonger(list, set);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " getLonger(list, set);\n" + - " ^^^^^^^^^\n" + - "Bound mismatch: The generic method getLonger(T, T) of type X is not applicable for the arguments (HashSet, ArrayList). The inferred type AbstractCollection&Cloneable&Serializable is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 - variation -public void test0786() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " > T getLonger(T t1, T t2) {\n" + - " return t1.size() > t2.size() ? t1 : t2;\n" + - " }\n" + - " \n" + - " void m(HashSet list, ArrayList set) {\n" + - " getLonger(list, set);\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 - variation -public void test0787() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " > T getLonger(T t1, T t2) {\n" + - " return t1.size() > t2.size() ? t1 : t2;\n" + - " }\n" + - " \n" + - " void m(HashSet list, ArrayList set) {\n" + - " getLonger(list, set);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " getLonger(list, set);\n" + - " ^^^^^^^^^\n" + - "Bound mismatch: The generic method getLonger(T, T) of type X is not applicable for the arguments (HashSet, ArrayList). The inferred type AbstractCollection&Cloneable&Serializable is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103994 -public void test0788() { - this.runConformTest( - new String[] { - "test/A.java", - "package test;\n" + - "\n" + - "public class A\n" + - "{\n" + - " class B\n" + - " extends A\n" + - " {\n" + - " }\n" + - "}\n", - "java/nio/channels/spi/AbstractSelectableChannel.java", - "package java.nio.channels.spi;\n" + - "\n" + - "public abstract class AbstractSelectableChannel\n" + - " extends java.nio.channels.SelectableChannel\n" + - "{\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103994 - variation (change ordering of files should have no effect) -public void test0789() { - this.runConformTest( - new String[] { - "java/nio/channels/spi/AbstractSelectableChannel.java", - "package java.nio.channels.spi;\n" + - "\n" + - "public abstract class AbstractSelectableChannel\n" + - " extends java.nio.channels.SelectableChannel\n" + - "{\n" + - "}\n", - "test/A.java", - "package test;\n" + - "\n" + - "public class A\n" + - "{\n" + - " class B\n" + - " extends A\n" + - " {\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103485 -public void test0790() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " > boolean isGreater(T t1, T t2) {\n" + - " return t1.compareTo(t2) > 0 ? true : false; \n" + - " }\n" + - "\n" + - " void method1(Integer i, Double d) {\n" + - " if (isGreater(i, d)) \n" + - " System.out.println(\"GREATER\");\n" + - " else\n" + - " System.out.println(\"LOWER\");\n" + - " }\n" + - " void method2(Integer i, Double d) {\n" + - " Comparable c1= i;\n" + - " Comparable c2= d;\n" + - " isGreater(c1, c2);\n" + - " } \n" + - " void method3(Integer i, Double d) {\n" + - " Comparable c1= i;\n" + - " Comparable c2= d;\n" + - " isGreater(c1, c2);\n" + - " } \n" + - " public static void main(String[] args) {\n" + - " Integer i = 1;\n" + - " Double d = 2.0;\n" + - " new X().method1(i, d);\n" + - " new X().method2(i, d);\n" + - " new X().method3(i, d);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " if (isGreater(i, d)) \n" + - " ^^^^^^^^^\n" + - "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Integer, Double). The inferred type Number&Comparable is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "2. ERROR in X.java (at line 15)\n" + - " isGreater(c1, c2);\n" + - " ^^^^^^^^^\n" + - "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Comparable, Comparable). The inferred type Comparable is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "3. WARNING in X.java (at line 18)\n" + - " Comparable c1= i;\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 19)\n" + - " Comparable c2= d;\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 20)\n" + - " isGreater(c1, c2);\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation isGreater(Comparable, Comparable) of the generic method isGreater(T, T) of type X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104655 -public void test0791() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " Sup method1(boolean b, E1 e1, E2 e2) {\n" + - " if (b)\n" + - " return e1;\n" + - " else\n" + - " return e2;\n" + - " }\n" + - "\n" + - " Sup method2(boolean b, E1 e1, E2 e2) {\n" + - " return b ? e1 : e2;\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - null /* do not check error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104649 -public void test0792() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " void shouldcompile() {\n" + - " java.util.Collections.max(null);\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105635 -public void test0793() { - this.runNegativeTest( - new String[] { - "X.java", - "class X { \n" + - " public java.util.List i,j[],k;\n" + - " void m() {\n" + - " i[0] = null;\n" + - " j[0] = null;\n" + - " k[0] = null;\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " i[0] = null;\n" + - " ^^^^\n" + - "The type of the expression must be an array type but it resolved to List\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " k[0] = null;\n" + - " ^^^^\n" + - "The type of the expression must be an array type but it resolved to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105635 -public void test0794() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "class X { \n" + - " public List i,j[],k;\n" + - " void m() {\n" + - " i[0] = null;\n" + - " j[0] = null;\n" + - " k[0] = null;\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " i[0] = null;\n" + - " ^^^^\n" + - "The type of the expression must be an array type but it resolved to List\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " k[0] = null;\n" + - " ^^^^\n" + - "The type of the expression must be an array type but it resolved to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 -public void test0795() { - this.runConformTest( - new String[] { - "X.java", - "public class X { \n" + - " class B {\n" + - " B() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " static { \n" + - " new X().new B() {};\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 - variation -public void test0796() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " class B {\n" + - " B(T t) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " static { \n" + - " new X().new B(12) {};\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().new B(12) {};\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor X.B(int) is undefined\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 - variation -public void test0797() { - this.runConformTest( - new String[] { - "X.java", - "public class X { \n" + - " class B {\n" + - " B() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " static { \n" + - " new X().new B();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " }\n" + - "}\n", - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106284 -public void test0798() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.math.BigDecimal;\n" + - "\n" + - "public class X\n" + - "{\n" + - " private static > T max(T... elems)\n" + - " {\n" + - " T max=null;\n" + - " for (T elem : elems)\n" + - " if (max == null || max.compareTo(elem) < 0)\n" + - " max=elem;\n" + - " return max;\n" + - " }\n" + - "\n" + - " public static void main(String[] args)\n" + - " {\n" + - " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + - " ^^^\n" + - "Bound mismatch: The generic method max(T...) of type X is not applicable for the arguments (Integer, Double, BigDecimal). The inferred type Number&Comparable is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105531 -public void test0799() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Y first;\n" + - " Y first2;\n" + - "\n" + - " U foo(U u1, U u2) {\n" + - " return u1;\n" + - " }\n" + - " void bar2(Y ref) {\n" + - " String s = foo(ref, first);\n" + - " }\n" + - " \n" + - " void foo(Y ref) {\n" + - " ref.next = first == null ? ref : first;\n" + - " String s = first == null ? ref : first;\n" + - " ref.next = first2 == null ? ref : first2;\n" + - " }\n" + - " Y bar(Y ref) {\n" + - " return first == null ? ref : first;\n" + - " }\n" + - "}\n" + - "\n" + - "class Y {\n" + - " Y next;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " Y first;\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " Y first2;\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " String s = foo(ref, first);\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Y to String\n" + - "----------\n" + - "4. WARNING in X.java (at line 13)\n" + - " ref.next = first == null ? ref : first;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + - "----------\n" + - "5. ERROR in X.java (at line 14)\n" + - " String s = first == null ? ref : first;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Y to String\n" + - "----------\n" + - "6. WARNING in X.java (at line 15)\n" + - " ref.next = first2 == null ? ref : first2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + - "----------\n" + - "7. WARNING in X.java (at line 18)\n" + - " return first == null ? ref : first;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 -public void test0800() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.lang.reflect.Constructor;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " final Class AnnClass = Ann.class;\n" + - " Constructor[] constrs = X.class.getConstructors();\n" + - " for (Constructor constructor : constrs) {\n" + - " final String message = constructor.getAnnotation(AnnClass).message();\n" + - " System.out.println(message);\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "@interface Ann {\n" + - " String message();\n" + - "}\n", - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. WARNING in X.java (at line 6)\n" + - " Constructor[] constrs = X.class.getConstructors();\n" + - " ^^^^^^^^^^^\n" + - "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " for (Constructor constructor : constrs) {\n" + - " ^^^^^^^^^^^\n" + - "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " final String message = constructor.getAnnotation(AnnClass).message();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " final String message = constructor.getAnnotation(AnnClass).message();\n" + - " ^^^^^^^\n" + - "The method message() is undefined for the type Annotation\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation -public void test0801() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " X.class.getConstructor(new Class[0]).getAnnotation(Ann.class).message();\n" + - " } catch(Exception e) {\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "@interface Ann {\n" + - " String message();\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation -public void test0802() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void bar(Y y, X x) {\n" + - " y.foo(x).zz();\n" + - " }\n" + - "}\n" + - "class Y {\n" + - " T foo(X x) { return null; }\n" + - "}\n" + - "\n" + - "class Z {\n" + - "}\n" + - "class ZZ extends Z {\n" + - " void zz() {}\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " void bar(Y y, X x) {\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " y.foo(x).zz();\n" + - " ^^^^^^^^\n" + - "Type safety: The method foo(X) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\n" + - " y.foo(x).zz();\n" + - " ^^\n" + - "The method zz() is undefined for the type Z\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101831 -public void test0803() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " ArrayList list = new ArrayList();\n" + - " ArrayList superList = new ArrayList();\n" + - " ArrayList extendsList = new ArrayList();\n" + - "\n" + - " ArrayList getList() {\n" + - " return true ? list : list;\n" + - " }\n" + - "\n" + - " ArrayList getSuperList() {\n" + - " return true ? superList : superList;\n" + - " }\n" + - "\n" + - " ArrayList getExtendsList() {\n" + - " return true ? extendsList : extendsList;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " return true ? superList : superList;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from ArrayList to ArrayList\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106865 -public void test0804() { - this.runNegativeTest( - new String[] { - "X.java", - "class Y {\n" + - " void foo(E e) {\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " void method1(Y y, Object[] os) {\n" + - " y.foo(os);\n" + - " }\n" + - " void method2(Y y, Cloneable c) {\n" + - " y.foo(c);\n" + - " } \n" + - " void method3(Y y, Object[] os) {\n" + - " y.foo(os);\n" + - " }\n" + - " void method4(Y y, Cloneable c) {\n" + - " y.foo(c);\n" + - " } \n" + - " \n" + - " void bar(Y y) {\n" + - " method2(y, null);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " y.foo(os);\n" + - " ^^^\n" + - "The method foo(capture#3-of ? extends Object[]) in the type Y is not applicable for the arguments (Object[])\n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " y.foo(c);\n" + - " ^^^\n" + - "The method foo(capture#4-of ? extends Cloneable) in the type Y is not applicable for the arguments (Cloneable)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106936 -public void test0805() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static T foo(T t1, T t2) { return t1; }\n" + - " public static void main(String[] args) {\n" + - " Number[] numbers = {}, numbers2, numbers3;\n" + - " Float[] floats = {};\n" + - " Integer[] integers = {};\n" + - "\n" + - " numbers2 = foo(numbers, floats);\n" + - " numbers3 = numbers != null ? numbers : floats;\n" + - " String s = foo(numbers, floats); \n" + - "\n" + - " numbers2 = foo(integers, floats);\n" + - " numbers3 = integers != null ? integers : floats;\n" + - " String s2 = foo(integers, floats);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " String s = foo(numbers, floats); \n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Number[] to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 14)\n" + - " String s2 = foo(integers, floats);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Number&Comparable>[] to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107079 -public void test0806() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "/**\n" + - " * This class demonstrates a generic program that Eclipse must not compile as it\n" + - " * can lead to a ClassCastException despite having no explicit type casts.\n" + - " */\n" + - "public class X {\n" + - " private static class ValueHolder {\n" + - " public T value;\n" + - " }\n" + - "\n" + - " public static void main(final String[] args) {\n" + - " List> multiList = new ArrayList>();\n" + - "\n" + - " ValueHolder intHolder = new ValueHolder();\n" + - " intHolder.value = 1;\n" + - "\n" + - " ValueHolder doubleHolder = new ValueHolder();\n" + - " doubleHolder.value = 1.5;\n" + - "\n" + - " multiList.add(intHolder);\n" + - " multiList.add(doubleHolder);\n" + - "\n" + - " // I believe this line is being erroneously treated as a capture\n" + - " // conversion under 3.1 JDT.\n" + - " // I believe the problem is that ? cannot be captured except in a first\n" + - " // level wildcard.\n" + - " swapFirstTwoValues(multiList);\n" + - "\n" + - " // this line causes a ClassCastException when checked.\n" + - " Integer value = intHolder.value;\n" + - " System.out.println(value);\n" + - " }\n" + - "\n" + - " private static void swapFirstTwoValues(List> multiList) {\n" + - " ValueHolder intHolder = multiList.get(0);\n" + - " ValueHolder doubleHolder = multiList.get(1);\n" + - "\n" + - " intHolder.value = doubleHolder.value;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 29)\n" + - " swapFirstTwoValues(multiList);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "The method swapFirstTwoValues(List>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107756 -public void test0807() { - this.runConformTest( - new String[] { - "X.java", - "interface Prop {\n" + - " Unmarshaller.Handler createHandler();\n" + - "}\n" + - "\n" + - "abstract class Unmarshaller {\n" + - " public static abstract class Handler {}\n" + - "}\n" + - "\n" + - "public class X {\n" + - " void foo(Prop p) {\n" + - " Unmarshaller.Handler h = p.createHandler(); \n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107756 - variation -public void test0808() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " x.ax = new AX();\n" + - " }\n" + - " \n" + - " AX ax;\n" + - "}\n" + - "\n" + - "class AX

{\n" + - " AX

p;\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106946 -public void test0809() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Iterator;\n" + - "\n" + - "class Node {}\n" + - "interface Set1 extends Iterable {}\n" + - "interface Set2 extends Iterable {}\n" + - "\n" + - "class SetIterator implements Iterator {\n" + - " public N next() {\n" + - " return null;\n" + - " }\n" + - " public boolean hasNext() {\n" + - " return true;\n" + - " }\n" + - " public void remove() {\n" + - " }\n" + - "}\n" + - "interface Set3 extends Iterable {\n" + - " SetIterator iterator();\n" + - "}\n" + - "public class X {\n" + - " void f1(Set1 s) {\n" + - " Node n_ = s.iterator().next();\n" + - " // ^Type mismatch: cannot convert from Object to Node\n" + - " // this was unexpected (s can only contain types derivered from Node)\n" + - " for (Node n : s) {\n" + - " // ^Type mismatch: cannot convert from Object to Node\n" + - " // this was unexpected\n" + - " }\n" + - " }\n" + - " void f2(Set2 s) {\n" + - " Node n_ = s.iterator().next();\n" + - " for (Node n : s) {\n" + - " }\n" + - " }\n" + - " void f3(Set3 s) {\n" + - " Node n_ = s.iterator().next();\n" + - " // (^ no error here)\n" + - " for (Node n : s) {\n" + - " // ^Type mismatch: cannot convert from Object to Node\n" + - " // this is even stranger as we already know that s.iterator().next()\n" + - " // have the right type\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 21)\n" + - " void f1(Set1 s) {\n" + - " ^^^^\n" + - "Set1 is a raw type. References to generic type Set1 should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 22)\n" + - " Node n_ = s.iterator().next();\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to Node\n" + - "----------\n" + - "3. ERROR in X.java (at line 25)\n" + - " for (Node n : s) {\n" + - " ^\n" + - "Type mismatch: cannot convert from element type Object to Node\n" + - "----------\n" + - "4. WARNING in X.java (at line 35)\n" + - " void f3(Set3 s) {\n" + - " ^^^^\n" + - "Set3 is a raw type. References to generic type Set3 should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 38)\n" + - " for (Node n : s) {\n" + - " ^\n" + - "Type mismatch: cannot convert from element type Object to Node\n" + - "----------\n"); -} -public void test0810() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "class A {\n" + - " public String toString() {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - "}\n" + - "public class X {\n" + - "\n" + - " public A foo(K type) {\n" + - " return new A();\n" + - " }\n" + - "\n" + - " public static void main(String args[]) {\n" + - " X x = new X();\n" + - " A a = x.foo(null);\n" + - " System.out.println(a);\n" + - " }\n" + - "}", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 -public void test0811() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " private T t;\n" + - " private X.Inner inner;\n" + - " private X.Inner[] inners;\n" + - " public X(T t, X.Inner in, X.Inner[] ins) {\n" + - " this.t = t;\n" + - " this.inner = in;\n" + - " this.inner = new X(null, null, null).new Inner();\n" + - " this.inners = ins;\n" + - " this.inners = new X.Inner[10];\n" + - " //Type mismatch: cannot convert from X.Inner[] to X.Inner[]\n" + - " }\n" + - " private class Inner {\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 - variation -public void test0812() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " private T t;\n" + - " private X.Inner inner;\n" + - " private X.Inner[] inners;\n" + - " public X(T t) {\n" + - " this.t = t;\n" + - " this.inner = new X.Inner();\n" + - " this.inners = new X.Inner[10];\n" + - " Zork z;\n" + - " }\n" + - " private class Inner {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " private T t;\n" + - " ^\n" + - "The field X.t is never read locally\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " private X.Inner inner;\n" + - " ^^^^^\n" + - "The field X.inner is never read locally\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " private X.Inner[] inners;\n" + - " ^^^^^^\n" + - "The field X.inners is never read locally\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " this.inner = new X.Inner();\n" + - " ^^^^^^^\n" + - "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 - variation -public void test0813() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " private T t;\n" + - " private X.Inner[] inners;\n" + - " public X(T t) {\n" + - " this.t = t;\n" + - " this.inners = new X.Inner[10];\n" + - " }\n" + - " private class Inner {\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 -public void test0814() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void method(Object o) {\n" + - " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + - " E[] es = (E[]) o;\n" + - " }\n" + - " if (o instanceof List[]) { //incorrect too\n" + - " List[] es = (List[]) o; \n" + - " }\n" + - " if (o instanceof List[]) { // unbound is ok\n" + - " List[] es = (List[]) o;\n" + - " }\n" + - " }\n" + - " void method(ArrayList[] al) {\n" + - " if (al instanceof List[]) { //incorrect too\n" + - " List[] es = (List[]) al; \n" + - " } \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type E[]. Use instead its raw form Object[] since generic type information will be erased at runtime\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " E[] es = (E[]) o;\n" + - " ^^^^^^^\n" + - "Type safety: Unchecked cast from Object to E[]\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " if (o instanceof List[]) { //incorrect too\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " List[] es = (List[]) o; \n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List[]\n" + - "----------\n" + - "5. ERROR in X.java (at line 15)\n" + - " if (al instanceof List[]) { //incorrect too\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n" + - "6. WARNING in X.java (at line 16)\n" + - " List[] es = (List[]) al; \n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from ArrayList[] to List[]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation -public void test0815() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(Object[][] e) {\n" + - " E[] o = (E[]) e;\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " E[] o = (E[]) e;\n" + - " ^^^^^^^\n" + - "Type safety: Unchecked cast from Object[][] to E[]\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation -public void test0816() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void method(Object[] o) {\n" + - " if (o instanceof List[][]) { //incorrect too\n" + - " List[][] es = (List[][]) o; \n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o instanceof List[][]) { //incorrect too\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[][]. Use instead its raw form List[][] since generic type information will be erased at runtime\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " List[][] es = (List[][]) o; \n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object[] to List[][]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation -public void test0817() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " private T t;\n" + - " private X.Inner inner;\n" + - " private X.Inner[] inners;\n" + - " public X(T t) {\n" + - " this.t = t;\n" + - " if (this.inner instanceof X.Inner) {}\n" + - " if (this.inners instanceof X.Inner[]) {}\n" + - " }\n" + - " private class Inner {\n" + - " }\n" + - " void foo(List l) {\n" + - " if (l instanceof List) {}\n" + - " if (l instanceof List) {}\n" + - " }\n" + - " void foo(List[] ls) {\n" + - " if (ls instanceof List[]) {}\n" + - " if (ls instanceof List[]) {}\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " private T t;\n" + - " ^\n" + - "The field X.t is never read locally\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " if (this.inner instanceof X.Inner) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The expression of type X.Inner is already an instance of type X.Inner\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " if (this.inners instanceof X.Inner[]) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The expression of type X.Inner[] is already an instance of type X.Inner[]\n" + - "----------\n" + - "4. WARNING in X.java (at line 14)\n" + - " void foo(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " if (l instanceof List) {}\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "The expression of type List is already an instance of type List\n" + - "----------\n" + - "6. ERROR in X.java (at line 16)\n" + - " if (l instanceof List) {}\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List. Use instead its raw form List since generic type information will be erased at runtime\n" + - "----------\n" + - "7. WARNING in X.java (at line 18)\n" + - " void foo(List[] ls) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 19)\n" + - " if (ls instanceof List[]) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The expression of type List[] is already an instance of type List\n" + - "----------\n" + - "9. ERROR in X.java (at line 20)\n" + - " if (ls instanceof List[]) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n"); -} -public void test0818() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " boolean b = this instanceof Y;\n" + - " static class Y extends X {\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101380 -public void test0819() { - this.runConformTest( - new String[] { - "X.java", - "public class X implements MyInterface {\n" + - " public void myMethod(myEnum value) {\n" + - " System.out.println(\"value is \"+value);\n" + - " }\n" + - " public static void main(String[] args){\n" + - " new X().myMethod(myEnum.one); \n" + - " }\n" + - "}\n" + - "\n" + - "interface MyInterface {\n" + - " enum myEnum {one,two};\n" + - " public void myMethod(myEnum value); \n" + - "}\n", - }, - "value is one"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101380 - variation -public void test0820() { - this.runConformTest( - new String[] { - "X.java", - "public class X implements I {\n" + - " public void x(M value) {}\n" + - "}\n" + - "interface I {\n" + - " class M {}\n" + - " void x(M value); \n" + - "}\n", - }, - ""); -} -public void test0821() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " void foo() {\n" + - " t.run();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(new A()).foo();\n" + - " }\n" + - "}\n" + - "class A implements Serializable, Runnable {\n" + - " public void run() {\n" + - " System.out.println(\"AA\");\n" + - " }\n" + - "}\n", - }, - "AA"); - // ensure proper declaring class for #run() invocation - String expectedOutput = - " // Method descriptor #15 ()V\n" + - " // Stack: 1, Locals: 1\n" + - " void foo();\n" + - " 0 aload_0 [this]\n" + - " 1 getfield X.t : java.io.Serializable [16]\n" + - " 4 checkcast java.lang.Runnable [25]\n" + - " 7 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + - " 12 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 9]\n" + - " [pc: 12, line: 10]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 13] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 13] local: this index: 0 type: X\n"; - - 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); - } -} -public void test0822() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " void foo(T t) {\n" + - " t.run();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().foo(new A());\n" + - " }\n" + - "}\n" + - "class A implements Serializable, Runnable {\n" + - " public void run() {\n" + - " System.out.println(\"AA\");\n" + - " }\n" + - "}\n", - }, - "AA"); - // ensure proper declaring class for #run() invocation - String expectedOutput = - " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + - " // Signature: (TT;)V\n" + - " // Stack: 1, Locals: 2\n" + - " void foo(java.io.Serializable t);\n" + - " 0 aload_1 [t]\n" + - " 1 checkcast java.lang.Runnable [20]\n" + - " 4 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + - " 9 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 5]\n" + - " [pc: 9, line: 6]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 10] local: this index: 0 type: X\n" + - " [pc: 0, pc: 10] local: t index: 1 type: java.io.Serializable\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 10] local: this index: 0 type: X\n" + - " [pc: 0, pc: 10] local: t index: 1 type: T\n"; - - 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); - } -} -public void test0823() throws Exception { - runConformTest( - true, - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " T t;\n" + - " X(T t) {\n" + - " this.t = t;\n" + - " }\n" + - " void foo() {\n" + - " (this == null ? t : t).run();\n" + - " ((V) t).run();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X(new A()).foo();\n" + - " }\n" + - "}\n" + - "class A implements Serializable, Runnable {\n" + - " public void run() {\n" + - " System.out.print(\"AA\");\n" + - " }\n" + - "}\n", - }, - null, - "AAAA", - null, - JavacTestOptions.JavacHasABug.JavacBug6531075); - // ensure proper declaring class for #run() invocation - String expectedOutput = - " // Method descriptor #15 ()V\n" + - " // Stack: 1, Locals: 1\n" + - " void foo();\n" + - " 0 aload_0 [this]\n" + - " 1 ifnonnull 11\n" + - " 4 aload_0 [this]\n" + - " 5 getfield X.t : java.io.Serializable [16]\n" + - " 8 goto 15\n" + - " 11 aload_0 [this]\n" + - " 12 getfield X.t : java.io.Serializable [16]\n" + - " 15 checkcast java.lang.Runnable [25]\n" + - " 18 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + - " 23 aload_0 [this]\n" + - " 24 getfield X.t : java.io.Serializable [16]\n" + - " 27 checkcast java.lang.Runnable [25]\n" + - " 30 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + - " 35 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 9]\n" + - " [pc: 23, line: 10]\n" + - " [pc: 35, line: 11]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 36] local: this index: 0 type: X\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 36] local: this index: 0 type: X\n"; - - 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); - } -} -public void test0824() throws Exception { - runConformTest( - true, - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " void foo(T t) {\n" + - " (this == null ? t : t).run();\n" + - " ((V) t).run();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().foo(new A());\n" + - " }\n" + - "}\n" + - "class A implements Serializable, Runnable {\n" + - " public void run() {\n" + - " System.out.print(\"AA\");\n" + - " }\n" + - "}\n", - }, - null, - "AAAA", - null, - JavacTestOptions.JavacHasABug.JavacBug6531075); - // ensure proper declaring class for #run() invocation - String expectedOutput = - " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + - " // Signature: (TT;)V\n" + - " // Stack: 1, Locals: 2\n" + - " void foo(java.io.Serializable t);\n" + - " 0 aload_0 [this]\n" + - " 1 ifnonnull 8\n" + - " 4 aload_1 [t]\n" + - " 5 goto 9\n" + - " 8 aload_1 [t]\n" + - " 9 checkcast java.lang.Runnable [20]\n" + - " 12 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + - " 17 aload_1 [t]\n" + - " 18 checkcast java.lang.Runnable [20]\n" + - " 21 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + - " 26 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 5]\n" + - " [pc: 17, line: 6]\n" + - " [pc: 26, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 27] local: this index: 0 type: X\n" + - " [pc: 0, pc: 27] local: t index: 1 type: java.io.Serializable\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 27] local: this index: 0 type: X\n" + - " [pc: 0, pc: 27] local: t index: 1 type: T\n"; - - 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); - } -} -public void test0825() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " void foo(T t) {\n" + - " Runnable r1 = t;\n" + - " Runnable r2 = (this == null ? t : t);\n" + - " Runnable r3 = ((V) t);\n" + - " \n" + - " bar(t);\n" + - " bar(this == null ? t : t);\n" + - " bar((V)t);\n" + - " }\n" + - " void bar(Runnable r) {} \n" + - " public static void main(String[] args) {\n" + - " new X().foo(new A());\n" + - " }\n" + - "}\n" + - "class A implements Serializable, Runnable {\n" + - " public void run() {\n" + - " System.out.println(\"AA\");\n" + - " }\n" + - "}\n", - }, - ""); - // ensure proper declaring class for #run() invocation - String expectedOutput = - " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + - " // Signature: (TT;)V\n" + - " // Stack: 2, Locals: 5\n" + - " void foo(java.io.Serializable t);\n" + - " 0 aload_1 [t]\n" + - " 1 astore_2 [r1]\n" + - " 2 aload_0 [this]\n" + - " 3 ifnonnull 10\n" + - " 6 aload_1 [t]\n" + - " 7 goto 11\n" + - " 10 aload_1 [t]\n" + - " 11 astore_3 [r2]\n" + - " 12 aload_1 [t]\n" + - " 13 astore 4 [r3]\n" + - " 15 aload_0 [this]\n" + - " 16 aload_1 [t]\n" + - " 17 invokevirtual X.bar(java.lang.Runnable) : void [20]\n" + - " 20 aload_0 [this]\n" + - " 21 aload_0 [this]\n" + - " 22 ifnonnull 29\n" + - " 25 aload_1 [t]\n" + - " 26 goto 30\n" + - " 29 aload_1 [t]\n" + - " 30 invokevirtual X.bar(java.lang.Runnable) : void [20]\n" + - " 33 aload_0 [this]\n" + - " 34 aload_1 [t]\n" + - " 35 invokevirtual X.bar(java.lang.Runnable) : void [20]\n" + - " 38 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 5]\n" + - " [pc: 2, line: 6]\n" + - " [pc: 12, line: 7]\n" + - " [pc: 15, line: 9]\n" + - " [pc: 20, line: 10]\n" + - " [pc: 33, line: 11]\n" + - " [pc: 38, line: 12]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 39] local: this index: 0 type: X\n" + - " [pc: 0, pc: 39] local: t index: 1 type: java.io.Serializable\n" + - " [pc: 2, pc: 39] local: r1 index: 2 type: java.lang.Runnable\n" + - " [pc: 12, pc: 39] local: r2 index: 3 type: java.lang.Runnable\n" + - " [pc: 15, pc: 39] local: r3 index: 4 type: java.lang.Runnable\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 39] local: this index: 0 type: X\n" + - " [pc: 0, pc: 39] local: t index: 1 type: T\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110570 -public void test0826() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public void test(V1 p1, V2 p2) {}\n" + - " \n" + - " public static void main(String[] args) {\n" + - " XA a = new XA(){};\n" + - " XB b = new XB(){};\n" + - "\n" + - " X t1 = new X();\n" + - " t1.test(a, b); //this gives an error but should be OK\n" + - " \n" + - " X t2 = new X();\n" + - " t2.test(a, b); //this compiles OK\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "\n" + - "interface XA {}\n" + - "interface XB extends XA {}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " X t1 = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " X t1 = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " t1.test(a, b); //this gives an error but should be OK\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The method test(Object, Object) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 14)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110570 - variation -// ensure variable V2 is substituted with upper bound erasure (List) and not just upperbound List -// for raw generic method invocation -public void test0827() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " public > void test(V1 p1, V2 p2) {}\n" + - " public static void main(String[] args) {\n" + - " XA a = new XA(){};\n" + - " List b = null;\n" + - " X t1 = new X();\n" + - " t1.test(a, b); //this gives an error but should be OK\n" + - " X t2 = new X();\n" + - " t2.test(a, b); //this compiles OK\n" + - " }\n" + - "}\n" + - "interface XA {}\n" + - "\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X t1 = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " X t1 = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " t1.test(a, b); //this gives an error but should be OK\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The method test(Object, List) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 10)\n" + - " t2.test(a, b); //this compiles OK\n" + - " ^^^^\n" + - "Bound mismatch: The generic method test(V1, V2) of type X is not applicable for the arguments (XA, List). The inferred type List is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109249 -public void test0828() { - this.runNegativeTest( - new String[] { - "X.java", - "interface Transformable\n" + - "{\n" + - " public T transform();\n" + - "}\n" + - "interface Volume extends Transformable\n" + - "{\n" + - "// public V transform();\n" + - "}\n" + - "@SuppressWarnings(\"null\")\n" + - "public class X {\n" + - " void foo(){\n" + - " Volume v1 = null;\n" + - " Volume v2 = v1.transform();\n" + - " }\n" + - " void bar(){\n" + - " Volume v1 = null;\n" + - " Volume v2 = v1.transform();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " interface Transformable\n" + - " ^^^^^^^^^^^^^\n" + - "Transformable is a raw type. References to generic type Transformable should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " interface Volume extends Transformable\n" + - " ^^^^^^\n" + - "Volume is a raw type. References to generic type Volume should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " Volume v1 = null;\n" + - " ^^^^^^\n" + - "Volume is a raw type. References to generic type Volume should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 13)\n" + - " Volume v2 = v1.transform();\n" + - " ^^^^^^\n" + - "Volume is a raw type. References to generic type Volume should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 13)\n" + - " Volume v2 = v1.transform();\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Transformable to Volume\n" + - "----------\n" + - "6. WARNING in X.java (at line 16)\n" + - " Volume v1 = null;\n" + - " ^^^^^^\n" + - "Volume is a raw type. References to generic type Volume should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 17)\n" + - " Volume v2 = v1.transform();\n" + - " ^^^^^^\n" + - "Volume is a raw type. References to generic type Volume should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109249 - variation -public void test0829() { - this.runConformTest( - new String[] { - "X.java", - "interface Transformable\n" + - "{\n" + - " public T transform();\n" + - "}\n" + - "interface Volume extends Transformable\n" + - "{\n" + - " public V transform();\n" + - "}\n" + - "public class X {\n" + - " void foo(){\n" + - " Volume v1 = null;\n" + - " Volume v2 = v1.transform();\n" + - " }\n" + - " void bar(){\n" + - " Volume v1 = null;\n" + - " Volume v2 = v1.transform();\n" + - " }\n" + - "}\n", - }, - ""); -} -// ensure no raw type ref complaint inside instanceof / cast -public void test0830() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo(Object o) {\n" + - " boolean b = o instanceof X;\n" + - " X x = (X) o;\n" + - " X xs = (X)o;\n" + - " Zork z;\n" + - " }\n" + - " void bar(ArrayList al) {\n" + - " List l = (List) al;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " X x = (X) o;\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " X x = (X) o;\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " X xs = (X)o;\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to X\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "5. WARNING in X.java (at line 10)\n" + - " List l = (List) al;\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 10)\n" + - " List l = (List) al;\n" + - " ^^^^^^^^^\n" + - "Unnecessary cast from ArrayList to List\n" + - "----------\n" + - "7. WARNING in X.java (at line 10)\n" + - " List l = (List) al;\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n"); -} -//unnecessary cast may be combined with unchecked cast warning -public void test0831() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo(Object o1) {\n" + - " Object o2 = (List) o1;\n" + - " \n" + - " foo((List)o2);\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Object o2 = (List) o1;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " Object o2 = (List) o1;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Object to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " foo((List)o2);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " foo((List)o2);\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Object to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106010 -public void test0832() { - this.runNegativeTest( - new String[] { - "X.java", - "class C1 {\n" + - " class C11 { }\n" + - " class C12 {\n" + - " T t;\n" + - " C1.C11[] m() {\n" + - " C1.C11[] ts = (C1.C11[]) new C1.C11[5];\n" + - " return ts;\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111014 -public void test0833() { - this.runConformTest( - new String[] { - "A.java", - "class A {}\n", - "B.java", - "class B extends A.Inner> { class Inner {} }\n", - "C.java", - "class C { B b; }\n", - }, - ""); - this.runConformTest( - new String[] { - "C.java", - "class C { B b; }\n", - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100809 -public void test0834() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Set set = new HashSet();\n" + - " set.add(42);\n" + - " Collection collection;\n" + - " collection = (Collection) set;\n" + - " System.out.println(collection.iterator().next());\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " collection = (Collection) set;\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Collection needs unchecked conversion to conform to Collection\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " collection = (Collection) set;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100809 - variation -public void test0835() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo(List ls) {\n" + - " ArrayList als = (ArrayList) ls;\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " ArrayList als = (ArrayList) ls;\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111208 -public void test0836() { - this.runConformTest( - new String[] { - "X.java", - " import java.util.Iterator;\n" + - " import java.util.List;\n" + - "\n" + - " public class X {\n" + - "\n" + - " interface Factory {\n" + - " T invoke();\n" + - " }\n" + - "\n" + - " public static Iterator iterate(Iterable iterable) {\n" + - " return iterable.iterator();\n" + - " }\n" + - "\n" + - " public Factory> factory(final Factory> factory) {\n" + - " return new Factory>() {\n" + - " public Iterator invoke() {\n" + - " //String s = iterate(factory.invoke());\n" + - " return iterate(factory.invoke());\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111208 - variation -public void test0837() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public void foo(List> l) {\n" + - " bar(l.get(0));\n" + - " swap(l.get(0));\n" + - " }\n" + - " void bar(String s) {}\n" + - " private static void swap(List l) {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " bar(l.get(0));\n" + - " ^^^\n" + - "The method bar(String) in the type X is not applicable for the arguments (capture#1-of ? extends List)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111689 -public void test0838() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public class CClass> {\n" + - " }\n" + - "}\n", - "AClass.java", - "public interface AClass {\n" + - " public interface BClass extends AClass {\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109118 -public void test0839() { - this.runConformTest( - new String[] { - "com/test/Tester.java", - "package com.test;\n" + - "\n" + - "import com.test.TestClass.MyException;\n" + - "\n" + - "public class Tester {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " TestClass test = new TestClass();\n" + - " } catch (MyException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}", - "com/test/TestClass.java", - "package com.test;\n" + - "\n" + - "public class TestClass {\n" + - " \n" + - " public TestClass() throws MyException {\n" + - " throw new MyException();\n" + - " }\n" + - "\n" + - " public static class MyException extends Exception {\n" + - " \n" + - " public MyException() {\n" + - " super();\n" + - " }\n" + - " }\n" + - "}" - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109118 -public void test0840() { - this.runNegativeTest( - new String[] { - "generics/NodeList.java", - "package generics;\n" + - "public class NodeList {\n" + - " public class Cursor { }\n" + - "}", - "generics/user/User.java", - "package generics.user;\n" + - "import generics.NodeList;\n" + - "import generics.NodeList.Cursor;\n" + - "public class User {\n" + - " Cursor raw;\n" + - " NodeList.Cursor rawQualified;\n" + - " NodeList.Cursor parameterized;\n" + - "\n" + - " void foo() {\n" + - " parameterized= rawQualified; //unchecked warning (OK)\n" + - " rawQualified= parameterized;\n" + - "\n" + - " parameterized= raw; //should just give unchecked warning, but errors\n" + - " raw= parameterized; //should not error\n" + - "\n" + - " raw= rawQualified; //should not error\n" + - " rawQualified= raw;\n" + - " }\n" + - " Zork z;\n" + - "}", - }, - "----------\n" + - "1. WARNING in generics\\user\\User.java (at line 5)\n" + - " Cursor raw;\n" + - " ^^^^^^\n" + - "NodeList.Cursor is a raw type. References to generic type NodeList.Cursor should be parameterized\n" + - "----------\n" + - "2. WARNING in generics\\user\\User.java (at line 6)\n" + - " NodeList.Cursor rawQualified;\n" + - " ^^^^^^^^^^^^^^^\n" + - "NodeList.Cursor is a raw type. References to generic type NodeList.Cursor should be parameterized\n" + - "----------\n" + - "3. WARNING in generics\\user\\User.java (at line 10)\n" + - " parameterized= rawQualified; //unchecked warning (OK)\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The expression of type NodeList.Cursor needs unchecked conversion to conform to NodeList.Cursor\n" + - "----------\n" + - "4. WARNING in generics\\user\\User.java (at line 13)\n" + - " parameterized= raw; //should just give unchecked warning, but errors\n" + - " ^^^\n" + - "Type safety: The expression of type NodeList.Cursor needs unchecked conversion to conform to NodeList.Cursor\n" + - "----------\n" + - "5. ERROR in generics\\user\\User.java (at line 19)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112268 -public void test0841() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " List bar() {\n" + - " List l = foo();\n" + - " return foo();\n" + - " }\n" + - " List foo() {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112500 -public void test0842() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " static List merge(List a, List b) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " List list1 = null;\n" + - " List list2 = null;\n" + - " List result = merge(list1, list2);\n" + - " List result2 = merge(list1, list2);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " List result2 = merge(list1, list2);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); -} -public void test0843() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " static List merge(List a, List b) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " List list1 = null;\n" + - " List list2 = null;\n" + - " Object result3 = (List)merge(list1, list2);\n" + - " Object result4 = (List)merge(list1, list2);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 11)\n" + - " Object result3 = (List)merge(list1, list2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from List to List\n" + - "----------\n" + - "2. ERROR in X.java (at line 12)\n" + - " Object result4 = (List)merge(list1, list2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " Object result4 = (List)merge(list1, list2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from List to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112595 -public void test0844() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " public Set< ? extends X> getModifiers()\n" + - " {\n" + - " return Collections.emptySet();\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112595 -public void test0845() { - this.runConformTest( - new String[] { - "Generic.java", // ================= - "public class Generic {\n" + - " public int size() {\n" + - " return 0;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}", // ================= - }, - "SUCCESS"); - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.ArrayList;\n" + - "\n" + - "public class X {\n" + - " public void testList(ArrayList aList) {\n" + - " aList.size();\n" + - " }\n" + - " public void testGeneric(Generic aGeneric) {\n" + - " aGeneric.size();\n" + - " }\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " public void testList(ArrayList aList) {\n" + - " ^^^^^^^^^\n" + - "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " public void testGeneric(Generic aGeneric) {\n" + - " ^^^^^^^\n" + - "Generic cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - } -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112666 -public void test0846() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.Collection;\n" + - "public class X {\n" + - " void m() {\n" + - " Collection> col = null;\n" + - " java.util.List n = null;\n" + - " col.add(n);\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112666 -public void test0847() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.Collection;\n" + - "\n" + - "public class X {\n" + - " void m() {\n" + - " Collection> col = null;\n" + - " java.util.List n = null;\n" + - " col.add(n);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " col.add(n);\n" + - " ^^^\n" + - "The method add(capture#1-of ? extends Collection) in the type Collection> is not applicable for the arguments (List)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106451 -public void test0848() throws Exception { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Collection asList= Arrays.asList(1, 2.2);\n" + - " List nums= (List) asList; // correct warning\n" + - " List numz= (LinkedList) asList; // type safety warning missing\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Collection asList= Arrays.asList(1, 2.2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Number&Comparable is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " List nums= (List) asList; // correct warning\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Collection to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " List numz= (LinkedList) asList; // type safety warning missing\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Collection to LinkedList\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); - - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Collection asList= Arrays.asList(1, 2.2);\n" + - " List nums= (List) asList; // correct warning\n" + - " List numz= (LinkedList) asList; // type safety warning missing\n" + - "}\n", // ================= - }, - ""); - // ensure presence of: "checkcast java.util.LinkedList" before putfield X.numz - String expectedOutput = - " // Method descriptor #14 ()V\n" + - " // Stack: 6, Locals: 1\n" + - " public X();\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [16]\n" + - " 4 aload_0 [this]\n" + - " 5 iconst_2\n" + - " 6 anewarray java.lang.Number [18]\n" + - " 9 dup\n" + - " 10 iconst_0\n" + - " 11 iconst_1\n" + - " 12 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [20]\n" + - " 15 aastore\n" + - " 16 dup\n" + - " 17 iconst_1\n" + - " 18 ldc2_w [26]\n" + - " 21 invokestatic java.lang.Double.valueOf(double) : java.lang.Double [28]\n" + - " 24 aastore\n" + - " 25 invokestatic java.util.Arrays.asList(java.lang.Object[]) : java.util.List [33]\n" + - " 28 putfield X.asList : java.util.Collection [38]\n" + - " 31 aload_0 [this]\n" + - " 32 aload_0 [this]\n" + - " 33 getfield X.asList : java.util.Collection [38]\n" + - " 36 checkcast java.util.List [40]\n" + - " 39 putfield X.nums : java.util.List [42]\n" + - " 42 aload_0 [this]\n" + - " 43 aload_0 [this]\n" + - " 44 getfield X.asList : java.util.Collection [38]\n" + - " 47 checkcast java.util.LinkedList [44]\n" + - " 50 putfield X.numz : java.util.List [46]\n" + - " 53 return\n"; - - 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); - } -} -//ensure no unsafe cast is diagnosed -public void test0849() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " static T[] cast(U[] a) { return (T[]) a; }\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " static T[] cast(U[] a) { return (T[]) a; }\n" + - " ^^^^^^^\n" + - "Unnecessary cast from U[] to T[]\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test0850() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " T f(Object o) {\n" + - " return (T) o; // OK\n" + - " }\n" + - "\n" + - " T g(Object o) {\n" + - " return (T) o; // bug???\n" + - " }\n" + - "\n" + - " T h(Object o) {\n" + - " return X.castTo(o); // workaround\n" + - " }\n" + - "\n" + - " private static T castTo(Object o) {\n" + - " return (T) o;\n" + - " }\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " return (T) o; // OK\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " return (T) o; // bug???\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "3. WARNING in X.java (at line 15)\n" + - " return (T) o;\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "4. ERROR in X.java (at line 17)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test0851() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "interface Foo {}\n" + - "interface Bar {}\n" + - "public class X {\n" + - " Object m(Foo f) {\n" + - " return (Bar)f;\n" + - " }\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " return (Bar)f;\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Foo to Bar\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " return (Bar)f;\n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Foo to Bar\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106466 -public void test0852() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " T foo() { return null; }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " T foo() { return null; }\n" + - " ^^^^^^^^\n" + - "Cannot specify any additional bound Runnable when first bound is a type parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112109 -public void test0853() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " void test(java.util.List list) { list.get(0).notify(null); }\n" + - "}\n" + - "interface I { Object notify(Object o); }", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113236 -public void test0854() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Field field = new Field();\n" + - " Form form = new Form(field);\n" + - " String result = form.getField().toString();\n" + - " System.out.print(result);\n" + - " }\n" + - "}", - "Form.java", - "public class Form {\n" + - " private final Field field;\n" + - " public Form(Field field) {\n" + - " this.field = field;\n" + - " }\n" + - " public T getField() {\n" + - " return (T) field;\n" + - " }\n" + - "}", - "Field.java", - "public class Field {\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - "}", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113218 -public void test0855() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " FieldManager manager = new FieldManagerImpl();\n" + - " FieldMeta meta = new FieldMeta(manager);\n" + - " Field field = new FieldImpl(meta);\n" + - " FieldMeta meta2 = field.getFieldMeta();\n" + - " System.out.print(meta2.getFieldManager() instanceof ExtFieldManager);\n" + - " }\n" + - "}", - "FieldMeta.java", - "public class FieldMeta {\n" + - " private final FieldManager fieldManager;\n" + - " public FieldMeta(FieldManager fieldManager) {\n" + - " this.fieldManager = fieldManager;\n" + - " }\n" + - " public > FB getFieldManager() {\n" + - " return (FB) fieldManager;\n" + - " }\n" + - "}", - "FieldManagerImpl.java", - "public class FieldManagerImpl extends FieldManager implements\n" + - " ExtFieldManager {\n" + - "}", - "FieldManager.java", - "public abstract class FieldManager {}", - "FieldImpl.java", - "public class FieldImpl extends Field {\n" + - " public FieldImpl(FieldMeta fieldMeta) {\n" + - " super(fieldMeta);\n" + - " }\n" + - "}", - "Field.java", - "public class Field {\n" + - " private final FieldManager fieldManager;\n" + - " private final FieldMeta fieldMeta;\n" + - " public FieldMeta getFieldMeta() {\n" + - " return fieldMeta;\n" + - " }\n" + - " public Field(FieldMeta fieldMeta) {\n" + - " this.fieldMeta = fieldMeta;\n" + - " this.fieldManager = fieldMeta.getFieldManager();\n" + - " }\n" + - " public FieldManager getFieldManager() {\n" + - " return fieldManager;\n" + - " }\n" + - "}", - "ExtFieldManager.java", - "public interface ExtFieldManager {}" - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "true" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test0856() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " static class MX {\n" + - " T t = null;\n" + - " }\n" + - " static T getT() {\n" + - " return (new MX()).t;\n" + - " }\n" + - " public static void test() {\n" + - " getT().getClass(); // error: java.lang.Object cannot be dereferenced\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113070 -public void test0857() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public void m(T t) {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public void m(T t) {\n" + - " ^^^^^^^^^\n" + - "Cannot specify any additional bound Cloneable when first bound is a type parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113560 -public void test0858() { - this.runConformTest( - new String[] { - "X.java", - "interface ExtCloneable extends Cloneable {\n" + - " public ExtCloneable clone( String arg) throws CloneNotSupportedException;\n" + - "}\n" + - "public class X {\n" + - " public static ExtCloneable cloneItem1( V value) throws CloneNotSupportedException {\n" + - " return value.clone( \"\");\n" + - " }\n" + - " public static ExtCloneable cloneItem2( ExtCloneable value) throws CloneNotSupportedException {\n" + - " return value.clone( \"\");\n" + - " }\n" + - " public static ExtCloneable cloneItem3( V value) throws CloneNotSupportedException {\n" + - " return ((ExtCloneable)value).clone( \"\");\n" + - " }\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113710 -public void test0859() { - this.runConformTest( - new String[] { - "X.java", - "import java.awt.Graphics2D;\n" + - "import java.awt.Shape;\n" + - "public class X {\n" + - " /** Base object for wrapping */\n" + - " protected V draw;\n" + - " /**\n" + - " * Draw the object with its attached text\n" + - " * \n" + - " * @param graphics the graphics object to draw into\n" + - " */\n" + - " public void draw( Graphics2D graphics ) {\n" + - " draw.draw(graphics);\n" + - " }\n" + - "}\n" + - "abstract class DrawObject implements Drawable {\n" + - " protected void draw( Graphics2D graphics, Shape shape ) {\n" + - " }\n" + - "}\n" + - "interface Drawable {\n" + - " void draw( Graphics2D graphics );\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 -public void test0860() { - this.runConformTest( - new String[] { - "A.java", - "interface A {\n" + - " A.I foo();\n" + - " interface I { }\n" + - "}\n" + - "\n" + - "interface B extends A { }\n" + - "\n" + - "interface C extends B {\n" + - " C.J foo();\n" + - " interface J extends B.I { }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation -public void test0861() { - this.runConformTest( - new String[] { - "A.java", - "interface A {\n" + - " A.I foo();\n" + - " interface I { }\n" + - "}\n" + - "\n" + - "interface B extends A { }\n" + - "\n" + - "interface C extends B {\n" + - " C.J foo();\n" + - " interface J extends A.I { }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation -public void test0862() { - this.runConformTest( - new String[] { - "A.java", - "interface A {\n" + - " interface I { }\n" + - "\n" + - " A.I foo();\n" + - "}\n" + - "\n" + - "interface B extends A { \n" + - " interface J extends B.I { }\n" + - "}\n" + - "\n" + - "interface C extends B {\n" + - " C.J foo();\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation -public void test0863() { - this.runConformTest( - new String[] { - "A.java", - "interface A {\n" + - " interface I { }\n" + - "\n" + - " A.I foo();\n" + - "}\n" + - "\n" + - "interface B extends A { \n" + - " interface J extends B.I { }\n" + - "}\n" + - "\n" + - "interface C extends B {\n" + - " B.J foo();\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation -public void test0864() { - this.runConformTest( - new String[] { - "A.java", - "interface A {\n" + - " interface I { }\n" + - "\n" + - " A.I foo();\n" + - "}\n" + - "\n" + - "interface B extends A { \n" + - " interface J extends B.I { }\n" + - "}\n" + - "\n" + - "interface C extends B {\n" + - " C.J foo();\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation -public void test0865() { - this.runConformTest( - new String[] { - "A.java", - "class A {\n" + - " interface I { }\n" + - "\n" + - " A.I foo() { return null; }\n" + - "}\n" + - "\n" + - "class B extends A { \n" + - " interface J extends B.I { }\n" + - "}\n" + - "\n" + - "class C extends B {\n" + - " @Override\n" + - " C.J foo() { return (B.J)super.foo(); }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114997 -public void test0866() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Collections;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public interface Interface {\n" + - " // nothing\n" + - " }\n" + - " public List field = Collections.emptyList();\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114087 -public void test0867() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "class Foo {\n" + - "\n" + - " static List> foo1() {\n" + - " return null;\n" + - " }\n" + - " static void bar1(List> l) {\n" + - " }\n" + - " static List foo2() {\n" + - " return null;\n" + - " }\n" + - " static void bar2(List l) {\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - "\n" + - " {\n" + - " List o = Foo.foo1();\n" + - " Foo.bar1(o);\n" + - " }\n" + - " {\n" + - " List o = Foo.foo2();\n" + - " Foo.bar2(o);\n" + - " }\n" + - "\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 20)\n" + - " List o = Foo.foo1();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 20)\n" + - " List o = Foo.foo1();\n" + - " ^^^^\n" + - "The method foo1() in the type Foo is not applicable for the arguments ()\n" + - "----------\n" + - "3. ERROR in X.java (at line 21)\n" + - " Foo.bar1(o);\n" + - " ^^^^\n" + - "The method bar1(List>) in the type Foo is not applicable for the arguments (List)\n" + - "----------\n" + - "4. WARNING in X.java (at line 24)\n" + - " List o = Foo.foo2();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 25)\n" + - " Foo.bar2(o);\n" + - " ^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar2(List) of the generic method bar2(List) of type Foo\n" + - "----------\n" + - "6. WARNING in X.java (at line 25)\n" + - " Foo.bar2(o);\n" + - " ^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114365 -public void test0868() { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runConformTest( - new String[] { - "X.java", - "import java.util.Collection;\n" + - "import java.util.Iterator;\n" + - "import java.io.Serializable;\n" + - "import java.lang.Cloneable;\n" + - "public class X implements Collection {\n" + - " public int size() {\n" + - " // TODO Auto-generated method stub\n" + - " return 0;\n" + - " }\n" + - " public boolean isEmpty() {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public boolean contains(Object arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public Iterator iterator() {\n" + - " // TODO Auto-generated method stub\n" + - " return null;\n" + - " }\n" + - " public Object[] toArray() {\n" + - " // TODO Auto-generated method stub\n" + - " return null;\n" + - " }\n" + - " public Object[] toArray(Object[] arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return null;\n" + - " }\n" + - " public boolean add(Object arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public boolean remove(Object arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public boolean containsAll(Collection arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public boolean addAll(Collection arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public boolean removeAll(Collection arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public boolean retainAll(Collection arg0) {\n" + - " // TODO Auto-generated method stub\n" + - " return false;\n" + - " }\n" + - " public void clear() {\n" + - " // TODO Auto-generated method stub\n" + - " \n" + - " }" + - "}", - }, - "", - null, - true, - null, - options, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115181 -public void test0869() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Comparator;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class c = Comparator.class;\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113950 -public void test0870() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public interface I {\n" + - " public void foo(List ls);\n" + - " }\n" + - "\n" + - " public abstract class A implements I {\n" + - " public void foo(List ls) { }\n" + - " }\n" + - "\n" + - " public class C extends A> { }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107788 -public void test0871() { - this.runConformTest( - new String[] { - "Lister.java", - "interface Lister {\n" + - " void endPacking(PackT p, BeanT b, Accessor acc);\n" + - "\n" + - " static class IDRefs implements\n" + - " Lister.Pack> {\n" + - " public void endPacking(Pack p, BeanT b, Accessor acc) {\n" + - " }\n" + - "\n" + - " private class Pack {\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class Accessor {\n" + - "}\n", - }, - ""); -} -public void test0872() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.io.PrintStream;\n" + - "\n" + - "public class X {\n" + - " public void foo1(){\n" + - " M1 m = new M1();\n" + - " M1.N1 n = m.new N1();\n" + - " }\n" + - " static class M1 {\n" + - " class N1 {\n" + - " }\n" + - " }\n" + - " public void foo2(){\n" + - " M2 m = new M2();\n" + - " M2.N2 n = m.new N2();\n" + - " }\n" + - " class M2 {\n" + - " class N2 {\n" + - " }\n" + - " }\n" + - " public void foo3(){\n" + - " M3 m = new M3();\n" + - " M3.N3 n = m.new N3();\n" + - " }\n" + - " class M3 {\n" + - " static class N3 {\n" + - " }\n" + - " }\n" + - " public void foo4(){\n" + - " M4 m = new M4();\n" + - " M4.N4 n = m.new N4();\n" + - " }\n" + - " static class M4 {\n" + - " static class N4 {\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 22)\n" + - " M3.N3 n = m.new N3();\n" + - " ^^^^^^^^\n" + - "The member type X.M3.N3 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M3\n" + - "----------\n" + - "2. ERROR in X.java (at line 25)\n" + - " static class N3 {\n" + - " ^^\n" + - "The member type N3 cannot be declared static; static types can only be declared in static or top level types\n" + - "----------\n" + - "3. ERROR in X.java (at line 30)\n" + - " M4.N4 n = m.new N4();\n" + - " ^^^^^^^^\n" + - "The member type X.M4.N4 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M4\n" + - "----------\n"); -} -public void test0873() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " static class XMap {\n" + - " XEntry[] table;\n" + - " static class XEntry {} \n" + - " void foo() {\n" + - " XEntry e = table[0];\n" + - " } \n" + - " } \n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115693 -public void test0874() throws Exception { - this.runConformTest( - new String[] { - "X.java", // ================= - "class A {}\n" + - "abstract class B {\n" + - " public B label(String s) { return this; }\n" + - "}\n" + - "final class C extends B {\n" + - " public static C instance(String s) { return new C(); }\n" + - " @Override public String toString() {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " C c = (C)C.instance(\"X\").label(\"Y\");\n" + - " System.out.println(c.toString());\n" + - " }\n" + - "}\n", - }, - "SUCCESS"); - // ensure only one checkcast C - String expectedOutput = - " // Method descriptor #15 ([Ljava/lang/String;)V\n" + - " // Stack: 2, Locals: 2\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 ldc [16]\n" + - " 2 invokestatic C.instance(java.lang.String) : C [17]\n" + - " 5 ldc [23]\n" + - " 7 invokevirtual C.label(java.lang.String) : B [25]\n" + - " 10 checkcast C [18]\n" + - " 13 astore_1 [c]\n" + - " 14 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + - " 17 aload_1 [c]\n" + - " 18 invokevirtual C.toString() : java.lang.String [35]\n" + - " 21 invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + - " 24 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 13]\n" + - " [pc: 14, line: 14]\n" + - " [pc: 24, line: 15]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 25] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 14, pc: 25] local: c index: 1 type: C\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 -public void test0875() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - "\n" + - " public static class DatabaseObject {}\n" + - " public static class ObjectFormUI {}\n" + - " private static final Map, Class> uiMap = new HashMap, Class>();\n" + - "\n" + - " public static Class> getUI(\n" + - " Class persistentClass) {\n" + - " return null != null \n" + - " ? uiMap.get(persistentClass)\n" + - " : (Class>) uiMap.get(persistentClass);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " private static final Map, Class> uiMap = new HashMap, Class>();\n" + - " ^^^^^^^^^^^^\n" + - "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " private static final Map, Class> uiMap = new HashMap, Class>();\n" + - " ^^^^^^^^^^^^\n" + - "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " return null != null \n" + - " ? uiMap.get(persistentClass)\n" + - " : (Class>) uiMap.get(persistentClass);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " : (Class>) uiMap.get(persistentClass);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Class to Class>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 - variation -public void test0876() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " void foo(){\n" + - " Class> cco = null;\n" + - " Class cc = cco; // ko\n" + - " Class> cco2 = cc; // ko\n" + - " \n" + - " Class> ceco = null;\n" + - " Class cec = ceco; // ok\n" + - " Class> ceco2 = cec; // ko\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " Class cc = cco; // ko\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Class cc = cco; // ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from Class> to Class\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " Class> cco2 = cc; // ko\n" + - " ^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " Class cec = ceco; // ok\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 10)\n" + - " Class> ceco2 = cec; // ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 - variation -public void test0877() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " void bar(T t) {\n" + - " Class c = t; // ok - unchecked\n" + - " }\n" + - " void bar2(List let) {\n" + - " Class c = let.get(0); // ok - unchecked\n" + - " }\n" + - " void bar3(List lec) {\n" + - " Class c = lec.get(0); // ok - unchecked\n" + - " }\n" + - " Zork z;\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " void bar(T t) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " void bar(T t) {\n" + - " ^^^^^\n" + - "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " Class c = t; // ok - unchecked\n" + - " ^\n" + - "Type safety: The expression of type T needs unchecked conversion to conform to Class\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " void bar2(List let) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 6)\n" + - " void bar2(List let) {\n" + - " ^^^^^\n" + - "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + - "----------\n" + - "6. WARNING in X.java (at line 7)\n" + - " Class c = let.get(0); // ok - unchecked\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type capture#1-of ? extends T needs unchecked conversion to conform to Class\n" + - "----------\n" + - "7. WARNING in X.java (at line 9)\n" + - " void bar3(List lec) {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 10)\n" + - " Class c = lec.get(0); // ok - unchecked\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type capture#2-of ? extends Class needs unchecked conversion to conform to Class\n" + - "----------\n" + - "9. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115693 - variation -public void test0878() throws Exception { - this.runConformTest( - new String[] { - "X.java", // ================= - "class A {}\n" + - "class D extends A {}\n" + - "abstract class B {\n" + - " public T label(String s) { return null; }\n" + - "}\n" + - "final class C extends B {\n" + - " public static C instance(String s) { return new C(); }\n" + - " @Override public String toString() {\n" + - " return \"SUCCESS\"; \n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " D d = (D)C.instance(\"X\").label(\"Y\");\n" + - " System.out.println(d);\n" + - " }\n" + - "}\n", - }, - "null"); - // ensure only one checkcast D - String expectedOutput = - " // Method descriptor #15 ([Ljava/lang/String;)V\n" + - " // Stack: 2, Locals: 2\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 ldc [16]\n" + - " 2 invokestatic C.instance(java.lang.String) : C [17]\n" + - " 5 ldc [23]\n" + - " 7 invokevirtual C.label(java.lang.String) : java.lang.Object [25]\n" + - " 10 checkcast D [29]\n" + - " 13 astore_1 [d]\n" + - " 14 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + - " 17 aload_1 [d]\n" + - " 18 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [37]\n" + - " 21 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 14]\n" + - " [pc: 14, line: 15]\n" + - " [pc: 21, line: 16]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 22] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 14, pc: 22] local: d index: 1 type: D\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122610 -public void test0879() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - "\n" + - " private class InnerClass1 {\n" + - " void foo() {\n" + - " X c = X.this;\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 -public void test0880() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "class Foo {\n" + - " static > U foo() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " {\n" + - " String s = (String) Foo.foo();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " String s = (String) Foo.foo();\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation -public void test0881() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "class Foo {\n" + - " static > U foo() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " {\n" + - " String s = (String) Foo.foo();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " String s = (String) Foo.foo();\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List> to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " String s = (String) Foo.foo();\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo() of type Foo is not applicable for the arguments (). The inferred type List> is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation -public void test0882() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " static > U foo(U u) {\n" + - " String s = (String) foo(u);\n" + - " return u;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " String s = (String) foo(u);\n" + - " ^^^^^^^^^^^^^^^\n" + - "Cannot cast from U to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation -public void test0883() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " static > U foo(U u) {\n" + - " List listu = null;\n" + - " String s = (String)foo(listu);\n" + - " return u;\n" + - " }\n" + - " static > V bar(V v) {\n" + - " List listv = null;\n" + - " String s = (String)foo(listv);\n" + - " return v;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " String s = (String)foo(listu);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " String s = (String)foo(listu);\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo(U) of type X is not applicable for the arguments (List). The inferred type List is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "3. ERROR in X.java (at line 11)\n" + - " String s = (String)foo(listv);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to String\n" + - "----------\n" + - "4. ERROR in X.java (at line 11)\n" + - " String s = (String)foo(listv);\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo(U) of type X is not applicable for the arguments (List). The inferred type List is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=123078 -public void test0884() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public abstract class X> {\n" + - " public static > T getDefault(Class clz) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " public Object getDefault() {\n" + - " String s = getClass();\n" + - " return (String) getDefault(getClass());\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " String s = getClass();\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " return (String) getDefault(getClass());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from capture#2-of ? extends X to String\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " return (String) getDefault(getClass());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation getDefault(Class) of the generic method getDefault(Class) of type X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125445 -public void test0885() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static > int m(\n" + - " A comparableNumberObj) {\n" + - " return comparableNumberObj.compareTo(comparableNumberObj);\n" + - " }\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public static > int m(\n" + - " ^^^^^^^^^^\n" + - "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124943 -public void test0886() { - Map customOptions= getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", // ================= - "public class X {\n" + - " void test() {\n" + - " \"Hello\".compareTo((Object) \"Hello\");\n" + - " }\n" + - "}\n" , - }, - // compiler options - null /* no class libraries */, - customOptions /* custom options */, - // compiler results - "" /* expected compiler log */, - // runtime results - "" /* expected output string */, - null /* do not check error string */, - // javac options - new JavacTestOptions("-source 1.4") /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 -public void test0887() { - this.runNegativeTest( - new String[] { - "Bar.java", // ================= - "class Foo {}\n" + - "public class Bar>>{\n" + - " Bar(X x){\n" + - " Foo f = x;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Bar.java (at line 4)\n" + - " Foo f = x;\n" + - " ^\n" + - "Type mismatch: cannot convert from X to Foo\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation -public void test0888() { - this.runNegativeTest( - new String[] { - "Bar.java", // ================= - "class Foo {}\n" + - "public class Bar>>{\n" + - " Bar(X x){\n" + - " Foo f = x;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Bar.java (at line 4)\n" + - " Foo f = x;\n" + - " ^\n" + - "Type mismatch: cannot convert from X to Foo\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation -public void test0889() { - this.runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "Test.java", // ================= - "import java.util.*;\n" + - "\n" + - "class Group> extends ArrayList implements\n" + - " Comparable> {\n" + - " public int compareTo(Group o) {\n" + - " return 0;\n" + - " }\n" + - "}\n" + - "\n" + - "class Sequence> extends TreeSet implements\n" + - " Comparable> {\n" + - " public int compareTo(Sequence o) {\n" + - " return 0;\n" + - " }\n" + - "}\n" + - "\n" + - "class Test> {\n" + - " > void foo(SortedSet setToCheck,\n" + - " SortedSet validSet) {\n" + - " }\n" + - "\n" + - " public void containsCombination(SortedSet> groups,\n" + - " SortedSet> sequences) {\n" + - " foo(groups, sequences);\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation -public void test0890() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "Simple.java", // ================= - "class A> {}\n" + - "class B extends A {}\n" + - "class C extends B {}\n" + - "class D {}\n" + - "\n" + - "public class Simple {\n" + - " , S extends T> D m(S s) {\n" + - " C c = null;\n" + - " D d = m(c);\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation -public void test0891() { - this.runNegativeTest( - new String[] { - "Test.java", // ================= - "interface Function {\n" + - " B apply(A x);\n" + - "}\n" + - "class Id implements Function {\n" + - " public A apply(A x) {\n" + - " return x;\n" + - " }\n" + - "}\n" + - "class Test {\n" + - " Id identity() {\n" + - " return new Id();\n" + - " }\n" + - "\n" + - " B applyToString(Function f) {\n" + - " return f.apply(\"abc\");\n" + - " }\n" + - " void test() {\n" + - " String s = applyToString(identity());\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in Test.java (at line 18)\n" + - " String s = applyToString(identity());\n" + - " ^^^^^^^^^^^^^\n" + - "The method applyToString(Function) in the type Test is not applicable for the arguments (Id)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126180 -public void test0892() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static void main(String[] args) {\n" + - " C2 c2 = null;\n" + - " C3 c3 = null;\n" + - " Object oc1 = m1(c2, c3).new C1Member();\n" + - " }\n" + - "\n" + - " public static T m1(T t1, T t2) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " class C1 {}\n" + - " interface I1 {}\n" + - " class C2 extends C1 implements I1 {}\n" + - " class C3 extends C1 implements I1 {\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Object oc1 = m1(c2, c3).new C1Member();\n" + - " ^^^^^^^^\n" + - "X.C1&X.I1.C1Member cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126177 -public void test0893() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " static String foo;\n" + - "\n" + - " public static void main(String[] args) {\n" + - " C2 c2 = null;\n" + - " C3 c3 = null;\n" + - " // method access\n" + - " m1(c2, c3).c1m1();\n" + - " m1(c2, c3).i1m1();\n" + - " m1(c2, c3).i2m1();\n" + - "\n" + - " // field access\n" + - " int ic1 = m1(c2, c3).c1f1;\n" + - " int ii1 = m1(c2, c3).i1f1;\n" + - " int ii2 = m1(c2, c3).i2f1;\n" + - " \n" + - " // member type access\n" + - " Object oc1 = m1(c2, c3).new C1Member();\n" + - " Object oi1 = m1(c2, c3).new I1Member(); \n" + - " Object oi2 = m1(c2, c3).new I2Member();\n" + - " }\n" + - "\n" + - " public static T m1(T t1, T t2) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " class C1 {\n" + - " void c1m1() {}\n" + - " int c1f1 = 0;\n" + - " class C1Member {}\n" + - " }\n" + - "\n" + - " interface I1 {\n" + - " void i1m1();\n" + - " int i1f1 = 1;\n" + - " class I1Member {}\n" + - " }\n" + - "\n" + - " interface I2 {\n" + - " void i2m1();\n" + - " int i2f1 = 2;\n" + - " class I2Member {}\n" + - " }\n" + - "\n" + - " class C2 extends C1 implements I1, I2 {\n" + - " public void i1m1() {\n" + - " }\n" + - " public void i2m1() {\n" + - " }\n" + - " }\n" + - "\n" + - " class C3 extends C1 implements I1, I2 {\n" + - " public void i1m1() {\n" + - " }\n" + - " public void i2m1() {\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 14)\n" + - " int ii1 = m1(c2, c3).i1f1;\n" + - " ^^^^\n" + - "The static field X.I1.i1f1 should be accessed in a static way\n" + - "----------\n" + - "2. WARNING in X.java (at line 15)\n" + - " int ii2 = m1(c2, c3).i2f1;\n" + - " ^^^^\n" + - "The static field X.I2.i2f1 should be accessed in a static way\n" + - "----------\n" + - "3. ERROR in X.java (at line 19)\n" + - " Object oi1 = m1(c2, c3).new I1Member(); \n" + - " ^^^^^^^^^^\n" + - "Illegal enclosing instance specification for type X.I1.I1Member\n" + - "----------\n" + - "4. ERROR in X.java (at line 20)\n" + - " Object oi2 = m1(c2, c3).new I2Member();\n" + - " ^^^^^^^^^^\n" + - "Illegal enclosing instance specification for type X.I2.I2Member\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126177 - variation -public void test0894() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", // ================= - "public class X {\n" + - " static class C1 {\n" + - " void c1m1() {\n" + - " System.out.print(\"[c1m1]\");\n" + - " }\n" + - " }\n" + - " static interface I {}\n" + - " static class C2 extends C1 implements I {}\n" + - " static class C3 extends C1 implements I {}\n" + - "\n" + - " public T m1(T t1, T t2) {\n" + - " return t1;\n" + - " }\n" + - "\n" + - " public void test(C2 c2, C3 c3, T t) {\n" + - " m1(c2, c3).c1m1(); // 1\n" + - " t.c1m1(); // 2\n" + - " (t != null ? c2 : c3).c1m1(); // 3\n" + - " }\n" + - "\n" + - " public static void main(String... args) {\n" + - " X x = new X();\n" + - " x.test(new C2(), new C3(), new C2()); // 4\n" + - " System.out.println();\n" + - " }\n" + - "}\n", - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "[c1m1][c1m1][c1m1]" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test0895() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "interface I {}\n" + - "public class X {\n" + - " Object o = new I() {};\n" + - "}\n" , - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Object o = new I() {};\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The constructor Object() of type Object is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - return; - } - this.runNegativeTest( - new String[] { - "X.java", // ================= - "interface I {}\n" + - "public class X {\n" + - " Object o = new I() {};\n" + - "}\n" , - "Y.java", - "class Y extends Zork {}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " Object o = new I() {};\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor Object() of type Object; it should not be parameterized with arguments \n" + - "----------\n" + - "----------\n" + - "1. ERROR in Y.java (at line 1)\n" + - " class Y extends Zork {}\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test0896() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", // ================= - "public class X {\n" + - " interface I { void f(); }\n" + - " interface J { void g(); }\n" + - "\n" + - " static class A implements I, J {\n" + - " public void f() { System.out.print(\"[A#f()]\");}\n" + - " public void g() { System.out.print(\"[A#g()]\");}\n" + - " }\n" + - "\n" + - " static class B implements J, I {\n" + - " public void f() { System.out.print(\"[B#f()]\");}\n" + - " public void g() { System.out.print(\"[B#g()]\");}\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " f(true, new A(), new B());\n" + - " f(false, new A(), new B());\n" + - " System.out.println();\n" + - " }\n" + - "\n" + - " static void f(boolean cond, A a, B b) {\n" + - " (cond ? a : b).f();\n" + - " (cond ? a : b).g();\n" + - " }\n" + - "}\n", - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "[A#f()][A#g()][B#f()][B#g()]" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test0897() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "Test.java", // ================= - "interface I { }\n" + - "class X { }\n" + - "class A extends X implements I { }\n" + - "class B extends X implements I { }\n" + - "public class Test {\n" + - " void test(A a, B b) {\n" + - " X x = (a.hashCode() == b.hashCode()) ? a : b;\n" + - " }\n" + - "}\n" + - "\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test0898() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", // ================= - "interface I1 {\n" + - " void i1();\n" + - "}\n" + - "class G1 {\n" + - " T get() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "interface I2 {\n" + - " void i2();\n" + - "}\n" + - "public class X {\n" + - " void f1(G1 g1) {\n" + - " g1.get().i1();\n" + - " }\n" + - " void f2(G1 g1) {\n" + - " g1.get().i1();\n" + - " g1.get().i2();\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122331 -public void test0899() { - this.runConformTest( - new String[] { - "A.java", // ================= - "public class A> extends SomeArbitraryClass {\n" + - " public static class B {\n" + - " private C c;\n" + - " protected void set(C val) {\n" + - " c = val;\n" + - " }\n" + - " protected class C {\n" + - " }\n" + - " }\n" + - "}", - "C.java", - "public class C {\n" + - " \n" + - " public C() {\n" + - " //do nothing\n" + - " }\n" + - " \n" + - "}", - "ObjThatExtendsB.java", - "public class ObjThatExtendsB extends A.B {\n" + - " protected void doSomeSetting() {\n" + - " super.set(new ObjThatExtendsC());\n" + - " }\n" + - " protected class ObjThatExtendsC extends C {\n" + - " }\n" + - "}", - "ObjThatExtendsC.java", - "public class ObjThatExtendsC extends C {\n" + - " public ObjThatExtendsC() {\n" + - " //do nothing\n" + - " }\n" + - "}", - "SomeArbitraryClass.java", - "public class SomeArbitraryClass> {\n" + - " public SomeArbitraryClass() {\n" + - " //do nothing\n" + - " }\n" + - "}" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97693 -public void test0900() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " static interface Interface extends Comparable {}\n" + - "\n" + - " static final class Implements implements Interface {\n" + - " public int compareTo(String o) {\n" + - " return 0;\n" + - " }\n" + - " }\n" + - "\n" + - " void method() {\n" + - " ((Comparable) new Implements()).toString();\n" + - " ((Comparable) new Implements()).toString();\n" + - " ((Comparable) new Implements()).toString();\n" + - " ((Comparable) new Implements()).toString();\n" + - " ((Comparable) new Implements()).toString();\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 11)\n" + - " ((Comparable) new Implements()).toString();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X.Implements to Comparable\n" + - "----------\n" + - "2. WARNING in X.java (at line 12)\n" + - " ((Comparable) new Implements()).toString();\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 16)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -// Object array vs Object into generic method -public void test0901() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " static T foo(T p1, T p2) {\n" + - " return p1;\n" + - " }\n" + - " static Object[] bar(int[] i, float[] f) {\n" + - " return foo(i, f);\n" + - " }\n" + - "}"}, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " return foo(i, f);\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object&Serializable&Cloneable to Object[]\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -// circular references amongst generic interfaces with co-implementing classes -public void test0902() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "I.java", - "public interface I>> {\n" + - "}", - "J.java", - "public interface J>> {\n" + - "}", - "CI.java", - "class CI & J,\n" + - " T extends CI & I>\n" + - " implements I {\n" + - "}", - "CJ.java", - "class CJ & I,\n" + - " U extends CJ & J>\n" + - " implements J {\n" + - "}"}, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126914 -public void test0903() { - this.runConformTest( - new String[] { - "X.java", - "interface I, U extends I> {\n" + - " // empty\n" + - "}\n" + - "interface J, U extends I> {\n" + - " // empty\n" + - "}\n" + - "final class Y extends X implements I, Y> {\n" + - " // empty\n" + - "}\n" + - "abstract class X implements J, Y> {\n" + - " // empty\n" + - "}\n" - }, - ""); -} - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126914 -public void test0904() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "interface I, U extends I> {\n" + - " // empty\n" + - "}\n" + - "interface J, U extends I> {\n" + - " // empty\n" + - "}\n" + - "abstract class X implements J, Y> {\n" + - " // empty\n" + - "}\n" + - "final class Y extends X implements I, Y> {\n" + - " // empty\n" + - "}\n" - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -// array in super bound -public void test0905() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.List;\n" + - " \n" + - "class X {\n" + - " void foo(List p) {\n" + - " p.add(new Object[0]);\n" + - " }\n" + - "}"}, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -// raw types in casts -public void test0906() { - this.runNegativeTest( - new String[] { - "X.java", - "interface I {\n" + - " // empty\n" + - "} \n" + - "public class X implements I {\n" + - " I x1 = (I) (X) null;\n" + - " I x2 = (I) new X();\n" + - " I x3 = (I) null;\n" + - " X x4 = (X) (I) null;\n" + - "}"}, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " public class X implements I {\n" + - " ^\n" + - "I is a raw type. References to generic type I should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " I x1 = (I) (X) null;\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to I\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " I x1 = (I) (X) null;\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X to I\n" + - "----------\n" + - "4. WARNING in X.java (at line 5)\n" + - " I x1 = (I) (X) null;\n" + - " ^^^^^^^^\n" + - "Unnecessary cast from null to X\n" + - "----------\n" + - "5. WARNING in X.java (at line 6)\n" + - " I x2 = (I) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to I\n" + - "----------\n" + - "6. WARNING in X.java (at line 6)\n" + - " I x2 = (I) new X();\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from X to I\n" + - "----------\n" + - "7. WARNING in X.java (at line 7)\n" + - " I x3 = (I) null;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from null to I\n" + - "----------\n" + - "8. WARNING in X.java (at line 8)\n" + - " X x4 = (X) (I) null;\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from null to I\n" + - "----------\n"); -} - -// parametrized method with array extends Object upper bound verification -public void test0907() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Collection;\n" + - "import java.util.Collections;\n" + - "public class X, V> {\n" + - " public void foo() {\n" + - " Y o = (new Z()). bar(Collections\n" + - " .singleton(new Y()));\n" + - " o.toString();\n" + - " }\n" + - "}\n" + - "class Y extends X {\n" + - " // empty\n" + - "}\n" + - "class Z {\n" + - " public , W extends V> U bar(Collection c) {\n" + - " return null;\n" + - " }\n" + - "}\n"}, - ""); -} - -// check capture for conditional operator - variant -public void test0908() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public abstract class X {\n" + - " protected void foo(Class clazz) {\n" + - " Class l = clazz.isInterface() ? bar(clazz) : clazz;\n" + - " }\n" + - " abstract public Class bar(Class p);\n" + - "}"}, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126105 -public void test0909() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " private static class B {\n" + - " private Object x;\n" + - "\n" + - " public B(T x) {\n" + - " this.x = x;\n" + - " }\n" + - " }\n" + - "\n" + - " private static class C {\n" + - " private Object x;\n" + - "\n" + - " public C(Object x) {\n" + - " this.x = x;\n" + - " }\n" + - " }\n" + - "\n" + - " public static void main(String[] args) throws Throwable {\n" + - " B b = new B(\"foo\");\n" + - " System.out.println(b.x);\n" + - "\n" + - " C c = new C(\"foo\");\n" + - " System.out.println(c.x);\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 24)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 -public void test0910() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.Collection;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - "\n" + - " void bar() {\n" + - " List lc1 = null;\n" + - " List> lc2 = null;\n" + - " List> lc3 = null;\n" + - " List lc4 = null;\n" + - " lc1 = lc2; //1 ko\n" + - " lc1 = lc3; //2 ko\n" + - " lc1 = lc4; //3 ko\n" + - " lc2 = lc1; //4 ko\n" + - " lc2 = lc3; //5 ko\n" + - " lc2 = lc4; //6 ko\n" + - " lc3 = lc1; //7 ko\n" + - " lc3 = lc2; //8 ok\n" + - " lc3 = lc4; //9 ko\n" + - " lc4 = lc1; //10 ok\n" + - " lc4 = lc2; //11 ok\n" + - " lc4 = lc3; //12 ok\n" + - " }\n" + - " private final List aList = new ArrayList();\n" + - " public void foo() {\n" + - " final List> listCopy = new ArrayList>(this.aList); // ko\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " List lc1 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " List lc4 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 12)\n" + - " lc1 = lc2; //1 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " lc1 = lc3; //2 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 14)\n" + - " lc1 = lc4; //3 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "6. ERROR in X.java (at line 15)\n" + - " lc2 = lc1; //4 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "7. ERROR in X.java (at line 16)\n" + - " lc2 = lc3; //5 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n" + - "8. ERROR in X.java (at line 17)\n" + - " lc2 = lc4; //6 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "9. ERROR in X.java (at line 18)\n" + - " lc3 = lc1; //7 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "10. ERROR in X.java (at line 20)\n" + - " lc3 = lc4; //9 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "11. WARNING in X.java (at line 25)\n" + - " private final List aList = new ArrayList();\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "12. WARNING in X.java (at line 25)\n" + - " private final List aList = new ArrayList();\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "13. ERROR in X.java (at line 27)\n" + - " final List> listCopy = new ArrayList>(this.aList); // ko\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor ArrayList>(List) is undefined\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation -public void test0911() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.Collection;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void bar() {\n" + - " List lc1 = null;\n" + - " List> lc2 = null;\n" + - " List> lc3 = null;\n" + - " List lc4 = null;\n" + - " lc1 = lc2; //1 ko\n" + - " lc1 = lc3; //2 ko\n" + - " lc1 = lc4; //3 ko\n" + - " lc2 = lc1; //4 ko\n" + - " lc2 = lc3; //5 ko\n" + - " lc2 = lc4; //6 ko\n" + - " lc3 = lc1; //7 ok\n" + - " lc3 = lc2; //8 ok\n" + - " lc3 = lc4; //9 ok\n" + - " lc4 = lc1; //10 ok\n" + - " lc4 = lc2; //11 ko\n" + - " lc4 = lc3; //12 ko\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " List lc1 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " List lc4 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 11)\n" + - " lc1 = lc2; //1 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n" + - "4. ERROR in X.java (at line 12)\n" + - " lc1 = lc3; //2 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 13)\n" + - " lc1 = lc4; //3 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "6. ERROR in X.java (at line 14)\n" + - " lc2 = lc1; //4 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "7. ERROR in X.java (at line 15)\n" + - " lc2 = lc3; //5 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n" + - "8. ERROR in X.java (at line 16)\n" + - " lc2 = lc4; //6 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "9. ERROR in X.java (at line 21)\n" + - " lc4 = lc2; //11 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n" + - "10. ERROR in X.java (at line 22)\n" + - " lc4 = lc3; //12 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation -public void test0912() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " void foo(List[]> l1, List l2) {\n" + - " l1 = l2;\n" + - " l2 = l1;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " void foo(List[]> l1, List l2) {\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " l1 = l2;\n" + - " ^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " l2 = l1;\n" + - " ^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation -public void test0913() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void bar() {\n" + - " List lc1 = null;\n" + - " List[]> lc2 = null;\n" + - " List[]> lc3 = null;\n" + - " List lc4 = null;\n" + - " lc1 = lc2; //1 ko\n" + - " lc1 = lc3; //2 ko\n" + - " lc1 = lc4; //3 ko\n" + - " lc2 = lc1; //4 ko\n" + - " lc2 = lc3; //5 ko\n" + - " lc2 = lc4; //6 ko\n" + - " lc3 = lc1; //7 ko\n" + - " lc3 = lc2; //8 ok\n" + - " lc3 = lc4; //9 ko\n" + - " lc4 = lc1; //10 ok\n" + - " lc4 = lc2; //11 ok\n" + - " lc4 = lc3; //12 ok \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List lc1 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " List lc4 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " lc1 = lc2; //1 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " lc1 = lc3; //2 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 10)\n" + - " lc1 = lc4; //3 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "6. ERROR in X.java (at line 11)\n" + - " lc2 = lc1; //4 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n" + - "7. ERROR in X.java (at line 12)\n" + - " lc2 = lc3; //5 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List[]>\n" + - "----------\n" + - "8. ERROR in X.java (at line 13)\n" + - " lc2 = lc4; //6 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n" + - "9. ERROR in X.java (at line 14)\n" + - " lc3 = lc1; //7 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n" + - "10. ERROR in X.java (at line 16)\n" + - " lc3 = lc4; //9 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation -public void test0914() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void bar() {\n" + - " List lc1 = null;\n" + - " List[]> lc2 = null;\n" + - " List[]> lc3 = null;\n" + - " List lc4 = null;\n" + - " lc1 = lc2; //1 ko\n" + - " lc1 = lc3; //2 ko\n" + - " lc1 = lc4; //3 ko\n" + - " lc2 = lc1; //4 ko\n" + - " lc2 = lc3; //5 ko\n" + - " lc2 = lc4; //6 ko\n" + - " lc3 = lc1; //7 ok\n" + - " lc3 = lc2; //8 ok\n" + - " lc3 = lc4; //9 ok\n" + - " lc4 = lc1; //10 ok\n" + - " lc4 = lc2; //11 ko\n" + - " lc4 = lc3; //12 ko \n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List lc1 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " List lc4 = null;\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " lc1 = lc2; //1 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " lc1 = lc3; //2 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 10)\n" + - " lc1 = lc4; //3 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "6. ERROR in X.java (at line 11)\n" + - " lc2 = lc1; //4 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n" + - "7. ERROR in X.java (at line 12)\n" + - " lc2 = lc3; //5 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List[]>\n" + - "----------\n" + - "8. ERROR in X.java (at line 13)\n" + - " lc2 = lc4; //6 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List[]>\n" + - "----------\n" + - "9. ERROR in X.java (at line 18)\n" + - " lc4 = lc2; //11 ko\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n" + - "10. ERROR in X.java (at line 19)\n" + - " lc4 = lc3; //12 ko \n" + - " ^^^\n" + - "Type mismatch: cannot convert from List[]> to List\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128389 -public void test0915() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class Y1 extends Throwable {\n" + - " private static final long serialVersionUID = 1L;\n" + - " T t;\n" + - " }\n" + - " static class Y2 extends Throwable {\n" + - " private static final long serialVersionUID = 1L;\n" + - " }\n" + - " class Y3 extends Throwable {\n" + - " private static final long serialVersionUID = 1L;\n" + - "\n" + - " T t;\n" + - " }\n" + - "}\n" + - "class Y4 extends Throwable {}\n" + - "\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " class Y1 extends Throwable {\n" + - " ^^^^^^^^^\n" + - "The generic class X.Y1 may not subclass java.lang.Throwable\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " class Y3 extends Throwable {\n" + - " ^^^^^^^^^\n" + - "The generic class X.Y3 may not subclass java.lang.Throwable\n" + - "----------\n" + - "3. WARNING in X.java (at line 15)\n" + - " class Y4 extends Throwable {}\n" + - " ^^\n" + - "The serializable class Y4 does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "4. ERROR in X.java (at line 15)\n" + - " class Y4 extends Throwable {}\n" + - " ^^^^^^^^^\n" + - "The generic class Y4 may not subclass java.lang.Throwable\n" + - "----------\n"); -} - -// synchronized inheritance for multiple generic types -public void test0916() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X> {\n" + - " T m2;\n" + - " T getX2() {\n" + - " return this.m2;\n" + - " }\n" + - "}\n" + - "class X2 {\n" + - " T m3;\n" + - " T getX3() {\n" + - " return this.m3;\n" + - " }\n" + - "}\n" + - "class X3 {\n" + - "}\n" + - "class Y1> extends X {\n" + - " public void foo() {\n" + - " getX2().getX3().bar(); // getX3 appropriately returns an Y3\n" + - " }\n" + - "}\n" + - "class Y2 extends X2 {\n" + - "}\n" + - "class Y3 extends X3 {\n" + - " public void bar() {\n" + - " }\n" + - "}\n"}, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 -// [1.5][compiler] ClassCastException on illegal code fragment -public void test0917() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends X2 { }\n" + - "class X2 { }\n" + - "class A { static class M {} }" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends X2 { }\n" + - " ^^^\n" + - "Illegal qualified access from the type parameter T\n" + - "----------\n" - // cannot select from a type variable - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation -public void test0917a() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends X2 { }\n" + - "class X2 { }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends X2 { }\n" + - " ^^^^^^^\n" + - "Illegal qualified access from the type parameter T\n" + - "----------\n" - // cannot select from a type variable - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation -public void test0917b() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { Class c = T.class; }" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X { Class c = T.class; }\n" + - " ^^^^^^^\n" + - "Illegal class literal for the type parameter T\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation -public void test0917c() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends X2 { }\n" + - "class X2 { }\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends X2 { }\n" + - " ^^^^^\n" + - "Syntax error on token \"class\", Identifier expected\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128560 -public void test0918() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "BasicNode.java", - "class BasicEdge & Node, E extends BasicEdge & Edge>\n" + - " implements Edge {\n" + - "}\n" + - "\n" + - "public class BasicNode & Edge, N extends BasicNode & Node>\n" + - " implements Node {\n" + - "}\n" + - "\n" + - "interface Edge>> {\n" + - "}\n" + - "\n" + - "interface Node>> {\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -public void test0919() { - this.runConformTest( - new String[] { - "X.java", - "class Box {\n" + - " private E element;\n" + - " void put(E elem) {\n" + - " this.element = elem;\n" + - " }\n" + - " E get() {\n" + - " return this.element;\n" + - " }\n" + - " Pair asPair() {\n" + - " return new Pair(this.element, this.element);\n" + - " }\n" + - " Box> nest() {\n" + - " Box> wrapper = new Box>();\n" + - " wrapper.put(this);\n" + - " return wrapper;\n" + - " }\n" + - "}\n" + - "\n" + - "class Pair {\n" + - " Pair(U u, V v) {\n" + - " }\n" + - "}\n" + - "\n" + - "class PandoraBox> extends Box {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " void test(PandoraBox pbox) {\n" + - " Box box = pbox.get();\n" + - " Pair pair = pbox.asPair();\n" + - " Box nbox = pbox.nest();\n" + - " }\n" + - "}\n", - }, - ""); -} -public void test0920() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "class Stack {\n" + - " private List contents = new ArrayList();\n" + - " void push(E e) {\n" + - " this.contents.add(e);\n" + - " }\n" + - " E pop() {\n" + - " int last = this.contents.size() - 1;\n" + - " if (last < 0) throw new EmptyStackException();\n" + - " return this.contents.remove(last);\n" + - " }\n" + - " private static void doSwap(Stack s) {\n" + - " T t1 = s.pop();\n" + - " T t2 = s.pop();\n" + - " s.push(t1);\n" + - " s.push(t2);\n" + - " }\n" + - " static void swap(Stack s) { doSwap(s); }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Stack si = new Stack();\n" + - " Integer[] ints = { 12, 13, 14, 15, };\n" + - " for (Integer i : ints) si.push(i);\n" + - " try {\n" + - " while(true) {\n" + - " System.out.print(\"[\"+si.pop()+\"]\");\n" + - " }\n" + - " } catch(EmptyStackException e) {\n" + - " System.out.println(\"[done]\");\n" + - " }\n" + - " }\n" + - "}\n", - }, - "[15][14][13][12][done]"); -} -public void test0921() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "Graph.java", - "class Node, E extends Edge> {\n" + - "}\n" + - "class Edge, E extends Edge> {\n" + - "}\n" + - "class Graph, E extends Edge>{\n" + - " N n;\n" + - " E e;\n" + - " private Graph(N n, E e) {\n" + - " this.n = n;\n" + - " this.e = e;\n" + - " }\n" + - " static , E extends Edge>\n" + - " Graph copy(Graph g) {\n" + - " return create(g.n,g.e);\n" + - " }\n" + - " static , E extends Edge>\n" + - " Graph create(N n, E e) {\n" + - " return new Graph(n,e);\n" + - " }\n" + - " Graph builder() {\n" + - " Graph g = null;\n" + - " return copy(g);\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -// Test case which comes from JDT/UI tests TypeEnvironmentTest.testWildcardAssignements -public void test0922() { - this.runNegativeTest( - new String[] { - "Test.java", - "import java.util.*;\n" + - "public class Test {\n" + - " List list_raw_list;\n" + - " {\n" + - " Collection> col = list_raw_list;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in Test.java (at line 3)\n" + - " List list_raw_list;\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in Test.java (at line 5)\n" + - " Collection> col = list_raw_list;\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to Collection>\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129129 -public void test0923() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " static void a(Class> c) {}\n" + - "\n" + - " static void b(X t) {\n" + - " X.a(t.getClass());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " X.a(t.getClass());\n" + - " ^\n" + - "The method a(Class>) in the type X is not applicable for the arguments (Class)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 -public void test0924() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "ExtendedOuter.java", - "class Outer {\n" + - " class Inner {\n" + - " }\n" + - "\n" + - " static void method(Outer.Inner x) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n" + - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new ExtendedOuter().new ExtendedInner();\n" + - " }\n" + - "}\n" - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test0925() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " private List toAdd;\n" + - "\n" + - " public X(List toAdd) {\n" + - " this.toAdd = toAdd;\n" + - " }\n" + - "\n" + - " private List getRelated(B b) {\n" + - " // some application logic\n" + - " // for demo\n" + - " return toAdd;\n" + - " }\n" + - "\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " public , LF extends Factory> L addOrCreate4(\n" + - " B b, L l, LF lf) {\n" + - " if (l == null) {\n" + - " l = lf.create();\n" + - " }\n" + - " ((List) l).addAll(getRelated(b)); \n" + - " l.addAll(getRelated(b));\n" + - " return l;\n" + - " }\n" + - "\n" + - " public static class ListFactory implements Factory> {\n" + - " public List create() {\n" + - " return new ArrayList();\n" + - " }\n" + - " }\n" + - "\n" + - " public static interface Factory {\n" + - " public T create();\n" + - " }\n" + - "\n" + - " public static void main(String... args) {\n" + - " ListFactory lf = new ListFactory();\n" + - " List longs = new ArrayList();\n" + - " longs.add(new Long(1));\n" + - " X test = new X(longs);\n" + - " List ret4 = null;\n" + - " ret4 = test.addOrCreate4(1, ret4, lf);\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 -public void test0926() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - "\n" + - " public void foo() {\n" + - " NonTerminalSourcePart> RESULT = null;\n" + - " NonTerminalSourcePart> t = null;\n" + - " RESULT = NonTerminalSourcePart.create(Tuple.create(true, t.value().fst()));\n" + - " }\n" + - "}\n" + - "\n" + - "class Term {\n" + - "}\n" + - "\n" + - "class Formula {\n" + - "}\n" + - "\n" + - "final class NonTerminalSourcePart {\n" + - " static NonTerminalSourcePart create(final V _value) {\n" + - " return null;\n" + - " }\n" + - " final V value() {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "class Tuple {\n" + - " public static Tuple create(final A a, final B b) {\n" + - " return null;\n" + - " }\n" + - " public A fst() {\n" + - " return null;\n" + - " }\n" + - "}\n" - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 6)\n" + - " RESULT = NonTerminalSourcePart.create(Tuple.create(true, t.value().fst()));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from NonTerminalSourcePart> to NonTerminalSourcePart>\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBug6557661 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0927() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public void foo() {\n" + - " List> RESULT = null;\n" + - " List lst = null;\n" + - " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + - " }\n" + - " public void bar() {\n" + - " List> RESULT = null;\n" + - " List lst = null;\n" + - " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + - " }\n" + - " public void baz() {\n" + - " List> RESULT = null;\n" + - " List lst = null;\n" + - " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + - " }\n" + - " public void bar2(List lst) {\n" + - " List RESULT = null;\n" + - " RESULT = lst;\n" + - " RESULT = Collections.singletonList(lst.get(0));\n" + - " } \n" + - " public static void main(String[] args) {\n" + - " List ls = new ArrayList();\n" + - " ls.add(\"str\");\n" + - " new X().bar2(ls);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n" + - "3. ERROR in X.java (at line 16)\n" + - " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n" + - "4. ERROR in X.java (at line 20)\n" + - " RESULT = lst;\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 21)\n" + - " RESULT = Collections.singletonList(lst.get(0));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0928() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) throws Throwable {\n" + - " List x1 = new ArrayList();\n" + - " List x2 = new ArrayList();\n" + - " x1.addAll(x2);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " x1.addAll(x2);\n" + - " ^^^^^^\n" + - "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117119 -public void test0929() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Collection;\n" + - "\n" + - "public class X {\n" + - " \n" + - " public static > void fails () {\n" + - " Class enumType = null;\n" + - " final Collection test = allOf(enumType);\n" + - "\n" + - " Collection colType = null;\n" + - " final Collection test2 = colType;\n" + - " }\n" + - " \n" + - " public static > Collection allOf(final Class enumType) {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " Class enumType = null;\n" + - " ^^^^\n" + - "Enum is a raw type. References to generic type Enum should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " final Collection test = allOf(enumType);\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " final Collection test = allOf(enumType);\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Collection to Collection\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " Collection colType = null;\n" + - " ^^^^\n" + - "Enum is a raw type. References to generic type Enum should be parameterized\n" + - "----------\n" + - "5. ERROR in X.java (at line 10)\n" + - " final Collection test2 = colType;\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from Collection to Collection\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 -public void test0930() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static int I;\n" + - " public void foo() {\n" + - " X.I= 10;\n" + - " }\n" + - " { Zork z; }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " { Zork z; }\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 - variation -public void test0931() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static int I;\n" + - " public void foo() {\n" + - " X.I= 10;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X.I= 10;\n" + - " ^\n" + - "Syntax error on token \"I\", VariableDeclaratorId expected after this token\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 - variation -public void test0932() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static int Method() { return 0; }\n" + - " public void foo() {\n" + - " X.Method();\n" + - " }\n" + - " public void bar() {\n" + - " X.Method();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " X.Method();\n" + - " ^^^^^^^^^^\n" + - "Syntax error on token(s), misplaced construct(s)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 -public void test0933() { - this.runNegativeTest( - new String[] { - "a/AbstractFoo.java", //================================ - "package a;\n" + - "public abstract class AbstractFoo> {\n" + - " protected static class Inner> {\n" + - " public Inner() {\n" + - " }\n" + - "\n" + - " public final void doSmth() {\n" + - " }\n" + - " }\n" + - "}\n", - "b/CustomFoo.java", //================================ - "package b;\n" + - "import a.AbstractFoo;\n" + - "public final class CustomFoo extends AbstractFoo {\n" + - " private Inner defaultInner;\n" + - "\n" + - " Inner getDefaultInner() {\n" + - " return (this.defaultInner == null)\n" + - " ? this.defaultInner = new Inner()\n" + - " : this.defaultInner;\n" + - " } \n" + - "\n" + - " private Inner customInner;\n" + - "\n" + - " Inner getCustomInner() {\n" + - " return (this.customInner == null)\n" + - " ? this.customInner = new Inner()\n" + - " : this.customInner;\n" + - " } \n" + - "}\n", - "b/DefaultFoo.java", //================================ - "package b;\n" + - "import a.AbstractFoo;\n" + - "public final class DefaultFoo extends AbstractFoo {\n" + - " private Inner defaultInner;\n" + - "\n" + - " Inner getDefaultInner() {\n" + - " return (this.defaultInner == null)\n" + - " ? this.defaultInner = new Inner()\n" + - " : this.defaultInner;\n" + - " } \n" + - "\n" + - " private Inner customInner;\n" + - "\n" + - " Inner getCustomInner() {\n" + - " return (this.customInner == null)\n" + - " ? this.customInner = new Inner()\n" + - " : this.customInner;\n" + - " }\n" + - "\n" + - " ///////////////////////////////////////////////////////////////////////\n" + - " public void testCompilationFailure(final CustomFoo foo) {\n" + - " final DefaultFoo foo1 = this;\n" + - " final CustomFoo foo2 = foo;\n" + - "\n" + - " // These get compiled w/o error:\n" + - " foo1.getCustomInner().doSmth();\n" + - " foo1.getDefaultInner().doSmth();\n" + - "\n" + - " // These do not (Eclipse 3.2.0 M4):\n" + - " foo2.getCustomInner().doSmth();\n" + - " foo2.getDefaultInner().doSmth();\n" + - "\n" + - " // Expect error\n" + - " String s11 = foo1.getCustomInner();\n" + - " String s12 = foo2.getDefaultInner();\n" + - " String s21 = foo2.getCustomInner();\n" + - " String s22 = foo2.getDefaultInner();\n" + - "\n" + - " // However, if we split statements, everything\'s ok: \n" + - " final Inner customInner2 = foo2.getCustomInner();\n" + - " customInner2.doSmth();\n" + - "\n" + - " final Inner defaultInner2 = foo2.getDefaultInner();\n" + - " defaultInner2.doSmth();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in b\\DefaultFoo.java (at line 34)\n" + - " String s11 = foo1.getCustomInner();\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + - "----------\n" + - "2. ERROR in b\\DefaultFoo.java (at line 35)\n" + - " String s12 = foo2.getDefaultInner();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + - "----------\n" + - "3. ERROR in b\\DefaultFoo.java (at line 36)\n" + - " String s21 = foo2.getCustomInner();\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + - "----------\n" + - "4. ERROR in b\\DefaultFoo.java (at line 37)\n" + - " String s22 = foo2.getDefaultInner();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation -public void test0934() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " static class Inner {\n" + - " static class InInner {\n" + - " }\n" + - " }\n" + - "}\n" + - "class Y extends X {\n" + - " void foo() {\n" + - " Inner inner = null;\n" + - " String s = inner;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " String s = inner;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from X.Inner to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation -public void test0935() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " static class Inner {\n" + - " class InInner {\n" + - " }\n" + - " }\n" + - "}\n" + - "class Y extends X {\n" + - " void foo() {\n" + - " Inner.InInner inner = null;\n" + - " String s = inner;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " String s = inner;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from X.Inner.InInner to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation -public void test0936() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " class Inner {\n" + - " class InInner {\n" + - " }\n" + - " }\n" + - "}\n" + - "class Y extends X {\n" + - " void foo() {\n" + - " Inner inner = null;\n" + - " String s = inner;\n" + - " \n" + - " Inner.InInner inner2 = null;\n" + - " s = inner2;\n" + - "\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " String s = inner;\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from X.Inner to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 13)\n" + - " s = inner2;\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from X.Inner.InInner to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation -public void test0937() { - this.runNegativeTest( - new String[] { - "ExtendedOuter.java", //================================ - "class Outer {\n" + - " class Inner {}\n" + - "\n" + - " static void method(Outer.Inner x) {}\n" + - "}\n" + - "\n" + - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - " void foo() {\n" + - " Zork zk;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in ExtendedOuter.java (at line 4)\n" + - " static void method(Outer.Inner x) {}\n" + - " ^^^^^^^^^^^\n" + - "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + - "----------\n" + - "2. ERROR in ExtendedOuter.java (at line 14)\n" + - " Zork zk;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation -public void test0938() { - this.runNegativeTest( - new String[] { - "ExtendedOuter.java", //================================ - "class Outer {\n" + - " class Inner {}\n" + - "\n" + - " static void method(Outer.Inner x) {}\n" + - "}\n" + - "\n" + - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - " void foo() {\n" + - " Zork zk;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in ExtendedOuter.java (at line 14)\n" + - " Zork zk;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation -public void test0939() { - this.runNegativeTest( - new String[] { - "ExtendedOuter.java", //================================ - "class Outer {\n" + - " class Inner {}\n" + - "\n" + - " static void method(Outer.Inner x) {}\n" + - "}\n" + - "\n" + - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - " void foo() {\n" + - " Zork zk;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in ExtendedOuter.java (at line 14)\n" + - " Zork zk;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0940() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "public class X {\n" + - " void bar3(List lst) {\n" + - " List RESULT = null;\n" + - " RESULT = lst; // 1\n" + - " RESULT = Collections.singletonList(lst.get(0)); // 2\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " RESULT = lst; // 1\n" + - " ^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " RESULT = Collections.singletonList(lst.get(0)); // 2\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0941() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Map foo(T t1, T t2) {\n" + - " return null;\n" + - " }\n" + - " void bar(U u, V v) {\n" + - " Map map1 = foo(u, v);\n" + - " Map map2 = foo(u, v);\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " Map map1 = foo(u, v);\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from Map to Map\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0942() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Map foo(T t1, T t2, T t3) {\n" + - " return null;\n" + - " }\n" + - " void bar(U u, V v) {\n" + - " Map map1 = foo(u, v, null);\n" + - " Map map2 = foo(u, v, null);\n" + - " } \n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " Map map1 = foo(u, v, null);\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Map to Map\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0943() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Map foo(T t1, T t2, T t3) {\n" + - " return null;\n" + - " }\n" + - " void bar(U u, V v, List lv) {\n" + - " Map map1 = foo(u, v, lv.get(0));\n" + - " Map map2 = foo(u, v, lv.get(0));\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " Map map1 = foo(u, v, lv.get(0));\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Map to Map\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129996 -public void test0944() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "public class X {\n" + - " public static Set method(List list) {\n" + - " return new HashSet();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " ArrayList l = new ArrayList();\n" + - " Set s1 = method(l);\n" + - " Set s2 = (Set) method(l);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Set s2 = (Set) method(l);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Set to Set\n" + - "----------\n"); -} -public void test0945() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args){\n" + - " Object[] objArray = {new Object()};\n" + - " ArrayList strList = new ArrayList();\n" + - " transferBug(objArray, strList);\n" + - " String str = strList.get(0);\n" + - "}\n" + - "public static void transferBug(Var[] src, Collection dest){\n" + - " dest.add(src[0]);\n" + - "}\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " transferBug(objArray, strList);\n" + - " ^^^^^^^^^^^\n" + - "The method transferBug(Var[], Collection) in the type X is not applicable for the arguments (Object[], ArrayList)\n" + - "----------\n"); -} -public void test0946() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", //================================ - "public class X {\n" + - " public static void main(String[] args) {\n" + - " operate(Operations.create());\n" + - " }\n" + - " static > void operate(Operators operators) {\n" + - " System.out.println(operators.spawn());\n" + - " }\n" + - "}\n" + - "class Operations {\n" + - " static Operators create() {\n" + - " return new IntOperators();\n" + - " }\n" + - "}\n" + - "interface Num {\n" + - " public O spawn();\n" + - "}\n" + - "class Int implements Num {\n" + - " public Int spawn() {\n" + - " return new Int();\n" + - " }\n" + - " public String toString() {\n" + - " return \"Int\";\n" + - " }\n" + - "}\n" + - "interface Operators> {\n" + - " O spawn();\n" + - "}\n" + - "class IntOperators implements Operators {\n" + - " public Int spawn() {\n" + - " return new Int();\n" + - " }\n" + - "}\n", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "Int" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0947() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "public class X {\n" + - " public void bar2(Box b) {\n" + - " Box bx = box(b.element);\n" + - " box(b.element).element.run();\n" + - " }\n" + - " static Box box(U u) {\n" + - " return new Box(u);\n" + - " }\n" + - "}\n" + - "class Box {\n" + - " E element;\n" + - " Box(E element) {\n" + - " this.element = element;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Box bx = box(b.element);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Box to Box\n" + - "----------\n", - JavacTestOptions.EclipseHasABug.EclipseBug236236); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation -public void test0948() { - this.runConformTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "public class X {\n" + - " public void bar2(Box b1, Box b2) {\n" + - " Pair blist = pair(b1.element, b2.element);\n" + - " }\n" + - " static Pair pair(U u1, U u2) {\n" + - " return new Pair(u1,u2);\n" + - " }\n" + - "}\n" + - "class Pair {\n" + - " Pair(E e, F f){}\n" + - "}\n" + - "class Box {\n" + - " E element;\n" + - " Box(E element) {\n" + - " this.element = element;\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 -public void test0949() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.Arrays;\n" + - "\n" + - "public class X {\n" + - " public Iterable m(T... ts) {\n" + - " return Arrays.asList(ts);\n" + - " }\n" + - " public void m3(Iterable... ts) {\n" + - " }\n" + - " public void m2() {\n" + - " m3(m(3, 3, 3));\n" + - " m3(m());\n" + - " m3(m(new Object[]{}));\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " m3(m(3, 3, 3));\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " m3(m());\n" + - " ^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " m3(m(new Object[]{}));\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation -public void test0950() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.Arrays;\n" + - "\n" + - "public class X {\n" + - " public Iterable m(T[]... ts) {\n" + - " return Arrays.asList(ts[0]);\n" + - " }\n" + - " public void m3(Iterable... ts) {\n" + - " }\n" + - " public void m2() {\n" + - " m3(m(new Integer[]{3, 3, 3}));\n" + - " m3(m());\n" + - " m3(m(new Object[][]{}));\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " m3(m(new Integer[]{3, 3, 3}));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " m3(m());\n" + - " ^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " m3(m(new Object[][]{}));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation -public void test0951() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.Arrays;\n" + - "\n" + - "public class X {\n" + - " public Iterable m(T[]... ts) {\n" + - " return Arrays.asList(ts[0]);\n" + - " }\n" + - " public void m3(Iterable... ts) {\n" + - " }\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " public void m2() {\n" + - " m3(m(new Integer[]{3, 3, 3}));\n" + - " m3(m());\n" + - " m3(m(new Object[][]{}));\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation -public void test0952() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " public Iterable m(T... ts) {\n" + - " return null;\n" + - " }\n" + - " public void m3(Iterable... ts) {\n" + - " }\n" + - " public void m2() {\n" + - " m3(m(null));\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " m3(m(null));\n" + - " ^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " m3(m(null));\n" + - " ^^^^^^^\n" + - "The argument of type null should explicitly be cast to Object[] for the invocation of the varargs method m(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106325 -public void test0953() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.lang.ref.WeakReference;\n" + - "import java.util.Arrays;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void m(WeakReference ref) {\n" + - " List> list= Arrays.asList(ref);\n" + - " Zork z;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " List> list= Arrays.asList(ref);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of WeakReference is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130543 -public void test0954() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " class Member {}\n" + - " static class SMember {}\n" + - " void foo1() {\n" + - " X[] xs = new X[]{};//1\n" + - " for(X x : xs) {\n" + - " System.out.println(x);\n" + - " }\n" + - " }\n" + - " void bar1() {\n" + - " Member[] members = new Member[]{};//2\n" + - " for(Member m : members) {\n" + - " System.out.println(m);\n" + - " }\n" + - " }\n" + - " void bas1() {\n" + - " SMember[] members = new SMember[]{};//3\n" + - " for(SMember m : members) {\n" + - " System.out.println(m);\n" + - " }\n" + - " }\n" + - " void baz1() {\n" + - " class Local{}\n" + - " Local[] locals = new Local[]{};//4\n" + - " for(Local l : locals) {\n" + - " System.out.println(l);\n" + - " }\n" + - " }\n" + - " void foo2() {\n" + - " X[] xs = new X[5];//5\n" + - " for(X x : xs) {\n" + - " System.out.println(x);\n" + - " }\n" + - " }\n" + - " void bar2() {\n" + - " Member[] members = new Member[5];//6\n" + - " for(Member m : members) {\n" + - " System.out.println(m);\n" + - " }\n" + - " }\n" + - " void bas2() {\n" + - " SMember[] members = new SMember[5];//7\n" + - " for(SMember m : members) {\n" + - " System.out.println(m);\n" + - " }\n" + - " }\n" + - " void baz2() {\n" + - " class Local{}\n" + - " Local[] locals = new Local[5];//8\n" + - " for(Local l : locals) {\n" + - " System.out.println(l);\n" + - " }\n" + - " }\n" + - " void foo3() {\n" + - " X[] xs = new X[5];//9\n" + - " for(X x : xs) {\n" + - " System.out.println(x);\n" + - " }\n" + - " }\n" + - " void bar3() {\n" + - " X.Member[] members = new X.Member[5];//10\n" + - " for(X.Member m : members) {\n" + - " System.out.println(m);\n" + - " }\n" + - " }\n" + - " static void baz3() {\n" + - " class Local{}\n" + - " Local[] locals = new Local[5];//11\n" + - " for(Local l : locals) {\n" + - " System.out.println(l);\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " Member[] members = new Member[]{};//2\n" + - " ^^\n" + - "Cannot create a generic array of X.Member\n" + - "----------\n" + - "2. ERROR in X.java (at line 26)\n" + - " Local[] locals = new Local[]{};//4\n" + - " ^^\n" + - "Cannot create a generic array of Local\n" + - "----------\n" + - "3. ERROR in X.java (at line 38)\n" + - " Member[] members = new Member[5];//6\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of X.Member\n" + - "----------\n" + - "4. ERROR in X.java (at line 51)\n" + - " Local[] locals = new Local[5];//8\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of Local\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105049 -public void test0955() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.List;\n" + - "public class X {\n" + - " void method(Object o) {\n" + - " if (o instanceof List[]) { //incorrect: bug 104695\n" + - " List[] es= (List[]) o; //unchecked\n" + - " }\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o instanceof List[]) { //incorrect: bug 104695\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " List[] es= (List[]) o; //unchecked\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List[]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130128 -public void test0956() { - this.runConformTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - "\n" + - " public void printNickname(Person person) {\n" + - " Person.Nickname nickname = person.getNickname();\n" + - " System.out.println(nickname);\n" + - " }\n" + - "\n" + - " static class Person {\n" + - " private Nickname nickname;\n" + - "\n" + - " public Nickname getNickname() {\n" + - " return nickname;\n" + - " }\n" + - "\n" + - " public void setNickname(Nickname nickname) {\n" + - " this.nickname = nickname;\n" + - " }\n" + - "\n" + - " class Nickname {\n" + - " private String name;\n" + - " private boolean insulting;\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=132348 -public void test0957() { - this.runNegativeTest( - new String[] { - "AnyInterface.java", //================================ - "public interface AnyInterface {\n" + - " public void doSomething();\n" + - "}", - "UsingGenericsClass", - "public class UsingGenericsClass {\n" + - " public UsingGenericsClass(){\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in UsingGenericsClass (at line 1)\n" + - " public class UsingGenericsClass {\n" + - " ^^^^^^^^^^^^\n" + - "Cannot specify any additional bound AnyInterface when first bound is a type parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=131935 -public void test0958() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.lang.ref.ReferenceQueue;\n" + - "import java.lang.ref.SoftReference;\n" + - "import java.util.Hashtable;\n" + - "\n" + - "public class X {\n" + - " private static final Hashtable cache = new Hashtable();\n" + - "\n" + - " private static final ReferenceQueue trash = new ReferenceQueue();\n" + - "\n" + - " private static final class Soft extends SoftReference {\n" + - " int key;\n" + - "\n" + - " Soft() {\n" + - " super(null);\n" + - " }\n" + - " }\n" + - "\n" + - " final Thread clean = new Thread(\"BigTableModel cleaner\") {\n" + - " @Override\n" + - " public void run() {\n" + - " for (;;)\n" + - " try {\n" + - " cache.remove(((Soft) trash.remove()).key);\n" + - " } catch (final InterruptedException e) {\n" + - " return;\n" + - " }\n" + - " Zork z;\n" + - " }\n" + - " };\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 27)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133803 -public void test0959() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.lang.ref.*;\n" + - "\n" + - "class Soft extends SoftReference {\n" + - " Soft() { super(null); }\n" + - "}\n" + - "\n" + - "class Bug {\n" + - " void m(Reference remove) {\n" + - " Soft soft= (Soft) remove;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Soft soft= (Soft) remove;\n" + - " ^^^^^^^^^^^^^\n" + - "Cannot cast from Reference to Soft\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273 -public void test0960() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " > X newInstance() {\n" + - " return new X();\n" + - " }\n" + - "\n" + - " X[] bugDemo() {\n" + - " X x = newInstance();\n" + - " return new X[] { x };\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " X x = newInstance();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " return new X[] { x };\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X[] needs unchecked conversion to conform to X[]\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273 - variation -public void test0961() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " > B newInstance2(X xb) {\n" + - " return null;\n" + - " }\n" + - " void foo() {\n" + - " X x = new X();\n" + - " Comparable c = newInstance2(x);\n" + - " }\n" + - " Zork z;\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 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 should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 7)\n" + - " Comparable c = newInstance2(x);\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " Comparable c = newInstance2(x);\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation newInstance2(X) of the generic method newInstance2(X) of type X\n" + - "----------\n" + - "5. WARNING in X.java (at line 7)\n" + - " Comparable c = newInstance2(x);\n" + - " ^\n" + - "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + - "----------\n" + - "6. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 -public void test0962() { - runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " public void bug() throws Exception {\n" + - " throw new Exception(\"Bug134645\") {\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"Bug134645\";\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n" - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 3)\n" + - " throw new Exception(\"Bug134645\") {\n" + - " ^^^^^^^^^\n" + - "The generic class new Exception(){} may not subclass java.lang.Throwable\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " throw new Exception(\"Bug134645\") {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "The serializable class does not declare a static final serialVersionUID field of type long\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 - variation -public void test0963() { - this.runConformTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " public void bug() throws Exception {\n" + - " throw new Exception(\"Bug134645\") {\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"Bug134645\";\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 - variation -public void test0964() { - this.runConformTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " public static void bug() throws Exception {\n" + - " throw new Exception(\"Bug134645\") {\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"Bug134645\";\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97494 -public void test0965() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public class X {\n" + - " protected static final Class> theClass = (Class>) X.class;\n" + - " void foo(Class cx) {\n" + - " Class> cx1 = cx;\n" + - " Class> cx2 = (Class>) cx;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " protected static final Class> theClass = (Class>) X.class;\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Class to Class>\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " void foo(Class cx) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " Class> cx1 = cx;\n" + - " ^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " Class> cx2 = (Class>) cx;\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Class to Class>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115918 -public void test0966() { - this.runConformTest( - new String[] { - "Child.java", //================================ - "public class Child extends Parent implements Comparable {\n" + - " public int compareTo(Child o) { return 0; }\n" + - "}\n" + - "class Parent extends Base {}\n" + - "class Base {}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=81949 -public void test0967() { - this.runConformTest( - new String[] { - "CSS.java", //================================ - "interface Ac,A extends Ac> {}\n" + - "interface St,A extends Ac> {}\n" + - "class CSN extends CSS implements Ac, CSN> {}\n" + - "public class CSS implements St, CSN> {}\n" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108045 -public void test0968() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.*;\n" + - "public class X extends ArrayList implements I {\n" + - "}\n" + - "interface I extends Collection {\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public class X extends ArrayList implements I {\n" + - " ^\n" + - "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " public class X extends ArrayList implements I {\n" + - " ^\n" + - "The serializable class X does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " interface I extends Collection {\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133071 -public void test0969() { - this.runConformTest( - new String[] { - "B.java", //================================ - "class B extends A {}\n" + - "class C extends B {}\n" + - "class A {}" - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=136946 -public void test0970() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public interface X { \n" + - " interface I1 extends X {\n" + - " interface I2 extends I1 {\n" + - " }\n" + - "\n" + - " interface I3 extends I1 {\n" + - " }\n" + - "\n" + - " interface I4 extends I1.I2, I1.I3 { \n" + - " }\n" + - " }\n" + - "}\n" + - "class XSub implements X {\n" + - " I1 i1 = null;\n" + - " I1.I2 i2 = null;\n" + - " I1.I2 i1i2 = null;\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " I1.I2 i1i2 = null;\n" + - " ^^^^^^^^\n" + - "The member type X.I1.I2 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.I1\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=136946 - variation -public void test0971() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "public interface X { \n" + - " interface I1 extends X {\n" + - " interface I2 extends I1 {\n" + - " }\n" + - "\n" + - " interface I3 extends I1 {\n" + - " }\n" + - "\n" + - " interface I4 extends I1.I2, I1.I3 { \n" + - " }\n" + - " }\n" + - "}\n" + - "class XSub implements X {\n" + - " I1 i1 = null;\n" + - " I1.I2 i2 = null;\n" + - " I1.I2 i1i2 = null;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " interface I1 extends X {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " interface I2 extends I1 {\n" + - " ^^\n" + - "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " interface I3 extends I1 {\n" + - " ^^\n" + - "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " interface I4 extends I1.I2, I1.I3 { \n" + - " ^^^^^\n" + - "X.I1.I2 is a raw type. References to generic type X.I1.I2 should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 9)\n" + - " interface I4 extends I1.I2, I1.I3 { \n" + - " ^^^^^\n" + - "X.I1.I3 is a raw type. References to generic type X.I1.I3 should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 14)\n" + - " I1 i1 = null;\n" + - " ^^\n" + - "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 15)\n" + - " I1.I2 i2 = null;\n" + - " ^^^^^\n" + - "X.I1.I2 is a raw type. References to generic type X.I1.I2 should be parameterized\n" + - "----------\n" + - "8. ERROR in X.java (at line 16)\n" + - " I1.I2 i1i2 = null;\n" + - " ^^^^^^^^\n" + - "The member type X.I1.I2 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.I1\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 -// simulate incremental compile -public void test0972() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "Outer.java", //================================ - "//Outer.java\n" + - "public class Outer {\n" + - " public class Inner {}\n" + - "\n" + - " public static void method(Outer.Inner x) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Outer.Inner x = null;\n" + - " method(x);\n" + - " }\n" + - "}\n" + - "\n", - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - "}\n" - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - - this.runConformTest( - new String[] { - "Outer.java", //================================ - "//Outer.java\n" + - "public class Outer {\n" + - " public class Inner {}\n" + - "\n" + - " public static void method(Outer.Inner x) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Outer.Inner x = null;\n" + - " method(x);\n" + - " }\n" + - "}\n" + - "\n", - }, - "SUCCESS", - null, - false, - null); - this.runConformTest( - new String[] { - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - - }, - "SUCCESS", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 - variation -//pure source scenario -public void test0973() { - this.runConformTest( - new String[] { - "Outer.java", //================================ - "//Outer.java\n" + - "public class Outer {\n" + - " public class Inner {}\n" + - "\n" + - " public static void method(Outer.Inner x) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Outer.Inner x = null;\n" + - " method(x);\n" + - " }\n" + - "}\n" + - "\n", - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 - variation -//simulate incremental compile -public void test0974() { - this.runConformTest( - new String[] { - "Outer.java", //================================ - "//Outer.java\n" + - "public class Outer {\n" + - " public class Inner {}\n" + - "\n" + - " public static void method(Outer.Inner x) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Outer.Inner x = null;\n" + - " method(x);\n" + - " }\n" + - "}\n" + - "\n", - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - "}\n" - }, - "SUCCESS"); - this.runConformTest( - new String[] { - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " {\n" + - " Outer.Inner in;\n" + - " Outer.method(this);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" - - }, - "SUCCESS", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122999 -public void test0975() { - this.runNegativeTest( - new String[] { - "X.java", //================================ - "import java.util.ArrayList;\n" + - "\n" + - "public class X extends ArrayList {\n" + - " public static class Bean {}\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " public class X extends ArrayList {\n" + - " ^\n" + - "The serializable class X does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " public class X extends ArrayList {\n" + - " ^^^^\n" + - "Bean cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139525 -public void test0976() { - this.runConformTest( - new String[] { - "S.java", // ================= - "import java.util.Collection;\n" + - "public class S {\n" + - " public static void cow(IDA s) {\n" + - " Collection ids = s.getIds(); // Error here\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", // ================= - "ID.java", // ================= - "import java.util.Collection;\n" + - "public interface ID {\n" + - " Collection> getIds();\n" + - "}\n", // ================= - "IDA.java", // ================= - "import java.util.Collection;\n" + - "public interface IDA extends ID {\n" + - " enum Enum1 {\n" + - " ONE, TWO\n" + - " }\n" + - " Collection getIds();\n" + - "}\n", // ================= - }, - "SUCCESS"); - this.runConformTest( - new String[] { - "S.java", // ================= - "import java.util.Collection;\n" + - "public class S {\n" + - " public static void cow(IDA s) {\n" + - " Collection ids = s.getIds(); // Error here\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS2\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS2", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139619 -public void test0977() { - this.runConformTest( - new String[] { - "MMTPProtocol.java", // ================= - "import java.io.InputStream;\n" + - "import java.util.HashSet;\n" + - "import bug.ProtocolManager;\n" + - "abstract class AbstractProtocol implements ProtocolManager {\n" + - " public AbstractProtocol(HashSet manager, String grp) {}\n" + - " AbstractProtocol(){} \n" + - " public void connect(ConnectType type) { }\n" + - "}\n" + - "public abstract class MMTPProtocol extends AbstractProtocol {\n" + - " public void connect(ConnectType type) {}\n" + - "}\n", // ================= - "bug/ProtocolManager.java", // ================= - "package bug;\n" + - "public interface ProtocolManager{\n" + - " public enum ConnectType {Client,Server}\n" + - " public void connect(ConnectType type) ;\n" + - " public boolean receive(R input) throws Exception;\n" + - "}", // ================= - }, - ""); - this.runConformTest( - new String[] { - "MMTPProtocol.java", // ================= - "import java.io.InputStream;\n" + - "import java.util.HashSet;\n" + - "import bug.ProtocolManager;\n" + - "abstract class AbstractProtocol implements ProtocolManager {\n" + - " public AbstractProtocol(HashSet manager, String grp) {}\n" + - " AbstractProtocol(){} \n" + - " public void connect(ConnectType type) { }\n" + - "}\n" + - "public abstract class MMTPProtocol extends AbstractProtocol {\n" + - " public void connect(ConnectType type) {}\n" + - "}\n", // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139669 -public void test0978() { - this.runConformTest( - new String[] { - "B.java", // ================= - "public class B implements A {\n" + - " public void foo(A.C c) {}\n" + - "}", // ================= - "A.java", // ================= - "public interface A {\n" + - " void foo(A.C c);\n" + - " class C {}\n" + - "}", // ================= - }, - ""); - this.runConformTest( - new String[] { - "A.java", // ================= - "public interface A {\n" + - " void foo(A.C c);\n" + - " class C {}\n" + - "}", // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139669 -public void test0979() { - this.runConformTest( - new String[] { - "B.java", // ================= - "public class B extends A {\n" + - " @Override\n" + - " public void foo(A.C c) {}\n" + - "}", // ================= - "A.java", // ================= - "public class A {\n" + - " public void foo(A.C c) {}\n" + - " public static class C {}\n" + - "}", // ================= - }, - ""); - this.runConformTest( - new String[] { - "A.java", // ================= - "public class A {\n" + - " public void foo(A.C c) {}\n" + - " public static class C {}\n" + - "}", // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140772 -public void test0980() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.Collections;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - " public Set keySet() {\n" + - " return Collections. emptySet();\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140569 -//simulate incremental compile -public void test0981() { - this.runConformTest( - new String[] { - "Outer.java", //================================ - "//Outer.java\n" + - "public class Outer {\n" + - " public class Inner {}\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n", - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " public void method(){\n" + - " Worker.method(this);\n" + - " }\n" + - " }\n" + - "}\n", - "Worker.java", //================================ - "public class Worker {\n" + - " public static void method(Outer.Inner i) {}\n" + - "}\n", //================================ - }, - "SUCCESS"); - this.runConformTest( - new String[] { - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " public void method(){\n" + - " Worker.method(this);\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", //================================ - }, - "SUCCESS", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140569 -//simulate incremental compile -public void test0982() { - this.runConformTest( - new String[] { - "Outer.java", //================================ - "//Outer.java\n" + - "public class Outer {\n" + - " public class Inner {\n" + - " public class Inner2 {}\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n" + - "\n", - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " class ExtendedInner2 extends Inner2 {\n" + - " public void method(){\n" + - " Worker.method(this);\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n", - "Worker.java", //================================ - "public class Worker {\n" + - " public static void method(Outer.Inner.Inner2 i) {}\n" + - "}\n", //================================ - }, - "SUCCESS"); - this.runConformTest( - new String[] { - "ExtendedOuter.java", //================================ - "public class ExtendedOuter extends Outer {\n" + - " class ExtendedInner extends Inner {\n" + - " class ExtendedInner2 extends Inner2 {\n" + - " public void method(){\n" + - " Worker.method(this);\n" + - " }\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", //================================ - }, - "SUCCESS", - null, - false, - null); -} -public void test0983() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) throws Throwable {\n" + - " List l1 = new ArrayList();\n" + - " List l2 = new ArrayList();\n" + - " l1.addAll(l2);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " l1.addAll(l2);\n" + - " ^^^^^^\n" + - "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + - "----------\n"); -} -// generic inner class within a non generic one -public void test0984() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " public class XX {}\n" + - "}", - "I.java", - "public interface I {\n" + - " X.XX foo();\n" + - "}", - "Y.java", - "public class Y extends X implements I {\n" + - " public XX foo() {\n" + - " return null;\n" + - " }\n" + - "}", - }, - // runtime results - "" /* expected output string */); - runConformTest( - // test directory preparation - false /* do not flush output directory */, - new String[] { /* test files */ - "Y.java", - "public class Y extends X implements I {\n" + - " public XX foo() {\n" + - " return null;\n" + - " }\n" + - "}", - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141330 -public void test0985() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " public void testBreak() {\n" + - " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List>> to List>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=91709 -public void test0986() { - this.runConformTest( - new String[] { - "T.java", // ================= - "public class T {\n" + - " public T() {\n" + - " S s = new S();\n" + - " s.setObj(\"S\");\n" + - " System.out.print(s.getObj());\n" + - " S i = new S();\n" + - " i.setObj(new Integer(100));\n" + - " System.out.print(i.getObj());\n" + - " S m = new S();\n" + - " m.setObj(new MyClass(\"[Terry]\"));\n" + - " System.out.print(m.getObj());\n" + - " S x = new S(new MyClass(\"[Corbet]\"));\n" + - " System.out.print(x.getObj());\n" + - " } // End of Constructor for T.\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " new T();\n" + - " System.out.println(\"SUCCESS\");\n" + - " } catch (Exception ex) {\n" + - " ex.printStackTrace();\n" + - " }\n" + - " } // End of main().\n" + - "\n" + - " class MyClass {\n" + - " private String str;\n" + - " public MyClass(String str) {\n" + - " this.str = str;\n" + - " } // End of Constructor for MyClass.\n" + - " @Override\n" + - " public String toString() {\n" + - " return (\"MyClass = \" + str);\n" + - " } // End of toString().\n" + - " } // End of Embedded MyClass Class.\n" + - "} // End of T Class.\n", // ================= - "S.java", // ================= - "public class S<$T> extends B<$T> {\n" + - " public S() {\n" + - " super();\n" + - " } // End of Constructor for S.\n" + - " public S($T obj) {\n" + - " super(obj);\n" + - " } // End of Constructor for S.\n" + - "} // End of S Class.\n", // ================= - "B.java", // ================= - "public abstract class B<$T> {\n" + - " $T obj;\n" + - " public B() {\n" + - " ;\n" + - " } // End of Constructor for B.\n" + - " public B($T obj) {\n" + - " this.obj = obj;\n" + - " } // End ofg Constructor of B.\n" + - " public $T getObj() {\n" + - " return (obj);\n" + - " } // End of getObj().\n" + - " public void setObj($T obj) {\n" + - " this.obj = obj;\n" + - " } // End of setObj().\n" + - "} // End of B Class.", // ================= - - }, - "S100MyClass = [Terry]MyClass = [Corbet]SUCCESS"); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 -public void test0987() { - String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 - ? "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " public ISheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^^\n" + - "The return type is incompatible with EditPart.getViewer()\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " public ISheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^\n" + - "The method getViewer() of type AbstractLinkView must override a superclass method\n" + - "----------\n" - : "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " public ISheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^^\n" + - "The return type is incompatible with EditPart.getViewer()\n" + - "----------\n"; - this.runNegativeTest( - new String[] { - "X.java",//=================== - "public class X {\n" + - " void bar(GLinkElementView g) {\n" + - " g.getViewer();\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class GLinkElementView extends AbstractLinkView {}\n" + - "\n" + - "abstract class AbstractLinkView extends AbstractConnectionEditPart implements ILinkViewElement {\n" + - " @Override\n" + - " public ISheetViewer getViewer() { return null; } \n" + - "}\n" + - "\n" + - "abstract class AbstractConnectionEditPart implements EditPart {}\n" + - "\n" + - "abstract class AbstractEditPart implements EditPart {\n" + - " public EditPartViewer getViewer() { return null; }\n" + - "}\n" + - "\n" + - "interface ILinkViewElement {\n" + - " public ISheetViewer getViewer();\n" + - "}\n" + - "\n" + - "interface ISheetViewer {}\n" + - "\n" + - "interface EditPart {\n" + - " EditPartViewer getViewer();\n" + - "}\n" + - "\n" + - "interface EditPartViewer {}\n", // ================= - }, - expectedOutput); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation -public void test0988() { - this.runNegativeTest( - new String[] { - "X.java",//=================== - "public class X {\n" + - " void bar(GLinkElementView g) {\n" + - " g.getViewer();\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class GLinkElementView extends AbstractLinkView {}\n" + - "\n" + - "abstract class AbstractLinkView extends AbstractConnectionEditPart implements ILinkViewElement, IModelChangeListener {\n" + - " @Override\n" + - " public SheetViewer getViewer() { return null; } \n" + - "}\n" + - "\n" + - "abstract class AbstractConnectionEditPart extends AbstractGraphicalEditPart implements ConnectionEditPart {}\n" + - "\n" + - "abstract class AbstractGraphicalEditPart extends AbstractEditPart implements GraphicalEditPart {}\n" + - "\n" + - "abstract class AbstractEditPart implements EditPart {\n" + - " public EditPartViewer getViewer() { return null; }\n" + - "}\n" + - "\n" + - "interface ILinkViewElement extends INodeViewElement {\n" + - " public ISheetViewer getViewer();\n" + - "}\n" + - "\n" + - "class SheetViewer implements ISheetViewer {}\n" + - "\n" + - "interface ISheetViewer {}\n" + - "\n" + - "interface EditPart {\n" + - " EditPartViewer getViewer();\n" + - "}\n" + - "\n" + - "interface ConnectionEditPart extends GraphicalEditPart {}\n" + - "interface GraphicalEditPart extends EditPart {}\n" + - "interface EditPartViewer {}\n" + - "interface IModelChangeListener {}\n" + - "\n" + - "interface INodeViewElement {\n" + - " public ISheetViewer getViewer();\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " public SheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^\n" + - "The return type is incompatible with AbstractEditPart.getViewer()\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 -public void test0989() { - this.runNegativeTest( - new String[] { - "Child.java",//=================== - "public class Child extends Parent {}\n" + - "abstract class Parent extends Grandparent implements IParent {}\n" + - "interface IParent extends IGrandparent {}\n" + - "abstract class Grandparent implements IGrandparent {}\n" + - "interface IGrandparent {}", // =================, // ================= - }, - "----------\n" + - "1. ERROR in Child.java (at line 2)\n" + - " abstract class Parent extends Grandparent implements IParent {}\n" + - " ^^^^^^\n" + - "The interface IGrandparent cannot be implemented more than once with different arguments: IGrandparent and IGrandparent\n" + - "----------\n" + - "2. WARNING in Child.java (at line 2)\n" + - " abstract class Parent extends Grandparent implements IParent {}\n" + - " ^^^^^^^\n" + - "IParent is a raw type. References to generic type IParent should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation -public void test0990() { - this.runNegativeTest( - new String[] { - "Child.java",//=================== - "public class Child extends Parent {}\n" + - "abstract class Parent extends Grandparent implements IParent {}\n" + - "interface IParent extends IGrandparent {}\n" + - "abstract class Grandparent implements IGrandparent {}\n" + - "interface IGrandparent {}", // =================, // ================= - }, - "----------\n" + - "1. ERROR in Child.java (at line 1)\n" + - " public class Child extends Parent {}\n" + - " ^^^^^\n" + - "The hierarchy of the type Child is inconsistent\n" + - "----------\n" + - "2. ERROR in Child.java (at line 2)\n" + - " abstract class Parent extends Grandparent implements IParent {}\n" + - " ^^^^^^^\n" + - "The type Parent cannot extend or implement IParent. A supertype may not specify any wildcard\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation -public void test0991() { - this.runNegativeTest( - new String[] { - "X.java",//=================== - "public class X extends SX implements IX {}\n" + - "class SX extends TX implements IX {}\n" + - "class TX implements IX {}\n" + - "interface IX {}\n", // =================, // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X extends SX implements IX {}\n" + - " ^\n" + - "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " class SX extends TX implements IX {}\n" + - " ^^\n" + - "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation -public void test0992() { - this.runNegativeTest( - new String[] { - "X.java",//=================== - "import java.util.*;\n" + - "public abstract class X implements Collection, I {\n" + - " \n" + - " void foo() {\n" + - " this.add(new Object());\n" + - " this.add(null);\n" + - " }\n" + - "}\n" + - "interface I extends Collection {\n" + - "}\n", // =================, // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public abstract class X implements Collection, I {\n" + - " ^\n" + - "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " public abstract class X implements Collection, I {\n" + - " ^^^^^^^^^^\n" + - "Collection is a raw type. References to generic type Collection should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " this.add(new Object());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " this.add(null);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 -public void test0993() { - runConformTest( - true, - new String[] { - "X.java",//=================== - "public class X {\n" + - " public class Inner {\n" + - " Inner() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new ATest();\n" + - " }\n" + - "}\n" + - "\n" + - "class ATest {\n" + - " public ATest() {\n" + - " T instance = makeInstance();\n" + - " X.Inner peq = instance.new Inner(); //**\n" + - " }\n" + - "\n" + - " private T makeInstance() {\n" + - " return (T) new X();\n" + - " }\n" + - "}", // ================= - }, - null, - "SUCCESS", - null, - JavacTestOptions.JavacHasABug.JavacBug6569404); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 - variation -public void test0994() { - this.runConformTest( - new String[] { - "X.java",//=================== - "public class X {\n" + - " public class Inner {\n" + - " Inner() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - " void foo(boolean b, X1 x1, X2 x2) {\n" + - " (b ? x1 : x2).new Inner();\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().foo(true, new X1(), new X2());\n" + - " }\n" + - "}\n" + - "\n" + - "class X1 extends X implements Comparable {\n" + - " public int compareTo(X1 other) {\n" + - " return 0;\n" + - " }\n" + - "}\n" + - "class X2 extends X implements Comparable {\n" + - " public int compareTo(X2 other) {\n" + - " return 0;\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142964 -public void _test0995() { - this.runNegativeTest( - new String[] { - "X.java",//=================== - "public class X {\n" + - " public class Inner {\n" + - " }\n" + - " void foo(boolean b, X1 x1, X2 x2) {\n" + - " Comparable cx1 = b ? x1 : x2;\n" + - " Comparable cx2 = b ? x1 : x2;\n" + - " String s = b ? x1 : x2;\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class X1 extends X implements Comparable {}\n" + - "abstract class X2 extends X implements Comparable {}", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143793 -public void test0996() { - this.runNegativeTest( - new String[] { - "X.java",//=================== - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " private T aObject = null;\n" + - " public static List castList(final List pList, final Class pClass) {\n" + - " final List result = new ArrayList();\n" + - " for (Object o:pList) {\n" + - " if (pClass.isInstance(o)) {\n" + - " result.add(pClass.cast(o));\n" + - " }\n" + - " }\n" + - " return result;\n" + - " }\n" + - "\n" + - " public static void main(final String[] pArgs) {\n" + - " final List l1 = new ArrayList();\n" + - " l1.add(new X());\n" + - " l1.add(new X());\n" + - " final List> l2 = castList(l1, List.class);\n" + - " \n" + - " List l3 = l2;\n" + - " List> l4 = null;\n" + - " l3 = l4;\n" + - " }\n" + - "\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " private T aObject = null;\n" + - " ^^^^^^^\n" + - "The field X.aObject is never read locally\n" + - "----------\n" + - "2. ERROR in X.java (at line 20)\n" + - " final List> l2 = castList(l1, List.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to List>\n" + - "----------\n" + - "3. WARNING in X.java (at line 22)\n" + - " List l3 = l2;\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 22)\n" + - " List l3 = l2;\n" + - " ^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n" + - "5. ERROR in X.java (at line 24)\n" + - " l3 = l4;\n" + - " ^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 - variation -public void test0997() { - runConformTest( - true, - new String[] { - "X.java",//=================== - "public class X implements Outer {\n" + - " public static void main(String[] args) {\n" + - " new ATest();\n" + - " }\n" + - "}\n" + - "interface Outer {\n" + - " public class Inner {\n" + - " Inner() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class ATest {\n" + - " public ATest() {\n" + - " Outer.Inner peq = new T.Inner(); //**\n" + - " }\n" + - "\n" + - " private T makeInstance() {\n" + - " return (T) new X();\n" + - " }\n" + - "}", // ================= - }, - null, - "SUCCESS", - null, - JavacTestOptions.JavacHasABug.JavacBug6569404); -} -//regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=144261 -public void test0998() { - this.runConformTest( - new String[] { - "X.java", - "class X {\n" + - " static abstract class Generic {\n" + - " static class Inner {\n" + - " static class InnerInner { }\n" + - " InnerInner createTableModel() {\n" + - " return new InnerInner();\n" + - " }\n" + - " }\n" + - " }\n" + - " static class SubGeneric extends Generic {\n" + - " static class SubInner extends Inner {\n" + - " InnerInner createTableModel() {\n" + - " return super.createTableModel(); \n" + - " }\n" + - " }\n" + - " }\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 -public void test0999() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static final Iterator chain(Iterator... it) {\n" + - " return null;\n" + - " }\n" + - " void foo1() {\n" + - " List l1 = Arrays.asList(1, 2, 3);\n" + - " List l2 = Arrays.asList(4f, 5f, 6f);\n" + - " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + - " }\n" + - " void foo2() {\n" + - " List l1 = Arrays.asList(1, 2, 3);\n" + - " List l2 = Arrays.asList(4f, 5f, 6f);\n" + - " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + - " }\n" + - " void foo3() {\n" + - " List l1 = Arrays.asList(1, 2, 3);\n" + - " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation chain(Iterator...) of the generic method chain(Iterator...) of type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + - " ^^^^^\n" + - "The method chain(Iterator...) in the type X is not applicable for the arguments (Iterator, Iterator)\n" + - "----------\n" + - "4. WARNING in X.java (at line 18)\n" + - " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterator is created for a varargs parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 -public void test1000() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static final Iterator chain(Iterator... it) {\n" + - " return null;\n" + - " }\n" + - " void foo1() {\n" + - " List l1 = Arrays.asList(1, 2, 3);\n" + - " List l2 = Arrays.asList(4f, 5f, 6f);\n" + - " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + - " }\n" + - " void foo2() {\n" + - " List l1 = Arrays.asList(1, 2, 3);\n" + - " List l2 = Arrays.asList(4f, 5f, 6f);\n" + - " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + - " }\n" + - " void foo3() {\n" + - " List l1 = Arrays.asList(1, 2, 3);\n" + - " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation chain(Iterator...) of the generic method chain(Iterator...) of type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + - "----------\n" + - "3. WARNING in X.java (at line 14)\n" + - " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterator> is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 14)\n" + - " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Iterator> to Iterator\n" + - "----------\n" + - "5. WARNING in X.java (at line 18)\n" + - " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterator is created for a varargs parameter\n" + - "----------\n" + - "6. ERROR in X.java (at line 18)\n" + - " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Iterator to Iterator\n" + - "----------\n"); -} -public void test1001() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Box {}\n" + - " static class ABox {}\n" + - " static class A {}\n" + - " \n" + - " void foo(ABox a1, ABox a2) {\n" + - " a1 = a2; \n" + - " }\n" + - "}", // ================= - }, - ""); -} -public void test1002() { - this.runNegativeTest( - new String[] { - "Base.java", - "class Base {\n" + - "}\n" + - "class Foo>> {\n" + - " U u;\n" + - " V v;\n" + - "}\n" + - "class Bar>> {\n" + - " E e;\n" + - " F f;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in Base.java (at line 3)\n" + - " class Foo>> {\n" + - " ^^^\n" + - "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter >> of the type Bar\n" + - "----------\n" + - "2. ERROR in Base.java (at line 7)\n" + - " class Bar>> {\n" + - " ^^^\n" + - "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter >> of the type Foo\n" + - "----------\n"); -} -public void test1003() { - this.runConformTest( - new String[] { - "B.java", - "class B {\n" + - "}\n" + - "class S, TT extends T> {\n" + - " BB b;\n" + - " TT t;\n" + - "}\n" + - "class T, TT extends T> {\n" + - " BB b;\n" + - " SS t;\n" + - "}\n", // ================= - }, - ""); -} -public void test1004() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " B getOtherValue() {\n" + - " return null;\n" + - " }\n" + - " A getValue() {\n" + - " return getOtherValue();\n" + - " }\n" + - "}", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145420 -public void test1005() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - "\n" + - " private static final Object NULL_REF = new Object();\n" + - " private Object data;\n" + - "\n" + - " private static RT unwrap(Object obj) {\n" + - " return (RT)(obj == NULL_REF ? null : obj);\n" + - " }\n" + - "\n" + - " public T1 getAsT1() {\n" + - " return unwrap(data);\n" + - " }\n" + - "\n" + - " public T2 getAsT2() {\n" + - " return unwrap(data);\n" + - " }\n" + - "}", // ================= - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=145420 - variant -public void test1005b() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " private static final Object NULL_REF = new Object();\n" + - " private Object data;\n" + - "\n" + - " private static RT unwrap(Object obj) {\n" + - " return (RT)(obj == NULL_REF ? null : obj);\n" + - " }\n" + - "\n" + - " public T1 getAsT1() {\n" + - " return unwrap(data);\n" + - " }\n" + - "\n" + - " public T2 getAsT2() {\n" + - " return unwrap(data);\n" + - " }\n" + - " Zork z;\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " return (RT)(obj == NULL_REF ? null : obj);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to RT\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test1006() { - this.runConformTest( - new String[] { - "X.java", - "class Reference {\n" + - " T target;\n" + - " Reference(T target) {\n" + - " this.target = target;\n" + - " }\n" + - " T deref() {\n" + - " return this.target;\n" + - " }\n" + - " static Reference create(U u) {\n" + - " return new Reference(u);\n" + - " }\n" + - "}\n" + - "class BaseObject {}\n" + - "class Person extends BaseObject {}\n" + - "class Building extends BaseObject {}\n" + - "\n" + - "public class X {\n" + - " void foo(Building b, Person p) {\n" + - " Reference bRef = Reference.create(b);\n" + - " Reference pRef = Reference.create(p);\n" + - "\n" + - " final Building building = bRef.deref();\n" + - " final Person person = pRef.deref();\n" + - " }\n" + - "}", // ================= - }, - ""); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147381 -public void test1007() { - this.runNegativeTest( - new String[] { - "GenericsProblem.java", - "public class GenericsProblem {\n" + - " public void test(T val) {\n" + - " GenericsProblem gp = new GenericsProblem();\n" + - " Class cl2 = gp.getClass();\n" + - " Class cl = val.getClass();\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in GenericsProblem.java (at line 5)\n" + - " Class cl = val.getClass();\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 -public void test1008() { - runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(L l, C c) {\n" + - " X x = bar(l, c);\n" + - " }\n" + - " T bar(L l, C c) { \n" + - " return null;\n" + - " } \n" + - "}\n" + - "class C {}\n" + - "class L {}\n" + - "\n" + - "\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\r\n" + - " void foo(L l, C c) {\r\n" + - " ^\n" + - "L is a raw type. References to generic type L should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\r\n" + - " X x = bar(l, c);\r\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(L, C) of the generic method bar(L, C) of type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\r\n" + - " X x = bar(l, c);\r\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to X\n" + - "----------\n" + - "4. WARNING in X.java (at line 3)\r\n" + - " X x = bar(l, c);\r\n" + - " ^\n" + - "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + - "----------\n", - JavacTestOptions.EclipseJustification.EclipseBug148061); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1009() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "public class X {\n" + - "\n" + - " void foo(Map map) {\n" + - " bar(map);\n" + - " }\n" + - " void bar(Map> map) {\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " void foo(Map map) {\n" + - " ^^^\n" + - "Map is a raw type. References to generic type Map should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " bar(map);\n" + - " ^^^\n" + - "The method bar(Map>) in the type X is not applicable for the arguments (Map)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1010() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "public class X {\n" + - "\n" + - " void foo(Map map) {\n" + - " bar(map);\n" + - " }\n" + - " void bar(Map> map) {\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " void foo(Map map) {\n" + - " ^^^\n" + - "Map is a raw type. References to generic type Map should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " bar(map);\n" + - " ^^^\n" + - "The method bar(Map>) in the type X is not applicable for the arguments (Map)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1011() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo(HashMap map, String s, Map map2) {\n" + - " bar(map, s, map2); //1\n" + - " bar(map2, s, map2); //2\n" + - " bar2(map, s, map2); //3\n" + - " bar3(map, s, map2); //4\n" + - " }\n" + - " void bar(Map map, U u, Map map2) {}\n" + - " void bar2(Map map, String s, Map map2) {}\n" + - " void bar3(Map map, U s, Map map2) {}\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " void foo(HashMap map, String s, Map map2) {\n" + - " ^^^^^^^\n" + - "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " bar(map, s, map2); //1\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(Map, Object, Map) of the generic method bar(Map, U, Map) of type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " bar(map, s, map2); //1\n" + - " ^^^\n" + - "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " bar2(map, s, map2); //3\n" + - " ^^^\n" + - "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + - "----------\n" + - "5. WARNING in X.java (at line 7)\n" + - " bar3(map, s, map2); //4\n" + - " ^^^\n" + - "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1012() { - runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(L l, C c) {\n" + - " X x = bar1(l, c);\n" + - " L lx = bar2(l, c);\n" + - " C cx = bar3(l, c);\n" + - " }\n" + - " T bar1(L l, C c) {\n" + - " return null;\n" + - " }\n" + - " L bar2(L l, C c) {\n" + - " return null;\n" + - " }\n" + - " C bar3(L l, C c) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "class C {}\n" + - "class L {}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\r\n" + - " void foo(L l, C c) {\r\n" + - " ^\n" + - "L is a raw type. References to generic type L should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\r\n" + - " X x = bar1(l, c);\r\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar1(L, C) of the generic method bar1(L, C) of type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\r\n" + - " X x = bar1(l, c);\r\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to X\n" + - "----------\n" + - "4. WARNING in X.java (at line 3)\r\n" + - " X x = bar1(l, c);\r\n" + - " ^\n" + - "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + - "----------\n" + - "5. WARNING in X.java (at line 4)\r\n" + - " L lx = bar2(l, c);\r\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar2(L, C) of the generic method bar2(L, C) of type X\n" + - "----------\n" + - "6. WARNING in X.java (at line 4)\r\n" + - " L lx = bar2(l, c);\r\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + - "----------\n" + - "7. WARNING in X.java (at line 4)\r\n" + - " L lx = bar2(l, c);\r\n" + - " ^\n" + - "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + - "----------\n" + - "8. WARNING in X.java (at line 5)\r\n" + - " C cx = bar3(l, c);\r\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar3(L, C) of the generic method bar3(L, C) of type X\n" + - "----------\n" + - "9. WARNING in X.java (at line 5)\r\n" + - " C cx = bar3(l, c);\r\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type C needs unchecked conversion to conform to C\n" + - "----------\n" + - "10. WARNING in X.java (at line 5)\r\n" + - " C cx = bar3(l, c);\r\n" + - " ^\n" + - "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + - "----------\n", - JavacTestOptions.EclipseJustification.EclipseBug148061); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1013() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List ls = new ArrayList();\n" + - " ls.add(\"foo\");\n" + - " List lx = new ArrayList();\n" + - " lx.add(new X());\n" + - " new X().foo(ls, lx);\n" + - " }\n" + - " void done() {\n" + - " System.out.println(\"[done]\");\n" + - " }\n" + - " void foo(List l1, List l2) {\n" + - " X x = bar1(l1, l2);\n" + - " x.done();\n" + - " List lx = bar2(l1, l2);\n" + - " lx.get(0).done();\n" + - " }\n" + - " T bar1(List l1, List l2) {\n" + - " return l1.get(0);\n" + - " }\n" + - " List bar2(List l1, List l2) {\n" + - " return l1;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 14)\r\n" + - " void foo(List l1, List l2) {\r\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 15)\r\n" + - " X x = bar1(l1, l2);\r\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar1(List, List) of the generic method bar1(List, List) of type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 15)\r\n" + - " X x = bar1(l1, l2);\r\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to X\n" + - "----------\n" + - "4. WARNING in X.java (at line 15)\r\n" + - " X x = bar1(l1, l2);\r\n" + - " ^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 17)\r\n" + - " List lx = bar2(l1, l2);\r\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar2(List, List) of the generic method bar2(List, List) of type X\n" + - "----------\n" + - "6. WARNING in X.java (at line 17)\r\n" + - " List lx = bar2(l1, l2);\r\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "7. WARNING in X.java (at line 17)\r\n" + - " List lx = bar2(l1, l2);\r\n" + - " ^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n", - JavacTestOptions.EclipseJustification.EclipseBug148061); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1014() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " void foo1(List l, List ls) {\n" + - " Set> mss1 = bar(l, ls).entrySet();\n" + - " String s = bar(l, ls).entrySet();\n" + - " }\n" + - " Map bar(List lu, List lv) { return null; }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " void foo1(List l, List ls) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " Set> mss1 = bar(l, ls).entrySet();\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " Set> mss1 = bar(l, ls).entrySet();\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type Set needs unchecked conversion to conform to Set>\n" + - "----------\n" + - "4. WARNING in X.java (at line 5)\n" + - " Set> mss1 = bar(l, ls).entrySet();\n" + - " ^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 6)\n" + - " String s = bar(l, ls).entrySet();\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + - "----------\n" + - "6. ERROR in X.java (at line 6)\n" + - " String s = bar(l, ls).entrySet();\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Set to String\n" + - "----------\n" + - "7. WARNING in X.java (at line 6)\n" + - " String s = bar(l, ls).entrySet();\n" + - " ^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1015() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo1(List l, List ls) {\n" + - " List ls1 = bar(l, ls);\n" + - " String s = bar(l, ls);\n" + - " }\n" + - " List bar(List lu, List lv) { return null; }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " void foo1(List l, List ls) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " List ls1 = bar(l, ls);\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " List ls1 = bar(l, ls);\n" + - " ^^^^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "4. WARNING in X.java (at line 4)\n" + - " List ls1 = bar(l, ls);\n" + - " ^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 5)\n" + - " String s = bar(l, ls);\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + - "----------\n" + - "6. ERROR in X.java (at line 5)\n" + - " String s = bar(l, ls);\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to String\n" + - "----------\n" + - "7. WARNING in X.java (at line 5)\n" + - " String s = bar(l, ls);\n" + - " ^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1016() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo1() {\n" + - " List ls1 = bar(null);\n" + - " List ls2 = bar(null);\n" + - " String s = bar(null);\n" + - " }\n" + - " List bar(List lu) { return null; }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List ls1 = bar(null);\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " String s = bar(null);\n" + - " ^^^^^^^^^\n" + - "Type mismatch: cannot convert from List to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1017() { - this.runNegativeTest( - new String[] { - "SortedList.java", - "import java.util.*;\n" + - "\n" + - "public class SortedList extends LinkedList\n" + - "{\n" + - " public boolean add(E e){\n" + - " int index = Collections.binarySearch(this,e);\n" + - " if (index<0)\n" + - " super.add(-index-1,e);\n" + - " return true;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in SortedList.java (at line 3)\n" + - " public class SortedList extends LinkedList\n" + - " ^^^^^^^^^^\n" + - "The serializable class SortedList does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. WARNING in SortedList.java (at line 3)\n" + - " public class SortedList extends LinkedList\n" + - " ^^^^^^^^^^\n" + - "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + - "----------\n" + - "3. WARNING in SortedList.java (at line 5)\n" + - " public boolean add(E e){\n" + - " ^^^^^^^^\n" + - "The method add(E) of type SortedList should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "4. ERROR in SortedList.java (at line 6)\n" + - " int index = Collections.binarySearch(this,e);\n" + - " ^^^^^^^^^^^^\n" + - "The method binarySearch(List>, T) in the type Collections is not applicable for the arguments (SortedList, E)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation -public void test1018() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " void foo(U u) {\n" + - " bar(u, new Exception());\n" + - " }\n" + - " T bar(U u, T t) { return null; }\n" + - "}", // ================= - }, - ""); -} -public void test1018a() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "class A {}\n" + - "\n" + - "class B extends A> {}\n" + - "\n" + - "public class X extends B {\n" + - " public static void main(String[] args) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}" - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -public void test1019() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " double[] d1 = new double[] { 1.0, 2.0, 3.0, 4.0 };\n" + - " System.out.println(deepToString(d1));\n" + - "\n" + - " Double[] d2 = new Double[] { 1.0, 2.0, 3.0, 4.0 };\n" + - " System.out.println(deepToString(d2));\n" + - " \n" + - " }\n" + - "\n" + - " public static String deepToString(T[] array) {\n" + - " StringBuffer s = new StringBuffer();\n" + - " for (T t : array) {\n" + - " s.append(t.toString());\n" + - " s.append(\",\");\n" + - " }\n" + - " if (s.length() > 0) {\n" + - " s.setLength(s.length() - 1); // removes last \",\"\n" + - " }\n" + - " return s.toString();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " System.out.println(deepToString(d1));\n" + - " ^^^^^^^^^^^^\n" + - "The method deepToString(T[]) in the type X is not applicable for the arguments (double[])\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149573 -public void test1020() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " void foo(List l1, List l2) {\n" + - " l1.add(l2.get(0));\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " l1.add(l2.get(0));\n" + - " ^^^\n" + - "The method add(capture#1-of ? extends Exception) in the type List is not applicable for the arguments (capture#2-of ? extends Exception)\n" + - "----------\n"); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149376 -public void test1021() { - this.runConformTest( - new String[] { - "p/SomeClass.java", - "package p;\n" + - "import static p.SomeClass.SomeEnum.*;\n" + - "public abstract class SomeClass extends Object {\n" + - " public enum SomeEnum {\n" + - " A;\n" + - " };\n" + - "}\n", - }, - "" - ); -} -public void test1021b() { // should this case be allowed? - this.runNegativeTest( - new String[] { - "p/SomeClass2.java", - "package p;\n" + - "import static p.SomeClass2.M1.*;\n" + - "public abstract class SomeClass2 extends M {\n" + - " public static class M1 extends M2 {}\n" + - " public static class M2 extends M3 {}\n" + - " public static class M3 {\n" + - " public static class M {}\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in p\\SomeClass2.java (at line 3)\n" + - " public abstract class SomeClass2 extends M {\n" + - " ^\n" + - "Cycle detected: the type SomeClass2 cannot extend/implement itself or one of its own member types\n" + - "----------\n" - ); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=151410 (duplicate of 149376) -public void test1021c() { - runConformTest( - new String[] { - "ccs/jdtbug/filters/NameRF.java", - "package ccs.jdtbug.filters;\n" + - "import static ccs.jdtbug.ResultFilter.Action.*;\n" + - "import ccs.jdtbug.*;\n" + - "public class NameRF implements ResultFilter {\n" + - " public NameRF() {}\n" + - " public Action getAction(String in, int ntotal, int naccept) {\n" + - " return YES;\n" + - " }\n" + - "} // end class\n", - "ccs/jdtbug/ResultFilter.java", - "package ccs.jdtbug;\n" + - "import java.io.*;\n" + - "public interface ResultFilter {\n" + - " public enum Action {\n" + - " YES, NO, CANCEL\n" + - " }\n" + - " public Action getAction(T in, int ntotal, int naccept) throws IOException;\n" + - "} // end interface\n" - } - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150294 -public void test1022() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " String testString = \"test string\";\n" + - "\n" + - " testWithNonGeneric(testString);\n" + - " testWithGeneric(testString);\n" + - " }\n" + - "\n" + - " private static void testWithNonGeneric(String input) {\n" + - " Class clazz = input.getClass();\n" + - "\n" + - " System.out.println(clazz.getName());\n" + - " }\n" + - "\n" + - " private static void testWithGeneric(T input) {\n" + - " Class clazz = input.getClass();\n" + - "\n" + - " System.out.println(clazz.getName());\n" + - " }\n" + - "}", // =================, - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " Class clazz = input.getClass();\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150362 -public void test1023() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "import java.util.Properties;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " Properties props = new Properties();\n" + - " for (Map.Entry entry : props.entrySet()) {\n" + - " System.out.println(entry);\n" + - " }\n" + - " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + - " System.out.println(entry);\n" + - " }\n" + - " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + - " System.out.println(entry);\n" + - " }\n" + - " for (Map.Entry entry : props.entrySet()) {\n" + - " System.out.println(entry);\n" + - " }\n" + - " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + - " System.out.println(entry);\n" + - " }\n" + - " for (Map.Entry entry : props.entrySet()) {\n" + - " System.out.println(entry);\n" + - " }\n" + - " }\n" + - "}", // =================, - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " for (Map.Entry entry : props.entrySet()) {\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from element type Map.Entry to Map.Entry\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Properties to Map\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151275 -public void test1024() { - runConformTest( - true, - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Integer castInteger = genericCast(1); // works\n" + - " int castInt1 = genericCast(1); // fails in javac but works in Eclipse\n" + - " int castInt2 = X. genericCast(1); // workaround for javac\n" + - " int castInt3 = (Integer) genericCast(1); // workaround for javac\n" + - " }\n" + - " private static T genericCast(Object input) {\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " T castValue = (T) input;\n" + - " return castValue;\n" + - " }\n" + - "}", // =================, - }, - null, - "", - null, - JavacTestOptions.EclipseJustification.EclipseBug151275); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 -public void test1025() { - this.runConformTest( - new String[] { - "GenericBaseClass.java", - "public class GenericBaseClass {\n" + - " public GenericBaseClass() {\n" + - " if (!(this instanceof ASubGenericClass)) {\n" + - " System.out.println(\"I\'m not ASubClass\");\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class ASubGenericClass extends GenericBaseClass {\n" + - " public ASubGenericClass() {\n" + - " // This compiles with both\n" + - " GenericBaseClass hey = this;\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 -public void test1026() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.LinkedHashSet;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public class A {};\n" + - " public class B extends A {};\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X g = new X();\n" + - " Set set = g.newSet(g.new B());\n" + - " }\n" + - " public Set newSet(V v) {\n" + - " Set set = new LinkedHashSet();\n" + - " set.add(v);\n" + - " return set;\n" + - " }\n" + - "}\n" // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 - variation -public void test1027() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.LinkedHashSet;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public class A {};\n" + - " public class B extends A {};\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X g = new X();\n" + - " Set set = g.newSet(g.new B());\n" + - " }\n" + - " public Set newSet(V... objects) {\n" + - " Set set = new LinkedHashSet();\n" + - " for (T t : objects) {\n" + - " set.add(t);\n" + - " }\n" + - " return set;\n" + - " }\n" + - "}\n" + - "\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 - variation -public void test1028() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.LinkedHashSet;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X g = new X();\n" + - " Set set = g.newSet(new B());\n" + - " }\n" + - " public Set newSet(V v) {\n" + - " Set set = new LinkedHashSet();\n" + - " set.add(v);\n" + - " return set;\n" + - " }\n" + - "}\n" + - "\n" + - "class A {};\n" + - "class B extends A {};\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156016 -public void test1029() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Arrays;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public static List makeNumberList(T a, T b) {\n" + - " return Arrays.asList(a, b);\n" + - " }\n" + - "\n" + - " public static void main(String... args) {\n" + - " List name = makeNumberList(5, 5D);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " return Arrays.asList(a, b);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of T is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " List name = makeNumberList(5, 5D);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to List\n" + - "----------\n"); -} -public void test1030() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public class PointList extends Object implements Iterable {\n" + - " private List theList = new ArrayList();\n" + - "\n" + - " public Iterator iterator() {\n" + - " return theList.iterator();\n" + - " }\n" + - " }\n" + - "\n" + - " private PointList waypoints = new PointList();\n" + - "\n" + - " public void printWaypoints() {\n" + - " for (Waypoint waypoint : waypoints) { // ***** This line does not compile *****\n" + - " System.out.println(waypoint.toString());\n" + - " }\n" + - " for (Iterator it = waypoints.iterator(); it.hasNext();) {\n" + - " Waypoint waypoint = it.next();\n" + - " System.out.println(waypoint.toString());\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class Waypoint {}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156765 -public void test1031() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "interface IValue extends Serializable {\n" + - " public > T getComparableValue();\n" + - "}\n" + - "\n" + - "@SuppressWarnings(\"null\")\n" + - "public class X {\n" + - " public static void foo0() {\n" + - " IValue val1 = null;\n" + - " Object o = val1.getComparableValue(); // 0\n" + - " }\n" + - " public static void foo1() {\n" + - " IValue val1 = null;\n" + - " String s = val1.getComparableValue(); // 1\n" + - " }\n" + - " public static int foo2() {\n" + - " IValue val1 = null;\n" + - " IValue val2 = null;\n" + - " return val1.getComparableValue().compareTo(val2.getComparableValue()); // 2\n" + - " } \n" + - " public static int foo3() {\n" + - " Comparable c = \"aaa\"; // 3\n" + - " Comparable o = new Object(); // 4\n" + - " return 0;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 24)\n" + - " Comparable o = new Object(); // 4\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to Comparable\n" + - "----------\n"); -} -public void test1032() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.io.*;\n" + - "\n" + - "public class X {\n" + - " T test(String name) {\n" + - "\n" + - " try {\n" + - " InputStream in = new FileInputStream(name);\n" + - " return (T) new ObjectInputStream(in).readObject();\n" + - " } catch (Exception e) {\n" + - " }\n" + - " return null;\n" + - " }\n" + - "\n" + - " U text() {\n" + - " return test(\"data\");\n" + - " }\n" + - "}", // ================= - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -public void test1032a() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.*;\n" + - "\n" + - "public class X {\n" + - " T test(String name) {\n" + - "\n" + - " try {\n" + - " InputStream in = new FileInputStream(name);\n" + - " return (T) new ObjectInputStream(in).readObject();\n" + - " } catch (Exception e) {\n" + - " }\n" + - " return null;\n" + - " }\n" + - "\n" + - " U text() {\n" + - " return test(\"data\");\n" + - " }\n" + - " Zork z;\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " return (T) new ObjectInputStream(in).readObject();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to T\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test1033() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " x.bar1(Integer.TYPE);\n" + - " x.bar2(Integer.TYPE);\n" + - " x.bar2(\"\");\n" + - " } \n" + - " void bar1(Class... classes) {}\n" + - " void bar2(Class... classes) {}\n" + - " \n" + - "}", // ================= - - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " X x = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " X x = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " x.bar1(Integer.TYPE);\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method bar1(Class...) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 6)\n" + - " x.bar2(\"\");\n" + - " ^^^^\n" + - "The method bar2(Class...) in the type X is not applicable for the arguments (String)\n" + - "----------\n" + - "5. WARNING in X.java (at line 9)\n" + - " void bar2(Class... classes) {}\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158519 -public void test1034() { - this.runNegativeTest( - new String[] { - "ChainedClosure.java", - "interface Closure {\n" + - " public void execute(I input);\n" + - "}\n" + - "\n" + - "class ChainedClosure implements Closure {\n" + - " private final Closure[] iClosures;\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " public static Closure getInstance(Closure closure1, Closure closure2) {\n" + - " if (closure1 == null || closure2 == null) {\n" + - " throw new IllegalArgumentException(\"Closures must not be null\");\n" + - " }\n" + - " Closure[] closures = new Closure[] { closure1, closure2 };\n" + - " return new ChainedClosure(closures);\n" + - " }\n" + - " public ChainedClosure(Closure[] closures) {\n" + - " super();\n" + - " iClosures = closures;\n" + - " }\n" + - " public void execute(I input) {\n" + - " for (int i = 0; i < iClosures.length; i++) {\n" + - " iClosures[i].execute(input);\n" + - " }\n" + - " }\n" + - "}\n" + - "class ClosureUtils {\n" + - " public static Closure chainedClosure(Closure closure1, Closure closure2) {\n" + - " return ChainedClosure.getInstance(closure1, closure2);\n" + - " }\n" + - " public static Closure chainedClosure2(Closure closure1, Closure closure2) {\n" + - " return ChainedClosure.getInstance(closure1, closure2);\n" + - " }\n" + - " public static Closure chainedClosure3(Closure closure1, Closure closure2) {\n" + - " return ChainedClosure.getInstance(closure1, closure2);\n" + - " }\n" + - "}", // ================= - - }, - "----------\n" + - "1. ERROR in ChainedClosure.java (at line 33)\n" + - " return ChainedClosure.getInstance(closure1, closure2);\n" + - " ^^^^^^^^^^^\n" + - "The method getInstance(Closure, Closure) in the type ChainedClosure is not applicable for the arguments (Closure, Closure)\n" + - "----------\n", - JavacTestOptions.EclipseHasABug.EclipseBug236370); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158531 -public void test1035() { - this.runNegativeTest( - new String[] { - "ComparableComparator.java", - "import java.util.Comparator;\n" + - "\n" + - "@SuppressWarnings(\"unchecked\")\n" + - "class ComparableComparator> implements Comparator {\n" + - "\n" + - " static ComparableComparator instance = new ComparableComparator();\n" + - "\n" + - "public static > ComparableComparator getInstance() {\n" + - " return instance;\n" + - "}\n" + - "static > Comparator bar() {\n" + - " return null;\n" + - "}\n" + - "static Comparator baz() {\n" + - " return null;\n" + - "}\n" + - "public int compare(T obj1, T obj2) {\n" + - " return obj1.compareTo(obj2);\n" + - "}\n" + - "}\n" + - "\n" + - "@SuppressWarnings(\"unchecked\")\n" + - "class ComparatorUtils {\n" + - "\n" + - " static Comparator BAR = ComparableComparator.bar();//0\n" + - " static Comparator NATURAL_COMPARATOR = ComparableComparator.getInstance();//1\n" + - " static Object BAR2 = ComparableComparator.bar();//1a\n" + - " static Comparator BAR3 = ComparableComparator.baz();//1b\n" + - "\n" + - "public static > Comparator naturalComparator() {\n" + - " return NATURAL_COMPARATOR;\n" + - "}\n" + - "\n" + - "public static Comparator nullLowComparator(Comparator comparator) {\n" + - " if (comparator == null)\n" + - " comparator = (Comparator) naturalComparator();//2\n" + - " return new NullComparator(comparator, false);\n" + - "}\n" + - "}\n" + - "\n" + - "@SuppressWarnings(\"unchecked\")\n" + - "class NullComparator implements Comparator {\n" + - "\n" + - " Comparator nonNullComparator;\n" + - " boolean nullsAreHigh;\n" + - "\n" + - "public NullComparator() {\n" + - " this((Comparator) ComparableComparator.getInstance(), true);//3\n" + - "}\n" + - "\n" + - "public NullComparator(Comparator nonNullComparator) {\n" + - " this(nonNullComparator, true);\n" + - "}\n" + - "\n" + - "public NullComparator(boolean nullsAreHigh) {\n" + - " this((Comparator) ComparableComparator.getInstance(), nullsAreHigh);//4\n" + - "}\n" + - "\n" + - "public NullComparator(Comparator nonNullComparator, boolean nullsAreHigh) {\n" + - " this.nonNullComparator = nonNullComparator;\n" + - " this.nullsAreHigh = nullsAreHigh;\n" + - " if (nonNullComparator == null) {\n" + - " throw new NullPointerException(\"null nonNullComparator\");\n" + - " }\n" + - "}\n" + - "\n" + - "public int compare(V obj1, V obj2) {\n" + - " return 0;\n" + - "}\n" + - "}", // ================= - - }, - "----------\n" + - "1. WARNING in ComparableComparator.java (at line 14)\n" + - " static Comparator baz() {\n" + - " ^^^^^^\n" + - "The type parameter M should not be bounded by the final type String. Final types cannot be further extended\n" + - "----------\n" + - "2. ERROR in ComparableComparator.java (at line 27)\n" + - " static Object BAR2 = ComparableComparator.bar();//1a\n" + - " ^^^\n" + - "Bound mismatch: The generic method bar() of type ComparableComparator is not applicable for the arguments (). The inferred type Comparable> is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 -public void test1036() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " List list;\n" + - " Map.Entry,List> entry;\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " \n" + - " p.q.Map.Entry entry3;\n" + - " \n" + - " String.Y y; // wrong\n" + - " X.Y y1; // wrong\n" + - " X.Y y2;\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\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 3)\n" + - " List list;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\n" + - " List list;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "4. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^\n" + - "Map cannot be resolved to a type\n" + - "----------\n" + - "5. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "6. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "7. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "8. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "9. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "10. ERROR in X.java (at line 4)\n" + - " Map.Entry,List> entry;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "11. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^^^\n" + - "jaavaa cannot be resolved to a type\n" + - "----------\n" + - "12. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "13. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "14. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "15. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "16. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "17. ERROR in X.java (at line 5)\n" + - " jaavaa.util.Map.Entry,List> entry2;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "18. ERROR in X.java (at line 7)\n" + - " p.q.Map.Entry entry3;\n" + - " ^\n" + - "p cannot be resolved to a type\n" + - "----------\n" + - "19. ERROR in X.java (at line 9)\n" + - " String.Y y; // wrong\n" + - " ^^^^^^\n" + - "The type String is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "20. ERROR in X.java (at line 10)\n" + - " X.Y y1; // wrong\n" + - " ^^^^^^^^^^^\n" + - "X.Y cannot be resolved to a type\n" + - "----------\n" + - "21. ERROR in X.java (at line 10)\n" + - " X.Y y1; // wrong\n" + - " ^^^^^^\n" + - "Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type X\n" + - "----------\n" + - "22. ERROR in X.java (at line 10)\n" + - " X.Y y1; // wrong\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "23. ERROR in X.java (at line 11)\n" + - " X.Y y2;\n" + - " ^^^^^^^^^^^\n" + - "X.Y cannot be resolved to a type\n" + - "----------\n" + - "24. ERROR in X.java (at line 11)\n" + - " X.Y y2;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 - variation -public void test1037() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " \n" + - " List list;\n" + - " Map.Entry entry;\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\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 3)\n" + - " List list;\n" + - " ^^^^\n" + - "List cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\n" + - " List list;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "4. ERROR in X.java (at line 4)\n" + - " Map.Entry entry;\n" + - " ^^^\n" + - "Map cannot be resolved to a type\n" + - "----------\n" + - "5. ERROR in X.java (at line 4)\n" + - " Map.Entry entry;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation -public void test1038() throws Exception { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "interface I {\n" + - " int CONST = A.foo();\n" + - "}\n" + - "\n" + - "class A {\n" + - " static int foo() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return 0;\n" + - " }\n" + - "}\n" + - "class B implements I {\n" + - " static int LOCAL_STATIC;\n" + - " int local_field;\n" + - " B(int param) {\n" + - " int i = CONST; // keep for possible \n" + - " int j = param; // may optimize out\n" + - " int k = LOCAL_STATIC; // may optimize out\n" + - " int l = local_field; // may optimize out\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new B(12);\n" + - " }\n" + - "}", // ================= - }, - "SUCCESS", - null, - false, - null, - options, - null); - // check the reference to I.CONST still got generated (for invocation side-effect) - String expectedOutput = - " // Method descriptor #10 (I)V\n" + - " // Stack: 1, Locals: 2\n" + - " B(int param);\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [12]\n" + - " 4 getstatic B.CONST : int [15]\n" + - " 7 pop\n" + - " 8 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 14]\n" + - " [pc: 4, line: 15]\n" + - " [pc: 8, line: 19]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 9] local: this index: 0 type: B\n" + - " [pc: 0, pc: 9] local: param index: 1 type: int\n"; - - File f = new File(OUTPUT_DIR + File.separator + "B.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation -public void test1039() throws Exception { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "interface I {\n" + - " Value CONST = A.foo(\"[I.CONST]\");\n" + - "}\n" + - "class Value {\n" + - " static String NAME = \"\";\n" + - " V v;\n" + - " Value(V v) {\n" + - " this.v = v;\n" + - " }\n" + - "}\n" + - "class A {\n" + - " static Value foo(String str) {\n" + - " System.out.print(str);\n" + - " return new Value(\"str\");\n" + - " }\n" + - "}\n" + - "class B implements I {\n" + - " static Value LOCAL_STATIC = A.foo(\"[B.LOCAL_STATIC]\");\n" + - " Value local_field = A.foo(\"[B.local_field]\");\n" + - " B(Value param) {\n" + - " String i = CONST.NAME; // keep for possible \n" + - " String j = param.NAME; // may optimize out\n" + - " String k = LOCAL_STATIC.NAME; // may optimize out\n" + - " String l = local_field.NAME; // may optimize out\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new B(new Value(\"[PARAM]\"));\n" + - " }\n" + - "}", // ================= - }, - "[B.LOCAL_STATIC][B.local_field][I.CONST]", - null, - false, - null, - options, - null); - // check the reference to I.CONST still got generated (for invocation side-effect) - String expectedOutput = - " // Method descriptor #28 (LValue;)V\n" + - " // Signature: (LValue;)V\n" + - " // Stack: 2, Locals: 2\n" + - " B(Value param);\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [30]\n" + - " 4 aload_0 [this]\n" + - " 5 ldc [32]\n" + - " 7 invokestatic A.foo(java.lang.String) : Value [17]\n" + - " 10 putfield B.local_field : Value [34]\n" + - " 13 getstatic B.CONST : Value [36]\n" + - " 16 pop\n" + - " 17 getstatic Value.NAME : java.lang.String [39]\n" + - " 20 pop\n" + - " 21 getstatic Value.NAME : java.lang.String [39]\n" + - " 24 pop\n" + - " 25 getstatic Value.NAME : java.lang.String [39]\n" + - " 28 pop\n" + - " 29 getstatic Value.NAME : java.lang.String [39]\n" + - " 32 pop\n" + - " 33 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 20]\n" + - " [pc: 4, line: 19]\n" + - " [pc: 13, line: 21]\n" + - " [pc: 21, line: 22]\n" + - " [pc: 25, line: 23]\n" + - " [pc: 29, line: 24]\n" + - " [pc: 33, line: 25]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 34] local: this index: 0 type: B\n" + - " [pc: 0, pc: 34] local: param index: 1 type: Value\n"; - - File f = new File(OUTPUT_DIR + File.separator + "B.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation -public void test1040() throws Exception { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "interface I {\n" + - " Value CONST = A.foo(\"[I.CONST]\");\n" + - "}\n" + - "class Value {\n" + - " static String NAME = \"\";\n" + - " V v;\n" + - " Value(V v) {\n" + - " this.v = v;\n" + - " }\n" + - "}\n" + - "class A {\n" + - " static Value foo(String str) {\n" + - " System.out.print(str);\n" + - " return new Value(\"str\");\n" + - " }\n" + - "}\n" + - "class B implements I {\n" + - " static Value LOCAL_STATIC = A.foo(\"[B.LOCAL_STATIC]\");\n" + - " Value local_field = A.foo(\"[B.local_field]\");\n" + - " B(Value param) {\n" + - " String i = this.CONST.NAME; // keep for possible \n" + - " String k = this.LOCAL_STATIC.NAME; // may optimize out\n" + - " String l = this.local_field.NAME; // may optimize out\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new B(new Value(\"[PARAM]\"));\n" + - " }\n" + - "}", // ================= - }, - "[B.LOCAL_STATIC][B.local_field][I.CONST]", - null, - false, - null, - options, - null); - // check the reference to I.CONST still got generated (for invocation side-effect) - String expectedOutput = - " // Method descriptor #28 (LValue;)V\n" + - " // Signature: (LValue;)V\n" + - " // Stack: 2, Locals: 2\n" + - " B(Value param);\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [30]\n" + - " 4 aload_0 [this]\n" + - " 5 ldc [32]\n" + - " 7 invokestatic A.foo(java.lang.String) : Value [17]\n" + - " 10 putfield B.local_field : Value [34]\n" + - " 13 getstatic B.CONST : Value [36]\n" + - " 16 pop\n" + - " 17 getstatic Value.NAME : java.lang.String [39]\n" + - " 20 pop\n" + - " 21 getstatic Value.NAME : java.lang.String [39]\n" + - " 24 pop\n" + - " 25 getstatic Value.NAME : java.lang.String [39]\n" + - " 28 pop\n" + - " 29 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 20]\n" + - " [pc: 4, line: 19]\n" + - " [pc: 13, line: 21]\n" + - " [pc: 21, line: 22]\n" + - " [pc: 25, line: 23]\n" + - " [pc: 29, line: 24]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 30] local: this index: 0 type: B\n" + - " [pc: 0, pc: 30] local: param index: 1 type: Value\n"; - - File f = new File(OUTPUT_DIR + File.separator + "B.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159245 -public void test1041() { - this.runNegativeTest( - new String[] { - "p/X.java", - "package p;\n" + - "\n" + - "public class X {\n" + - " {\n" + - " X rawx = null;\n" + - " X[] rawxs = { rawx };\n" + - " System.out.println(rawxs.length);\n" + - " }\n" + - " {\n" + - " p.X rawx = null;\n" + - " p.X[] rawxs = { rawx };\n" + - " System.out.println(rawxs.length);\n" + - " }\n" + - " Zork z;\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in p\\X.java (at line 5)\n" + - " X rawx = null;\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in p\\X.java (at line 6)\n" + - " X[] rawxs = { rawx };\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in p\\X.java (at line 10)\n" + - " p.X rawx = null;\n" + - " ^^^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "4. WARNING in p\\X.java (at line 11)\n" + - " p.X[] rawxs = { rawx };\n" + - " ^^^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "5. ERROR in p\\X.java (at line 14)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159818 -public void test1042() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public void foo(T x) {\n" + - " Class c = x.getClass();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Class c = x.getClass();\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 -public void test1043() { - this.runNegativeTest( - new String[] { - "A.java", - "class A {\n" + - " T t;\n" + - " S s;\n" + - " void test(A a) {\n" + - " this.t = this.s; //fine\n" + - " a.t = a.s;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in A.java (at line 6)\n" + - " a.t = a.s;\n" + - " ^^^\n" + - "Type mismatch: cannot convert from capture#4-of ? extends S to capture#1-of ? extends Long\n" + - "----------\n", - JavacTestOptions.EclipseJustification.EclipseBug159214); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 - variation -public void test1044() { - this.runConformTest( - new String[] { - "X.java", - "class X {\n" + - " X x;\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 - variation -public void test1045() { - this.runConformTest( - new String[] { - "X.java", - "class X {\n" + - " X x;\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 -public void test1046() { - this.runConformTest( - new String[] { - "X.java", //======================== - "public interface X {\n" + - " interface Entry {\n" + - " interface Internal extends Entry {\n" + - " Internal createEntry();\n" + - " }\n" + - " }\n" + - "}\n", //======================== - "Y.java", - "public class Y implements X.Entry.Internal {\n" + - " public Internal createEntry() {\n" + - " return null;\n" + - " }\n" + - "}\n" , //======================== - }, - ""); - // compile Y against X binary - this.runConformTest( - new String[] { - "Y.java", //======================== - "public class Y implements X.Entry.Internal {\n" + - " public Internal createEntry() {\n" + - " return null;\n" + - " }\n" + - "}\n" , //======================== - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation -public void test1047() { - this.runConformTest( - new String[] { - "p/X.java", //======================== - "package p;\n" + - "public interface X {\n" + - " interface Entry {\n" + - " interface Internal extends Entry {\n" + - " Internal createEntry();\n" + - " }\n" + - " }\n" + - "}\n", //======================== - "Y.java", - "import p.X.Entry.Internal;\n" + - "public class Y implements Internal {\n" + - " public Internal createEntry() {\n" + - " return null;\n" + - " }\n" + - "}\n" , //======================== - }, - ""); - // compile Y against X binary - this.runConformTest( - new String[] { - "Y.java", //======================== - "import p.X.Entry.Internal;\n" + - "public class Y implements Internal {\n" + - " public Internal createEntry() {\n" + - " return null;\n" + - " }\n" + - "}\n" , //======================== - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation -public void test1048() { - this.runConformTest( - new String[] { - "X.java", //======================== - "public interface X {\n" + - " static class Entry {\n" + - " static abstract class Internal extends Entry {\n" + - " abstract Internal createEntry();\n" + - " }\n" + - " }\n" + - "}\n", //======================== - "Y.java", - "public class Y extends X.Entry.Internal {\n" + - " @Override public Internal createEntry() {\n" + - " return null;\n" + - " }\n" + - "}\n" , //======================== - }, - ""); - // compile Y against X binary - this.runConformTest( - new String[] { - "Y.java", //======================== - "public class Y extends X.Entry.Internal {\n" + - " @Override public Internal createEntry() {\n" + - " return null;\n" + - " }\n" + - "}\n" , //======================== - }, - "", - null, - false, - null); -} -public void test1049() { - this.runConformTest( - new String[] { - "X.java", //======================== - "import java.util.*;\n" + - "public class X {\n" + - "}\n" + - "\n" + - "//===================\n" + - "interface FooHandle> extends BarHandle {}\n" + - "interface Foo> extends FooHandle, Bar {\n" + - " FooHandle foo();\n" + - "}\n" + - "//===================\n" + - "interface EveHandle> extends SimpleHandle {}\n" + - "interface Eve> extends Simple, EveHandle {\n" + - " List foo();\n" + - " BazHandle handles();\n" + - "}\n" + - "\n" + - "//===================\n" + - "interface BobHandle extends BillHandle {}\n" + - "interface Bob extends BobHandle, Bill {}\n" + - "\n" + - "//===================\n" + - "interface BarHandle> extends BazHandle {\n" + - " boolean same(BarHandle o);\n" + - "}\n" + - "interface Bar> extends Baz, BarHandle {\n" + - " BarHandle handle();\n" + - "}\n" + - "\n" + - "//===================\n" + - "interface BazHandle> {\n" + - " T baz();\n" + - " boolean same(BazHandle o);\n" + - "}\n" + - "interface Baz> extends BazHandle {\n" + - " BazHandle handle();\n" + - " T baz();\n" + - "}\n" + - "\n" + - "//===================\n" + - "interface BillHandle extends FooHandle {}\n" + - "interface Bill extends BillHandle, Foo {}\n" + - "\n" + - "//===================\n" + - "interface SimpleHandle extends BazHandle {}\n" + - "interface Simple extends Baz, SimpleHandle {}\n" + - "\n" + - "//===================\n" + - "interface KeyHandle extends FooHandle {}\n" + - "interface Key extends Foo, KeyHandle {}\n" + - "\n" + - "//===================\n" + - "interface ClydeHandle extends BillHandle {}\n" + - "interface Clyde extends ClydeHandle, Bill {\n" + - " void add(BobHandle h);\n" + - " public List handles();\n" + - "}\n" + - "\n" + - "//===================\n" + - "interface FredHandle> extends BarHandle {}\n" + - "interface Fred> extends FredHandle, Bar {}\n" + - "\n", // ================= - }, - ""); -} -public void test1050() { - String expectedOutput = - "xxx\n" + - "true\n" + - "ClassCastException: Object[] cannot be cast to String[]\n" + - "ClassCastException: Object[] cannot be cast to String[]"; - - this.runConformTest( - new String[] { - "X.java", //======================== - "class Container {\n" + - " public Container() {\n" + - " data = (E[]) new Object[100];\n" + - " }\n" + - " protected E[] data;\n" + - " protected int size;\n" + - " E get(int index) {\n" + - " return data[index];\n" + - " }\n" + - " void add(E object) {\n" + - " data[size++] = object;\n" + - " }\n" + - " E[] data() {\n" + - " return data;\n" + - " }\n" + - "}\n" + - "class StringContainer extends Container {\n" + - " public StringContainer() {\n" + - " }\n" + - " public void doSomething() {\n" + - " add(\"xxx\");\n" + - " System.out.println(get(0));\n" + - " System.out.println((\"\" + data()).\n" + - " startsWith(\"[Ljava.lang.Object;@\"));\n" + - " try {\n" + - " System.out.println(data[0]);\n" + - " } catch (ClassCastException e) {\n" + - " System.out.println(\"ClassCastException: Object[] cannot be cast to String[]\");\n" + - " }\n" + - " try {\n" + - " System.out.println(data()[0]);\n" + - " } catch (ClassCastException e) {\n" + - " System.out.println(\"ClassCastException: Object[] cannot be cast to String[]\");\n" + - " }\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " StringContainer x = new StringContainer();\n" + - " x.doSomething();\n" + - " }\n" + - "}", // ================= - }, - expectedOutput); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114088 -public void test1051() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public interface Intf {\n" + - " void foo(List.Inner> ls);\n" + - " }\n" + - "\n" + - " public class Conc {\n" + - " Intf impl;\n" + - " public Conc(Intf impl) {\n" + - " this.impl = impl;\n" + - " }\n" + - " public class Inner { }\n" + - "\n" + - " public void bar(List.Inner> ls) {\n" + - " impl.foo(ls);\n" + - " }\n" + - " }\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115691 -public void test1052() { - Map options = this.getCompilerOptions(); - options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); - options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); - options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); - this.runConformTest( - new String[] { - "X.java", - "public class X extends java.util.ArrayList {\n" + - " private static final long serialVersionUID = 713223190582506215L;\n" + - " static void test() {\n" + - " java.util.ArrayList a1 = new X();\n" + - " X b1 = (X) a1;\n" + - " X c1 = X.class.cast(a1);\n" + - " java.util.ArrayList a2 = new X();\n" + - " X b2 = (X) a2;\n" + - " }\n" + - "}", - }, - "", - null, - true, - null, - options, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122163 -public void test1053() { - this.runConformTest( - new String[] { - "X.java", - "class X {\n" + - " class innerclass {\n" + - " void foo() {\n" + - " X c = X.this;\n" + - " }\n" + - " }\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142935 -public void test1054() { - Map customOptions = getCompilerOptions(); - // check no unsafe type operation problem is issued - customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - String expectedOutput = - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " Bar bar= clazz.getAnnotation(Bar.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to Bar\n" + - "----------\n"; - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.annotation.Retention;\r\n" + - "import java.lang.annotation.RetentionPolicy;\r\n" + - "import java.lang.reflect.Method;\r\n" + - "\r\n" + - "@Bar\r\n" + - "public class X {\r\n" + - "\r\n" + - " @Bar\r\n" + - " public void bar() throws Exception {\r\n" + - " Class clazz= X.class;\r\n" + - " Bar bar= clazz.getAnnotation(Bar.class);\n" + - " Method method= clazz.getMethod(\"bar\");\r\n" + - " Bar bar2= method.getAnnotation(Bar.class);\r\n" + - " }\r\n" + - "}\r\n" + - "\r\n" + - "@Retention(RetentionPolicy.RUNTIME)\r\n" + - "@interface Bar {\r\n" + - "}", - }, - expectedOutput, - null, - true, - customOptions); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142935 -public void test1055() { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.annotation.Retention;\r\n" + - "import java.lang.annotation.RetentionPolicy;\r\n" + - "import java.lang.reflect.Method;\r\n" + - "\r\n" + - "@Bar\r\n" + - "public class X {\r\n" + - "\r\n" + - " @Bar\r\n" + - " public void bar() throws Exception {\r\n" + - " Class clazz= X.class;\r\n" + - " Bar bar= clazz.getAnnotation(Bar.class);\n" + - " Method method= clazz.getMethod(\"bar\");\r\n" + - " Bar bar2= method.getAnnotation(Bar.class);\r\n" + - " }\r\n" + - "}\r\n" + - "\r\n" + - "@Retention(RetentionPolicy.RUNTIME)\r\n" + - "@interface Bar {\r\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162400 -public void test1056() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static T foo() {\n" + - " return null;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " String[] s = { foo() };\n" + - " } \n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159738 -public void test1057() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "\n" + - "class GenericType & Map.Entry> {\n" + - " public void doSomething(E e) {\n" + - " System.out.println(e.compareTo(e.getValue()));\n" + - " }\n" + - "}\n" + - "class ConcreteType {\n" + - " public void doSomething(Object obj) {\n" + - " System.out.println(((Comparable) obj).compareTo(((Map.Entry) obj).getValue()));\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " new GenericType().doSomething(\"a1\");\n" + - " } catch (Throwable e) {\n" + - " System.out.print(\"[\" + e.getClass().getSimpleName() + \":1]\");\n" + - " }\n" + - " try {\n" + - " new ConcreteType().doSomething(\"a2\");\n" + - " } catch (Throwable e) {\n" + - " System.out.print(\"[\" + e.getClass().getSimpleName() + \":2]\");\n" + - " }\n" + - " }\n" + - "}\n", // =================, - }, - "[ClassCastException:1][ClassCastException:2]"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 -public void test1058() throws Exception { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", // ================= - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " int foo = 0;\n" + - " String bar = \"zero\";\n" + - " System.out.println((foo != 0 ? foo : bar).compareTo(null));\n" + - " } catch(NullPointerException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}", // ================= - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - String expectedOutput = - " // Method descriptor #15 ([Ljava/lang/String;)V\n" + - " // Stack: 3, Locals: 3\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 iconst_0\n" + - " 1 istore_1 [foo]\n" + - " 2 ldc [16]\n" + - " 4 astore_2 [bar]\n" + - " 5 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + - " 8 iload_1 [foo]\n" + - " 9 ifeq 19\n" + - " 12 iload_1 [foo]\n" + - " 13 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [24]\n" + - " 16 goto 20\n" + - " 19 aload_2 [bar]\n" + - " 20 aconst_null\n" + - " 21 invokeinterface java.lang.Comparable.compareTo(java.lang.Object) : int [30] [nargs: 2]\n" + - " 26 invokevirtual java.io.PrintStream.println(int) : void [36]\n" + - " 29 goto 41\n" + - " 32 astore_1 [e]\n" + - " 33 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + - " 36 ldc [42]\n" + - " 38 invokevirtual java.io.PrintStream.println(java.lang.String) : void [44]\n" + - " 41 return\n" + - " Exception Table:\n" + - " [pc: 0, pc: 29] -> 32 when : java.lang.NullPointerException\n" + - " Line numbers:\n" + - " [pc: 0, line: 4]\n" + - " [pc: 2, line: 5]\n" + - " [pc: 5, line: 6]\n" + - " [pc: 32, line: 7]\n" + - " [pc: 33, line: 8]\n" + - " [pc: 41, line: 10]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 42] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 2, pc: 32] local: foo index: 1 type: int\n" + - " [pc: 5, pc: 32] local: bar index: 2 type: java.lang.String\n" + - " [pc: 33, pc: 41] local: e index: 1 type: java.lang.NullPointerException\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160795 -public void test1059() { - this.runNegativeTest( - new String[] { - "A.java", // ================= - "class A {\n" + - " S test(A a) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " void m() {\n" + - " A a = null;\n" + - " Number b = test(a);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in A.java (at line 8)\n" + - " Number b = test(a);\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from capture#1-of ? to Number\n" + - "----------\n"); -} -public void test1060() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", // ================= - "import java.util.Collection;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public static void m(List list,Collection coll) {\n" + - " m(list,coll);\n" + - " }\n" + - "}", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159752 -public void test1061() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "predicate/Predicate.java", // ================= - "package predicate;\n" + - "public interface Predicate {\n" + - " public boolean evaluate(T object);\n" + - "}\n" + - "final class AndPredicate implements Predicate {\n" + - " private final Predicate iPredicate1;\n" + - " private final Predicate iPredicate2;\n" + - " public static Predicate getInstance(Predicate predicate1,\n" + - " Predicate predicate2) {\n" + - " if (predicate1 == null || predicate2 == null) {\n" + - " throw new IllegalArgumentException(\"Predicate must not be null\");\n" + - " }\n" + - " return new AndPredicate(predicate1, predicate2);\n" + - " }\n" + - " public AndPredicate(Predicate predicate1,\n" + - " Predicate predicate2) {\n" + - " super();\n" + - " iPredicate1 = predicate1;\n" + - " iPredicate2 = predicate2;\n" + - " }\n" + - " public boolean evaluate(T object) {\n" + - " return iPredicate1.evaluate(object) && iPredicate2.evaluate(object);\n" + - " }\n" + - "}\n" + - "class PredicateUtils {\n" + - "\n" + - " public static Predicate andPredicate(\n" + - " Predicate predicate1, Predicate predicate2) {\n" + - " return AndPredicate.getInstance(predicate1, predicate2);\n" + - " }\n" + - "}", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 -public void test1062() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.HashSet;\n" + - "import java.util.Iterator;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Set set = new HashSet();\n" + - " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + - " Set element1 = iterator.next();\n" + - " Set element2 = (Set) iterator.next(); // warning\n" + - " }\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Set element1 = iterator.next();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to Set\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " Set element2 = (Set) iterator.next(); // warning\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to Set\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation -public void test1063() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.HashSet;\n" + - "import java.util.Iterator;\n" + - "import java.util.Set;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Set set = new HashSet();\n" + - " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + - " Set element1 = iterator.next();\n" + - " Set element2 = (Set) iterator.next(); // warning\n" + - " }\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Set element1 = iterator.next();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Cloneable to Set\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " Set element2 = (Set) iterator.next(); // warning\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Cloneable to Set\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation -public void test1064() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.HashSet;\n" + - "import java.util.Iterator;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " HashSet set = new HashSet();\n" + - " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + - " HashSet element1 = iterator.next();\n" + - " HashSet element2 = (HashSet) iterator.next();\n" + - " }\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " HashSet element1 = iterator.next();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to HashSet\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " HashSet element2 = (HashSet) iterator.next();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to HashSet\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 - variation -public void test1065() throws Exception { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", // ================= - "public class X {\n" + - " void testFoo(boolean t, A a, B b) {\n" + - " System.out.print((t ? a : b).foo());\n" + - " }\n" + - " void testBar(boolean t, A a, B b) {\n" + - " System.out.print((t ? a : b).bar());\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " A a = new A();\n" + - " B b = new B();\n" + - " x.testFoo(true, a, b);\n" + - " x.testFoo(false, a, b);\n" + - " x.testBar(true, a, b);\n" + - " x.testBar(false, a, b);\n" + - " }\n" + - "}\n" + - "interface Foo { String foo(); }\n" + - "interface Bar { String bar(); }\n" + - "class A implements Foo, Bar {\n" + - " public String foo() { return \"[A#foo()]\"; }\n" + - " public String bar() { return \"[A#bar()]\"; }\n" + - "}\n" + - "class B implements Foo, Bar {\n" + - " public String foo() { return \"[B#foo()]\"; }\n" + - " public String bar() { return \"[B#bar()]\"; }\n" + - "}\n", // ================= - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "[A#foo()][B#foo()][A#bar()][B#bar()]" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); - // check presence of checkcast in #testFoo() and #testBar() - String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_5 - ? " // Method descriptor #15 (ZLA;LB;)V\n" + - " // Stack: 2, Locals: 4\n" + - " void testFoo(boolean t, A a, B b);\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + - " 3 iload_1 [t]\n" + - " 4 ifeq 11\n" + - " 7 aload_2 [a]\n" + - " 8 goto 12\n" + - " 11 aload_3 [b]\n" + - " 12 invokeinterface Foo.foo() : java.lang.String [22] [nargs: 1]\n" + - " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + - " 20 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 3]\n" + - " [pc: 20, line: 4]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 21] local: this index: 0 type: X\n" + - " [pc: 0, pc: 21] local: t index: 1 type: boolean\n" + - " [pc: 0, pc: 21] local: a index: 2 type: A\n" + - " [pc: 0, pc: 21] local: b index: 3 type: B\n" + - " \n" + - " // Method descriptor #15 (ZLA;LB;)V\n" + - " // Stack: 2, Locals: 4\n" + - " void testBar(boolean t, A a, B b);\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + - " 3 iload_1 [t]\n" + - " 4 ifeq 11\n" + - " 7 aload_2 [a]\n" + - " 8 goto 12\n" + - " 11 aload_3 [b]\n" + - " 12 checkcast Bar [41]\n" + - " 15 invokeinterface Bar.bar() : java.lang.String [43] [nargs: 1]\n" + - " 20 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + - " 23 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 6]\n" + - " [pc: 23, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 24] local: this index: 0 type: X\n" + - " [pc: 0, pc: 24] local: t index: 1 type: boolean\n" + - " [pc: 0, pc: 24] local: a index: 2 type: A\n" + - " [pc: 0, pc: 24] local: b index: 3 type: B\n" - : " // Method descriptor #15 (ZLA;LB;)V\n" + - " // Stack: 2, Locals: 4\n" + - " void testFoo(boolean t, A a, B b);\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + - " 3 iload_1 [t]\n" + - " 4 ifeq 11\n" + - " 7 aload_2 [a]\n" + - " 8 goto 12\n" + - " 11 aload_3 [b]\n" + - " 12 invokeinterface Foo.foo() : java.lang.String [22] [nargs: 1]\n" + - " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + - " 20 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 3]\n" + - " [pc: 20, line: 4]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 21] local: this index: 0 type: X\n" + - " [pc: 0, pc: 21] local: t index: 1 type: boolean\n" + - " [pc: 0, pc: 21] local: a index: 2 type: A\n" + - " [pc: 0, pc: 21] local: b index: 3 type: B\n" + - " Stack map table: number of frames 2\n" + - " [pc: 11, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + - " [pc: 12, full, stack: {java.io.PrintStream, Foo}, locals: {X, int, A, B}]\n" + - " \n" + - " // Method descriptor #15 (ZLA;LB;)V\n" + - " // Stack: 2, Locals: 4\n" + - " void testBar(boolean t, A a, B b);\n" + - " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + - " 3 iload_1 [t]\n" + - " 4 ifeq 11\n" + - " 7 aload_2 [a]\n" + - " 8 goto 12\n" + - " 11 aload_3 [b]\n" + - " 12 checkcast Bar [46]\n" + - " 15 invokeinterface Bar.bar() : java.lang.String [48] [nargs: 1]\n" + - " 20 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + - " 23 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 6]\n" + - " [pc: 23, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 24] local: this index: 0 type: X\n" + - " [pc: 0, pc: 24] local: t index: 1 type: boolean\n" + - " [pc: 0, pc: 24] local: a index: 2 type: A\n" + - " [pc: 0, pc: 24] local: b index: 3 type: B\n" + - " Stack map table: number of frames 2\n" + - " [pc: 11, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + - " [pc: 12, full, stack: {java.io.PrintStream, Foo}, locals: {X, int, A, B}]\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 - variation -public void test1066() throws Exception { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " List l = new ArrayList();\n" + - " l.add(\"zork\");\n" + - " List la = l;\n" + - " List lb = l;\n" + - " boolean t = true, f = false;\n" + - " try {\n" + - " System.out.print((t ? la.get(0) : lb.get(0)).foo());\n" + - " } catch (Throwable e) {\n" + - " System.out.print(\"[\" + e.getClass().getSimpleName() + \":foo(1)]\");\n" + - " } \n" + - " try {\n" + - " System.out.print((f ? la.get(0) : lb.get(0)).foo());\n" + - " } catch (Throwable e) {\n" + - " System.out.print(\"[\" + e.getClass().getSimpleName() + \":foo(2)]\");\n" + - " } \n" + - " try {\n" + - " System.out.print((t ? la.get(0) : lb.get(0)).bar());\n" + - " } catch (Throwable e) {\n" + - " System.out.print(\"[\" + e.getClass().getSimpleName() + \":bar(1)]\");\n" + - " } \n" + - " try {\n" + - " System.out.print((f ? la.get(0) : lb.get(0)).bar());\n" + - " } catch (Throwable e) {\n" + - " System.out.print(\"[\" + e.getClass().getSimpleName() + \":bar(2)]\");\n" + - " } \n" + - " }\n" + - "}\n" + - "interface Foo { String foo(); }\n" + - "interface Bar { String bar(); }\n" + - "abstract class A implements Foo, Bar { }\n" + - "abstract class B implements Foo, Bar { }\n", // ================= - }, - "[ClassCastException:foo(1)][ClassCastException:foo(2)][ClassCastException:bar(1)][ClassCastException:bar(2)]"); - // check presence of checkcast - String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_5 - ? " // Stack: 4, Locals: 8\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 new X [1]\n" + - " 3 dup\n" + - " 4 invokespecial X() [16]\n" + - " 7 astore_1 [x]\n" + - " 8 new java.util.ArrayList [17]\n" + - " 11 dup\n" + - " 12 invokespecial java.util.ArrayList() [19]\n" + - " 15 astore_2 [l]\n" + - " 16 aload_2 [l]\n" + - " 17 ldc [20]\n" + - " 19 invokeinterface java.util.List.add(java.lang.Object) : boolean [22] [nargs: 2]\n" + - " 24 pop\n" + - " 25 aload_2 [l]\n" + - " 26 astore_3 [la]\n" + - " 27 aload_2 [l]\n" + - " 28 astore 4 [lb]\n" + - " 30 iconst_1\n" + - " 31 istore 5 [t]\n" + - " 33 iconst_0\n" + - " 34 istore 6 [f]\n" + - " 36 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 39 iload 5 [t]\n" + - " 41 ifeq 57\n" + - " 44 aload_3 [la]\n" + - " 45 iconst_0\n" + - " 46 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 51 checkcast Foo [38]\n" + - " 54 goto 68\n" + - " 57 aload 4 [lb]\n" + - " 59 iconst_0\n" + - " 60 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 65 checkcast Foo [38]\n" + - " 68 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + - " 73 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 76 goto 115\n" + - " 79 astore 7 [e]\n" + - " 81 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 84 new java.lang.StringBuilder [50]\n" + - " 87 dup\n" + - " 88 ldc [52]\n" + - " 90 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 93 aload 7 [e]\n" + - " 95 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 98 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 101 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 104 ldc [69]\n" + - " 106 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 109 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 112 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 115 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 118 iload 6 [f]\n" + - " 120 ifeq 136\n" + - " 123 aload_3 [la]\n" + - " 124 iconst_0\n" + - " 125 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 130 checkcast Foo [38]\n" + - " 133 goto 147\n" + - " 136 aload 4 [lb]\n" + - " 138 iconst_0\n" + - " 139 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 144 checkcast Foo [38]\n" + - " 147 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + - " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 155 goto 194\n" + - " 158 astore 7 [e]\n" + - " 160 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 163 new java.lang.StringBuilder [50]\n" + - " 166 dup\n" + - " 167 ldc [52]\n" + - " 169 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 172 aload 7 [e]\n" + - " 174 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 177 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 180 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 183 ldc [74]\n" + - " 185 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 188 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 191 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 194 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 197 iload 5 [t]\n" + - " 199 ifeq 215\n" + - " 202 aload_3 [la]\n" + - " 203 iconst_0\n" + - " 204 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 209 checkcast Foo [38]\n" + - " 212 goto 226\n" + - " 215 aload 4 [lb]\n" + - " 217 iconst_0\n" + - " 218 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 223 checkcast Foo [38]\n" + - " 226 checkcast Bar [76]\n" + - " 229 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + - " 234 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 237 goto 276\n" + - " 240 astore 7 [e]\n" + - " 242 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 245 new java.lang.StringBuilder [50]\n" + - " 248 dup\n" + - " 249 ldc [52]\n" + - " 251 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 254 aload 7 [e]\n" + - " 256 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 259 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 262 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 265 ldc [81]\n" + - " 267 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 270 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 273 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 276 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 279 iload 6 [f]\n" + - " 281 ifeq 297\n" + - " 284 aload_3 [la]\n" + - " 285 iconst_0\n" + - " 286 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 291 checkcast Foo [38]\n" + - " 294 goto 308\n" + - " 297 aload 4 [lb]\n" + - " 299 iconst_0\n" + - " 300 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 305 checkcast Foo [38]\n" + - " 308 checkcast Bar [76]\n" + - " 311 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + - " 316 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 319 goto 358\n" + - " 322 astore 7 [e]\n" + - " 324 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 327 new java.lang.StringBuilder [50]\n" + - " 330 dup\n" + - " 331 ldc [52]\n" + - " 333 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 336 aload 7 [e]\n" + - " 338 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 341 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 344 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 347 ldc [83]\n" + - " 349 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 352 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 355 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 358 return\n" + - " Exception Table:\n" + - " [pc: 36, pc: 76] -> 79 when : java.lang.Throwable\n" + - " [pc: 115, pc: 155] -> 158 when : java.lang.Throwable\n" + - " [pc: 194, pc: 237] -> 240 when : java.lang.Throwable\n" + - " [pc: 276, pc: 319] -> 322 when : java.lang.Throwable\n" + - " Line numbers:\n" + - " [pc: 0, line: 4]\n" + - " [pc: 8, line: 5]\n" + - " [pc: 16, line: 6]\n" + - " [pc: 25, line: 7]\n" + - " [pc: 27, line: 8]\n" + - " [pc: 30, line: 9]\n" + - " [pc: 36, line: 11]\n" + - " [pc: 79, line: 12]\n" + - " [pc: 81, line: 13]\n" + - " [pc: 115, line: 16]\n" + - " [pc: 158, line: 17]\n" + - " [pc: 160, line: 18]\n" + - " [pc: 194, line: 21]\n" + - " [pc: 240, line: 22]\n" + - " [pc: 242, line: 23]\n" + - " [pc: 276, line: 26]\n" + - " [pc: 322, line: 27]\n" + - " [pc: 324, line: 28]\n" + - " [pc: 358, line: 30]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 359] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 8, pc: 359] local: x index: 1 type: X\n" + - " [pc: 16, pc: 359] local: l index: 2 type: java.util.List\n" + - " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + - " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + - " [pc: 33, pc: 359] local: t index: 5 type: boolean\n" + - " [pc: 36, pc: 359] local: f index: 6 type: boolean\n" + - " [pc: 81, pc: 115] local: e index: 7 type: java.lang.Throwable\n" + - " [pc: 160, pc: 194] local: e index: 7 type: java.lang.Throwable\n" + - " [pc: 242, pc: 276] local: e index: 7 type: java.lang.Throwable\n" + - " [pc: 324, pc: 358] local: e index: 7 type: java.lang.Throwable\n" + - " Local variable type table:\n" + - " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + - " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" - : " // Method descriptor #15 ([Ljava/lang/String;)V\n" + - " // Stack: 4, Locals: 8\n" + - " public static void main(java.lang.String[] args);\n" + - " 0 new X [1]\n" + - " 3 dup\n" + - " 4 invokespecial X() [16]\n" + - " 7 astore_1 [x]\n" + - " 8 new java.util.ArrayList [17]\n" + - " 11 dup\n" + - " 12 invokespecial java.util.ArrayList() [19]\n" + - " 15 astore_2 [l]\n" + - " 16 aload_2 [l]\n" + - " 17 ldc [20]\n" + - " 19 invokeinterface java.util.List.add(java.lang.Object) : boolean [22] [nargs: 2]\n" + - " 24 pop\n" + - " 25 aload_2 [l]\n" + - " 26 astore_3 [la]\n" + - " 27 aload_2 [l]\n" + - " 28 astore 4 [lb]\n" + - " 30 iconst_1\n" + - " 31 istore 5 [t]\n" + - " 33 iconst_0\n" + - " 34 istore 6 [f]\n" + - " 36 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 39 iload 5 [t]\n" + - " 41 ifeq 57\n" + - " 44 aload_3 [la]\n" + - " 45 iconst_0\n" + - " 46 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 51 checkcast Foo [38]\n" + - " 54 goto 68\n" + - " 57 aload 4 [lb]\n" + - " 59 iconst_0\n" + - " 60 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 65 checkcast Foo [38]\n" + - " 68 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + - " 73 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 76 goto 115\n" + - " 79 astore 7 [e]\n" + - " 81 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 84 new java.lang.StringBuilder [50]\n" + - " 87 dup\n" + - " 88 ldc [52]\n" + - " 90 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 93 aload 7 [e]\n" + - " 95 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 98 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 101 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 104 ldc [69]\n" + - " 106 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 109 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 112 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 115 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 118 iload 6 [f]\n" + - " 120 ifeq 136\n" + - " 123 aload_3 [la]\n" + - " 124 iconst_0\n" + - " 125 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 130 checkcast Foo [38]\n" + - " 133 goto 147\n" + - " 136 aload 4 [lb]\n" + - " 138 iconst_0\n" + - " 139 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 144 checkcast Foo [38]\n" + - " 147 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + - " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 155 goto 194\n" + - " 158 astore 7 [e]\n" + - " 160 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 163 new java.lang.StringBuilder [50]\n" + - " 166 dup\n" + - " 167 ldc [52]\n" + - " 169 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 172 aload 7 [e]\n" + - " 174 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 177 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 180 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 183 ldc [74]\n" + - " 185 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 188 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 191 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 194 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 197 iload 5 [t]\n" + - " 199 ifeq 215\n" + - " 202 aload_3 [la]\n" + - " 203 iconst_0\n" + - " 204 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 209 checkcast Foo [38]\n" + - " 212 goto 226\n" + - " 215 aload 4 [lb]\n" + - " 217 iconst_0\n" + - " 218 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 223 checkcast Foo [38]\n" + - " 226 checkcast Bar [76]\n" + - " 229 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + - " 234 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 237 goto 276\n" + - " 240 astore 7 [e]\n" + - " 242 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 245 new java.lang.StringBuilder [50]\n" + - " 248 dup\n" + - " 249 ldc [52]\n" + - " 251 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 254 aload 7 [e]\n" + - " 256 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 259 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 262 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 265 ldc [81]\n" + - " 267 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 270 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 273 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 276 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 279 iload 6 [f]\n" + - " 281 ifeq 297\n" + - " 284 aload_3 [la]\n" + - " 285 iconst_0\n" + - " 286 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 291 checkcast Foo [38]\n" + - " 294 goto 308\n" + - " 297 aload 4 [lb]\n" + - " 299 iconst_0\n" + - " 300 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + - " 305 checkcast Foo [38]\n" + - " 308 checkcast Bar [76]\n" + - " 311 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + - " 316 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 319 goto 358\n" + - " 322 astore 7 [e]\n" + - " 324 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + - " 327 new java.lang.StringBuilder [50]\n" + - " 330 dup\n" + - " 331 ldc [52]\n" + - " 333 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + - " 336 aload 7 [e]\n" + - " 338 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + - " 341 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + - " 344 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 347 ldc [83]\n" + - " 349 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + - " 352 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + - " 355 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + - " 358 return\n" + - " Exception Table:\n" + - " [pc: 36, pc: 76] -> 79 when : java.lang.Throwable\n" + - " [pc: 115, pc: 155] -> 158 when : java.lang.Throwable\n" + - " [pc: 194, pc: 237] -> 240 when : java.lang.Throwable\n" + - " [pc: 276, pc: 319] -> 322 when : java.lang.Throwable\n" + - " Line numbers:\n" + - " [pc: 0, line: 4]\n" + - " [pc: 8, line: 5]\n" + - " [pc: 16, line: 6]\n" + - " [pc: 25, line: 7]\n" + - " [pc: 27, line: 8]\n" + - " [pc: 30, line: 9]\n" + - " [pc: 36, line: 11]\n" + - " [pc: 79, line: 12]\n" + - " [pc: 81, line: 13]\n" + - " [pc: 115, line: 16]\n" + - " [pc: 158, line: 17]\n" + - " [pc: 160, line: 18]\n" + - " [pc: 194, line: 21]\n" + - " [pc: 240, line: 22]\n" + - " [pc: 242, line: 23]\n" + - " [pc: 276, line: 26]\n" + - " [pc: 322, line: 27]\n" + - " [pc: 324, line: 28]\n" + - " [pc: 358, line: 30]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 359] local: args index: 0 type: java.lang.String[]\n" + - " [pc: 8, pc: 359] local: x index: 1 type: X\n" + - " [pc: 16, pc: 359] local: l index: 2 type: java.util.List\n" + - " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + - " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + - " [pc: 33, pc: 359] local: t index: 5 type: boolean\n" + - " [pc: 36, pc: 359] local: f index: 6 type: boolean\n" + - " [pc: 81, pc: 115] local: e index: 7 type: java.lang.Throwable\n" + - " [pc: 160, pc: 194] local: e index: 7 type: java.lang.Throwable\n" + - " [pc: 242, pc: 276] local: e index: 7 type: java.lang.Throwable\n" + - " [pc: 324, pc: 358] local: e index: 7 type: java.lang.Throwable\n" + - " Local variable type table:\n" + - " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + - " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + - " Stack map table: number of frames 16\n" + - " [pc: 57, full, stack: {java.io.PrintStream}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + - " [pc: 68, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + - " [pc: 79, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + - " [pc: 115, same]\n" + - " [pc: 136, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + - " [pc: 147, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + - " [pc: 158, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + - " [pc: 194, same]\n" + - " [pc: 215, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + - " [pc: 226, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + - " [pc: 240, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + - " [pc: 276, same]\n" + - " [pc: 297, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + - " [pc: 308, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + - " [pc: 322, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + - " [pc: 358, same]\n"; - - 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); - } -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162991 -// using only source types -public void test1067() { - this.runConformTest( - new String[] { - "Something.java", - "public interface Something {\n" + - "\n" + - "}", // ================= - "Doing.java", // ================= - "public interface Doing {\n" + - " public T get(Class clazz);\n" + - "}", // ================= - "DoingImpl.java", // ================= - "public class DoingImpl implements Doing {\n" + - " public T get(Class clazz) {\n" + - " return null;\n" + - " }\n" + - "}" // ================= - }, - ""); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162991 -// using source and binary types -public void test1068() { - this.runConformTest( - new String[] { - "Something.java", - "public interface Something {\n" + - "\n" + - "}", // ================= - "Doing.java", // ================= - "public interface Doing {\n" + - " public T get(Class clazz);\n" + - "}", // ================= - }, - ""); - this.runConformTest( - new String[] { - "DoingImpl.java", // ================= - "public class DoingImpl implements Doing {\n" + - " public T get(Class clazz) {\n" + - " return null;\n" + - " }\n" + - "}" // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163262 -public void test1069() { - this.runConformTest( - new String[] { - "Bug.java", // ================= - "public class Bug {\n" + - " void bug() {\n" + - " new Runnable() {\n" + - " public void run() {\n" + - " Bug bug = Bug.this;\n" + - " }\n" + - " };\n" + - " }\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163262 -public void test1070() { - this.runConformTest( - new String[] { - "Bug.java", // ================= - "public class Bug {\n" + - " Bug reproduce() {\n" + - " return Bug.this;\n" + - " }\n" + - "}", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 -public void test1071() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " List x = null;\n" + - " void[] y;\n" + - " void[] foo(void[] arg) {\n" + - " void[] local;\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " List x = null;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " void[] y;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "5. ERROR in X.java (at line 6)\n" + - " void[] local;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 -public void test1072() { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " List x = null;\n" + - " void[] y;\n" + - " void[] foo(void[] arg) {\n" + - " void[] local;\n" + - " Class c = void[].class;\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " List x = null;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " void[] y;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "5. ERROR in X.java (at line 6)\n" + - " void[] local;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "6. ERROR in X.java (at line 7)\n" + - " Class c = void[].class;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n", - null, - true, - options); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 -public void test1073() { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " List x = null;\n" + - " void[] y;\n" + - " void[] foo(void[] arg) {\n" + - " try {\n" + - " void[] local;\n" + - " Class c = void[].class;\n" + - " } catch(void[] e) {\n" + - " }\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " List x = null;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " void[] y;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "5. ERROR in X.java (at line 7)\n" + - " void[] local;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "6. ERROR in X.java (at line 8)\n" + - " Class c = void[].class;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "7. ERROR in X.java (at line 9)\n" + - " } catch(void[] e) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n", - null, - true, - options); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 -public void test1074() { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " List x = null;\n" + - " void[] y;\n" + - " void[] foo(void[] arg) {\n" + - " try {\n" + - " void[] local = new void[0];\n" + - " void[] local1 = new void[]{ null, null };\n" + - " void[] local2 = { null, null };\n" + - " System.out.println((void[]) null);\n" + - " Class c = void[].class;\n" + - " } catch(void[] e) {\n" + - " }\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " List x = null;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " void[] y;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " void[] foo(void[] arg) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "5. ERROR in X.java (at line 7)\n" + - " void[] local = new void[0];\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "6. ERROR in X.java (at line 7)\n" + - " void[] local = new void[0];\n" + - " ^^^^^^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "7. ERROR in X.java (at line 8)\n" + - " void[] local1 = new void[]{ null, null };\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "8. ERROR in X.java (at line 8)\n" + - " void[] local1 = new void[]{ null, null };\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "9. ERROR in X.java (at line 9)\n" + - " void[] local2 = { null, null };\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "10. ERROR in X.java (at line 10)\n" + - " System.out.println((void[]) null);\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "11. ERROR in X.java (at line 11)\n" + - " Class c = void[].class;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "12. ERROR in X.java (at line 12)\n" + - " } catch(void[] e) {\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n", - null, - true, - options); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163680 -public void test1075() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X .J>{\n" + - " public class J implements I{}\n" + - "}\n", - "I.java", - "public interface I {}\n", - "Y.java", - "public class Y extends X {}\n", - }, - // runtime results - "" /* expected output string */); - runConformTest( - // test directory preparation - false /* do not flush output directory */, - new String[] { - "Y.java", - "public class Y extends X {}", - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} - -public void test1076() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " List threads;\n" + - " void foo(String[] strings) {}\n" + - " void bar() {\n" + - " foo(this.threads.toArray(new String[this.threads.size()]));\n" + - " foo(myToArray(this.threads, new String[this.threads.size()]));\n" + - " foo(myToArray2(this.threads, new String[this.threads.size()]));\n" + - " }\n" + - " \n" + - " static T[] myToArray(List list, T[] a) {\n" + - " return list.toArray(a);\n" + - " }\n" + - " static T[] myToArray2(List list, T[] a) {\n" + - " return list.toArray(a);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " foo(myToArray2(this.threads, new String[this.threads.size()]));\n" + - " ^^^^^^^^^^\n" + - "Bound mismatch: The generic method myToArray2(List, T[]) of type X is not applicable for the arguments (List, String[]). The inferred type Thread is not a valid substitute for the bounded parameter \n" + - "----------\n"); -} -// check presence of field hiding warning -public void test1077() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Y {\n" + - " static int foo;\n" + - " }\n" + - " static class Z extends Y {\n" + - " int foo;\n" + - " {\n" + - " foo = 1;\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " int foo;\n" + - " ^^^\n" + - "The field X.Z.foo is hiding a field from type X.Y\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 -public void test1078() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "import java.util.Map;\n" + - "\n" + - "public class X \n" + - "{\n" + - " public static void main(String[] args)\n" + - " {\n" + - " Object object = null;\n" + - "\n" + - " List list = (List)object;//[1]\n" + - "\n" + - " foo((List)object);//[2]\n" + - " foo((List)object);//[3]\n" + - " foo((List)object);//[4]unchecked cast\n" + - " foo((List)object);//[5]\n" + - "\n" + - " foo((Map)object);//[6]\n" + - " foo((Map)object);//[7]\n" + - " foo((Map)object);//[8]unchecked cast\n" + - " foo((Map)object);//[9]unchecked cast\n" + - " foo((Map)object);//[10]unchecked cast\n" + - " foo((Map)object);//[11]unchecked cast\n" + - " foo((Map)object);//[12]\n" + - " Zork z;\n" + - " }\n" + - "\n" + - " public static void foo(List list) {\n" + - " }\n" + - "\n" + - " public static void foo(Map map) {\n" + - " }\n" + - "}", // =================, - }, - // unchecked warnings on [4][5][8][9][10][11][12] - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " List list = (List)object;//[1]\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " List list = (List)object;//[1]\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " foo((List)object);//[2]\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 14)\n" + - " foo((List)object);//[4]unchecked cast\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List\n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " foo((List)object);//[5]\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List\n" + - "----------\n" + - "6. WARNING in X.java (at line 17)\n" + - " foo((Map)object);//[6]\n" + - " ^^^\n" + - "Map is a raw type. References to generic type Map should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 19)\n" + - " foo((Map)object);//[8]unchecked cast\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Map\n" + - "----------\n" + - "8. WARNING in X.java (at line 20)\n" + - " foo((Map)object);//[9]unchecked cast\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Map\n" + - "----------\n" + - "9. WARNING in X.java (at line 21)\n" + - " foo((Map)object);//[10]unchecked cast\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Map\n" + - "----------\n" + - "10. WARNING in X.java (at line 22)\n" + - " foo((Map)object);//[11]unchecked cast\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Map\n" + - "----------\n" + - "11. WARNING in X.java (at line 23)\n" + - " foo((Map)object);//[12]\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Map\n" + - "----------\n" + - "12. ERROR in X.java (at line 24)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation -public void test1079() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " X bar(Object o) {\n" + - " return (AX) o;\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "class AX extends X {}\n", // =================, - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " return (AX) o;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to AX\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation -public void test1080() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " CX foo(X x) {\n" + - " return (CX) x; // unchecked\n" + - " }\n" + - " BX bar(X x) {\n" + - " return (BX) x;\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "class AX extends X {}\n" + - "class BX extends AX {}\n" + - "class CX extends AX {}\n", // =================, - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " return (CX) x; // unchecked\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to CX\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation -public void test1081() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " AX foo(X x) {\n" + - " return (BX) x;\n" + - " }\n" + - "}\n" + - "class AX extends X {}\n" + - "class BX extends AX {}\n", // =================, - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " return (BX) x;\n" + - " ^^^^^^\n" + - "Cannot cast from X to BX\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation -public void test1082() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " CX foo(X x) {\n" + - " return (CX) x; // unchecked\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "class AX extends X {}\n" + - "class CX extends AX {}\n", // =================, - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " return (CX) x; // unchecked\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to CX\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " class CX extends AX {}\n" + - " ^^\n" + - "AX is a raw type. References to generic type AX should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106451 - variation -public void test1083() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.io.Serializable;\n" + - "import java.util.LinkedList;\n" + - "\n" + - "class SerializableList extends LinkedList {\n" + - " private static final long serialVersionUID = 1L; \n" + - "}\n" + - "public class X {\n" + - " @SuppressWarnings({\"nls\", \"unused\"})\n" + - " public static void main(String[] args) {\n" + - " LinkedList linkedList= new LinkedList();\n" + - " linkedList.add(\"Hello\");\n" + - " java.util.List a = linkedList;\n" + - " java.util.List b = (LinkedList) a; // unchecked\n" + - " java.util.List c = (LinkedList) a; // unchecked\n" + - " java.util.List d = (LinkedList) a; // inconvertible / unchecked ?\n" + - " c.get(0).intValue(); // fails at run time\n" + - " d.get(0).gc(); // fails at run time\n" + - " Zork z;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 13)\n" + - " java.util.List b = (LinkedList) a; // unchecked\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to LinkedList\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " java.util.List c = (LinkedList) a; // unchecked\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to LinkedList\n" + - "----------\n" + - "3. WARNING in X.java (at line 15)\n" + - " java.util.List d = (LinkedList) a; // inconvertible / unchecked ?\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from List to LinkedList\n" + - "----------\n" + - "4. ERROR in X.java (at line 18)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 -public void test1084() { - this.runNegativeTest( - new String[] { - "X.java", - "class Y {\n" + - "}\n" + - "class Z {\n" + - "}\n" + - "class X {\n" + - " void foo() {\n" + - " Z> l1 = null;\n" + - " Z l2 = (Z) l1;\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " Z l2 = (Z) l1;\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Z l2 = (Z) l1;\n" + - " ^^^^^^^^^\n" + - "Cannot cast from Z> to Z\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " Z l2 = (Z) l1;\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165291 -public void test1085() { - this.runNegativeTest( - new String[] { - "Y.java", - "class Z {\n" + - " Z z1 = z1;\n" + - " Z[] z2 = z2;\n" + - "}\n" + - "public class Y {\n" + - " E e0 = es[0];\n" + - " E e = e;\n" + - " E[] es = es;\n" + - " E e2 = e2.e;\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in Y.java (at line 2)\n" + - " Z z1 = z1;\n" + - " ^^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "2. ERROR in Y.java (at line 3)\n" + - " Z[] z2 = z2;\n" + - " ^^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "3. ERROR in Y.java (at line 6)\n" + - " E e0 = es[0];\n" + - " ^^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "4. ERROR in Y.java (at line 7)\n" + - " E e = e;\n" + - " ^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "5. ERROR in Y.java (at line 8)\n" + - " E[] es = es;\n" + - " ^^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "6. ERROR in Y.java (at line 9)\n" + - " E e2 = e2.e;\n" + - " ^^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "7. ERROR in Y.java (at line 9)\n" + - " E e2 = e2.e;\n" + - " ^^^^\n" + - "e2.e cannot be resolved or is not a field\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165645 -public void test1086() { - this.runNegativeTest( - new String[] { - "X.java", - "interface IFoo { void foo(); }\n" + - "interface IBar { void bar(); }\n" + - "public class X {\n" + - " class Bar implements IBar { public void bar(){} }\n" + - " void foo(Bar b) {\n" + - " b.foo(); // unbound (Bar is member type)\n" + - " b.bar(); // ok\n" + - " }\n" + - "}\n", // =================, - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " b.foo(); // unbound (Bar is member type)\n" + - " ^^^\n" + - "The method foo() is undefined for the type X.Bar\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165645 - variation -public void test1087() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " static public class M {\n" + - " }\n" + - " static public class M2 extends M {\n" + - " }\n" + - "}\n" + - "\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 -public void test1088() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static public class M {}\n" + - " Zork z;\n" + - " void foo() {\n" + - " class M {} // hides member\n" + - " }\n" + - "}\n" + - "class Y {\n" + - " class Local {}\n" + - " void foo() {\n" + - " class T {}; // hiding warning\n" + - " class Local {};\n" + - " }\n" + - " static void bar() {\n" + - " class T {}; // no hiding warning\n" + - " class Local {}; // no hiding warning\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " class M {} // hides member\n" + - " ^\n" + - "The type M is hiding the type X.M\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " class T {}; // hiding warning\n" + - " ^\n" + - "The nested type T is hiding the type parameter T of type Y\n" + - "----------\n" + - "4. WARNING in X.java (at line 11)\n" + - " class T {}; // hiding warning\n" + - " ^\n" + - "The type T is never used locally\n" + - "----------\n" + - "5. WARNING in X.java (at line 12)\n" + - " class Local {};\n" + - " ^^^^^\n" + - "The type Local is hiding the type Y.Local\n" + - "----------\n" + - "6. WARNING in X.java (at line 12)\n" + - " class Local {};\n" + - " ^^^^^\n" + - "The type Local is never used locally\n" + - "----------\n" + - "7. WARNING in X.java (at line 15)\n" + - " class T {}; // no hiding warning\n" + - " ^\n" + - "The type T is never used locally\n" + - "----------\n" + - "8. WARNING in X.java (at line 16)\n" + - " class Local {}; // no hiding warning\n" + - " ^^^^^\n" + - "The type Local is never used locally\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 - variation -public void test1089() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class U {}\n" + - " void foo(T t) {\n" + - " class T {\n" + - " T t = t;\n" + - " }\n" + - " class U {\n" + - " }\n" + - " }\n" + - "}\n" + - "\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " class T {\n" + - " ^\n" + - "The nested type T is hiding the type parameter T of the generic method foo(T) of type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " T t = t;\n" + - " ^\n" + - "The field T.t is hiding another local variable defined in an enclosing type scope\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " T t = t;\n" + - " ^\n" + - "Cannot reference a field before it is defined\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " class U {\n" + - " ^\n" + - "The type U is hiding the type X.U\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 - variation -public void _test1090() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class T {} // warn hiding type parameter\n" + - " class U {}// warn hiding type parameter+warn param hiding member type\n" + - " \n" + - " void foo() {\n" + - " class Local {\n" + - " class T {} // warn hiding type parameter\n" + - " class U {}// warn hiding type parameter+warn param hiding member type\n" + - " }\n" + - " }\n" + - " static void bar() {\n" + - " class Local {\n" + - " class T {} // no warn\n" + - " class U {} // no warn\n" + - " }\n" + - " }\n" + - "}", // ================= - }, - "???"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165909 -public void test1091() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "\n" + - "public class X {\n" + - " void foo() {\n" + - " Object a = null;\n" + - " Map.Entry aa = (Map.Entry)a; \n" + - " }\n" + - " void bar() {\n" + - " Number a = null;\n" + - " Map.Entry aa = (Map.Entry)a; \n" + - " Zork z;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " Map.Entry aa = (Map.Entry)a; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to Map.Entry\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\n" + - " Map.Entry aa = (Map.Entry)a; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Number to Map.Entry\n" + - "----------\n" + - "3. ERROR in X.java (at line 11)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166490 -public void test1092() { - Map customOptions = this.getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runConformTest( - new String[] { - "Class_01.java", - "public interface Class_01> extends\r\n" + - " Class_09 {\r\n" + - "}", - "Class_02.java", - "public interface Class_02> extends\r\n" + - " Class_10 {\r\n" + - "}", - "Class_03.java", - "public abstract class Class_03, H extends Class_02, P extends Class_06>\r\n" + - " extends Class_08 implements Class_05 {\r\n" + - "}", - "Class_04.java", - "public interface Class_04 extends Class_06, Class_19{\r\n" + - "}", - "Class_05.java", - "public interface Class_05{\r\n" + - "}", - "Class_06.java", - "public interface Class_06> extends\r\n" + - " Class_13, Class_17 {\r\n" + - "}", - "Class_07.java", - "public interface Class_07

> extends\r\n" + - " Class_14 {\r\n" + - "}", - "Class_08.java", - "public abstract class Class_08, H extends Class_10, P extends Class_06>\r\n" + - " extends Class_11 implements Class_05 {\r\n" + - "}", - "Class_09.java", - "public interface Class_09> extends\r\n" + - " Class_13, Class_17 {\r\n" + - "}", - "Class_10.java", - "public interface Class_10> extends\r\n" + - " Class_14 {\r\n" + - "}", - "Class_11.java", - "public abstract class Class_11, H extends Class_14, O>\r\n" + - " extends Class_15 implements Class_05 {\r\n" + - "}", - "Class_12.java", - "public final class Class_12 {\r\n" + - "}", - "Class_13.java", - "public interface Class_13, O>{\r\n" + - "}", - "Class_14.java", - "public interface Class_14, O>{\r\n" + - "}", - "Class_15.java", - "public abstract class Class_15, H extends Class_14, O>\r\n" + - " extends Class_16 {\r\n" + - "}", - "Class_16.java", - "public abstract class Class_16{\r\n" + - "}", - "Class_17.java", - "public interface Class_17{\r\n" + - "}", - "Class_18.java", - "public interface Class_18 extends Class_07{\r\n" + - "}", - "Class_19.java", - "public interface Class_19{\r\n" + - "}", - "MyClass.java", - "abstract class MyClass, H extends Class_02>\r\n" + - " extends Class_03 implements Class_05 {\r\n" + - "}" - }, - "", - null, - true, - null, - customOptions, - null); - - // incremental build - this.runConformTest( - new String[] { - "Class_01.java", - "public interface Class_01> extends\r\n" + - " Class_09 {\r\n" + - "}", - }, - "", - null, - false, - null, - customOptions, - null); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=156952 -// invalid bug - regression test only -public void test1093() { - Map customOptions = this.getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runNegativeTest(new String[] { - "X.java", - "public class X {\n" + - " X foo() {\n" + - " return this;\n" + - " }\n" + - " T bar(T p) {\n" + - " return p;\n" + " }\n" + - " public static void main (String args) {\n" + - " X x1 = new X();\n" + - " System.out.println(x1.foo().bar(\"OK\"));\n" + // OK - " X x2 = new X();\n" + - " System.out.println(x2.foo().bar(\"OK\"));\n" + // KO: type safety issue - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 12)\n" + - " System.out.println(x2.foo().bar(\"OK\"));\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method bar(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n", - null /* no extra class libraries */, - true /* flush output directory */, - customOptions, - false /* do not generate output */, - false /* do not show category */, - false /* do not show warning token */, - false /* do not skip javac for this peculiar test */, - false /* do not perform statements recovery */); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167268 -public void test1094() { - Map customOptions = this.getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runConformTest( - new String[] { - "Crazy.java", - "public interface Crazy {}", - "ExampleFactory.java", - "public interface ExampleFactory {\n" + - " Crazy createCrazy();\n" + - "}", - "Other.java", - "public interface Other {}", - "ExampleFactoryImpl.java", - "public class ExampleFactoryImpl implements ExampleFactory {\n" + - " public Crazy createCrazy() {\n" + - " return null;\n" + - " }\n" + - "}" - }, - "", - null /* no extra class libraries */, - true /* flush output directory */, - null /* vm arguments*/, - customOptions, - null /* compiler requestor*/); - this.runConformTest( - new String[] { - "ExampleFactoryImpl.java", - "public class ExampleFactoryImpl implements ExampleFactory {\n" + - " public Crazy createCrazy() {\n" + - " return null;\n" + - " }\n" + - "}" - }, - "", - null /* no extra class libraries */, - false /* flush output directory */, - null /* vm arguments*/, - customOptions, - null /* compiler requestor*/); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 -//invalid bug - regression test only -public void test1095() { - Map customOptions = this.getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); - runNegativeTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.lang.reflect.Constructor;\n" + - "\n" + - "@interface Annot {\n" + - " String message() default \"\"; //$NON-NLS-1$\n" + - "}\n" + - "\n" + - "public class X {\n" + - " X() {\n" + - " }\n" + - " public String getAnnotationValue(Constructor constructor){\n" + - " Annot annotation = constructor.getAnnotation(Annot.class);\n" + - " return (annotation != null) ? annotation.message() : null;\n" + - " }\n" + - "}" - }, - // compiler options - null /* no class libraries */, - customOptions /* custom options */, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 11)\n" + - " Annot annotation = constructor.getAnnotation(Annot.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to Annot\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 -//invalid bug - regression test only -public void test1096() { - Map customOptions = this.getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); - this.runConformTest( - new String[] { - "X.java", - "import java.lang.reflect.Constructor;\n" + - "\n" + - "@interface Annot {\n" + - " String message() default \"\"; //$NON-NLS-1$\n" + - "}\n" + - "\n" + - "public class X {\n" + - " X() {\n" + - " }\n" + - " public String getAnnotationValue(Constructor constructor){\n" + - " Annot annotation = constructor.getAnnotation(Annot.class);\n" + - " return (annotation != null) ? annotation.message() : null;\n" + - " }\n" + - "}" - }, - "", - null /* no extra class libraries */, - true /* flush output directory */, - null, - customOptions, - null/* do not perform statements recovery */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=168232 -public void test1097() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " String[] foo = new String[] {};\n" + - "}" - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 2)\n" + - " String[] foo = new String[] {};\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Syntax error on token(s), misplaced construct(s)\n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " String[] foo = new String[] {};\n" + - " ^\n" + - "Syntax error on token \">\", , expected\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 -public void test1098() { - this.runNegativeTest(new String[] { - "X.java", - "public class X { \n" + - " private class A {\n" + - " class B {}\n" + - " }\n" + - " private class Y extends A {\n" + - " }\n" + - " Y.B d = null;\n" + - "}\n" + - "class Y extends Zork {}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " private class Y extends A {\n" + - " ^\n" + - "Access to enclosing constructor X.A() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " class Y extends Zork {}\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test1099() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public class A {};\n" + - " public class B extends A {\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"SUCCESS\";\n" + - " }\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " List l = x.newList(x.new B());\n" + - " for (A a: l) {\n" + - " System.out.println(a);\n" + - " }\n" + - " }\n" + - "\n" + - " public List newList(V... values) {\n" + - " List l = new ArrayList();\n" + - " for (V v : values) {\n" + - " l.add(v);\n" + - " }\n" + - " return l;\n" + - " }\n" + - "\n" + - "}\n" - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170318 -public void test1100() { - this.runNegativeTest(new String[] { - "X.java", - "class X {\n" + - "}\n" + - "class Y {\n" + - " public void foo(final X x) {\n" + - " }\n" + - "}\n" + - "class Z extends Y {\n" + - " public void foo(final X x) {\n" + - " super.foo(x);\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " class Z extends Y {\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " public void foo(final X x) {\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(X) of type Z has the same erasure as foo(X) of type Y but does not override it\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " super.foo(x);\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The method foo(X) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172189 -public void test1101() { - this.runNegativeTest(new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public final class X {\n" + - " public A a;\n" + - " public B b;\n" + - " public X(A pa, B pb) {\n" + - " a = pa;\n" + - " b = pb;\n" + - " }\n" + - " public static X create(A pa, B pb) {\n" + - " return new X(pa, pb);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " List> list = new ArrayList>();\n" + - " list.add(X.create(\"\", \"\"));\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " list.add(X.create(\"\", \"\"));\n" + - " ^\n" + - "Wildcard is not allowed at this location\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 -public void test1102() { - this.runNegativeTest(new String[] { - "X.java", - "public class X {\n" + - " X(T t) {\n" + - " }\n" + - "\n" + - " class A {\n" + - " A(T t) {\n" + - " }\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X(null);\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " new X(null);\n" + - " ^\n" + - "Wildcard is not allowed at this location\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 -public void test1103() { - this.runNegativeTest(new String[] { - "X.java", - "public class X {\n" + - " X(T t) {\n" + - " }\n" + - " X(int i) {\n" + - " this(null);\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " this(null);\n" + - " ^\n" + - "Wildcard is not allowed at this location\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 -public void test1104() { - this.runNegativeTest(new String[] { - "X.java", - "public class X {\n" + - " X(T t) { }\n" + - " \n" + - " class A {\n" + - " A(T t) { }\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " new X(null).new A(null);\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " new X(null).new A(null);\n" + - " ^\n" + - "Wildcard is not allowed at this location\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174724 -public void test1105() { - Map customOptions = this.getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); - this.runNegativeTest(new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Class foo = Class.forName(Integer.class.getName());\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Class foo = Class.forName(Integer.class.getName());\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Wildcard is not allowed at this location\n" + - "----------\n", - null, - true, - customOptions); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174766 -public void test1106() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " public class Y extends Exception {\n" + - " private static final long serialVersionUID = 1L;\n" + - " }\n" + - "}" - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 2)\n" + - " public class Y extends Exception {\n" + - " ^^^^^^^^^\n" + - "The generic class X.Y may not subclass java.lang.Throwable\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172913 -public void test1107() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.Collection;\n" + - "import java.util.HashMap;\n" + - "import java.util.Iterator;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " private void processLocks(HashMap locksMap, Object key) {\n" + - " for (Iterator iter = locksMap.keySet().iterator(); iter.hasNext();) {\n" + - " Object call = iter.next();\n" + - " List locks = externLocks((Collection) locksMap.get(call), call);\n" + - " // ...\n" + - " }\n" + - " }\n" + - " private List externLocks(Collection locks, Object call) {\n" + - " List result = new ArrayList();\n" + - " // ..\n" + - " return result;\n" + - " }\n" + - "}\n", - }, - ""); - // ensure only one instance of: checkcast java.util.Collection - String expectedOutput = - " // Method descriptor #15 (Ljava/util/HashMap;Ljava/lang/Object;)V\n" + - " // Stack: 3, Locals: 6\n" + - " private void processLocks(java.util.HashMap locksMap, java.lang.Object key);\n" + - " 0 aload_1 [locksMap]\n" + - " 1 invokevirtual java.util.HashMap.keySet() : java.util.Set [16]\n" + - " 4 invokeinterface java.util.Set.iterator() : java.util.Iterator [22] [nargs: 1]\n" + - " 9 astore_3 [iter]\n" + - " 10 goto 38\n" + - " 13 aload_3 [iter]\n" + - " 14 invokeinterface java.util.Iterator.next() : java.lang.Object [28] [nargs: 1]\n" + - " 19 astore 4 [call]\n" + - " 21 aload_0 [this]\n" + - " 22 aload_1 [locksMap]\n" + - " 23 aload 4 [call]\n" + - " 25 invokevirtual java.util.HashMap.get(java.lang.Object) : java.lang.Object [34]\n" + - " 28 checkcast java.util.Collection [38]\n" + - " 31 aload 4 [call]\n" + - " 33 invokespecial X.externLocks(java.util.Collection, java.lang.Object) : java.util.List [40]\n" + - " 36 astore 5\n" + - " 38 aload_3 [iter]\n" + - " 39 invokeinterface java.util.Iterator.hasNext() : boolean [44] [nargs: 1]\n" + - " 44 ifne 13\n" + - " 47 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 9]\n" + - " [pc: 13, line: 10]\n" + - " [pc: 21, line: 11]\n" + - " [pc: 38, line: 9]\n" + - " [pc: 47, line: 14]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 48] local: this index: 0 type: X\n" + - " [pc: 0, pc: 48] local: locksMap index: 1 type: java.util.HashMap\n" + - " [pc: 0, pc: 48] local: key index: 2 type: java.lang.Object\n" + - " [pc: 10, pc: 47] local: iter index: 3 type: java.util.Iterator\n" + - " [pc: 21, pc: 38] local: call index: 4 type: java.lang.Object\n"; - - 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); - } -} -public void test1108() { - this.runConformTest( - new String[] { - "X.java", - "interface UnaryFunction {\n" + - " public R invoke(A o) throws X;\n" + - "}\n" + - " \n" + - "public class X implements UnaryFunction {\n" + - " public Void invoke(String o) throws RuntimeException {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591 -//?: cuts assignment context -public void test1109() { - this.runNegativeTest( - new String[] { - "X.java", - "class X {\n" + - " public Y foo()\n" + - " {\n" + - " return true ? Z.bar() : null;\n" + - " }\n" + - "}\n" + - "class Y {\n" + - "}\n" + - "class Z {\n" + - " static Y bar() {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " return true ? Z.bar() : null;\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Y to Y\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591 -//variant -public void test1110() { - this.runConformTest( - new String[] { - "X.java", - "class X {\n" + - " public Y foo()\n" + - " {\n" + - " return true ? Z.bar() : null;\n" + - " }\n" + - "}\n" + - "class Y {\n" + - "}\n" + - "class Z {\n" + - " static Y bar() {\n" + - " return null;\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 -public void test1111() { - Map settings = getCompilerOptions(); - settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "class A {\n" + - " public T foo(Object o) {\n" + - " return (T) o; // should get unchecked warning\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " A a = new A();\n" + - " try {\n" + - " X s = a.foo(new Object());\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return;\n" + - " }\n" + - " System.out.println(\"FAILED\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS", - null, - true, - null, - settings, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation -public void test1112() { - Map settings = getCompilerOptions(); - settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "class A {\n" + - " public T foo;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " A a = new A();\n" + - " A ua = a;\n" + - " ua.foo = new Object();\n" + - " try {\n" + - " X s = a.foo;\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return;\n" + - " }\n" + - " System.out.println(\"FAILED\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS", - null, - true, - null, - settings, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation -public void test1113() { - Map settings = getCompilerOptions(); - settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "class A {\n" + - " public T foo;\n" + - "}\n" + - "\n" + - "public class X extends A{\n" + - " public static void main(String[] args) {\n" + - " new X().foo();\n" + - " }\n" + - " public void foo() {\n" + - " A ua = this;\n" + - " ua.foo = new Object();\n" + - " try {\n" + - " X s = foo;\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return;\n" + - " }\n" + - " System.out.println(\"FAILED\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS", - null, - true, - null, - settings, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation -public void test1114() { - Map settings = getCompilerOptions(); - settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "class A {\n" + - " public T foo;\n" + - "}\n" + - "\n" + - "public class X extends A{\n" + - " public static void main(String[] args) {\n" + - " new X().foo();\n" + - " }\n" + - " public void foo() {\n" + - " A ua = this;\n" + - " ua.foo = new Object();\n" + - " try {\n" + - " X s = this.foo;\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return;\n" + - " }\n" + - " System.out.println(\"FAILED\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS", - null, - true, - null, - settings, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation -public void test1115() { - Map settings = getCompilerOptions(); - settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "class A {\n" + - " public T foo;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " static X ROOT;\n" + - " public static void main(String[] args) {\n" + - " A a = new A();\n" + - " A ua = a;\n" + - " ua.foo = new Object();\n" + - " try {\n" + - " X s = a.foo.ROOT;\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return;\n" + - " }\n" + - " System.out.println(\"FAILED\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS", - null, - true, - null, - settings, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation -public void test1116() { - this.runConformTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "interface I {\n" + - " int CONST = 1;\n" + - "}\n" + - "\n" + - "class Z {\n" + - " T c;\n" + - " Z(T c) {\n" + - " this.c = c;\n" + - " }\n" + - " int foo() {\n" + - " return c.CONST;\n" + - " }\n" + - "}\n" + - "\n" + - "public class X implements Serializable, I {\n" + - " public static void main(String argv[]) {\n" + - " Z z = new Z(new X());\n" + - " Z rawz = z;\n" + - " rawz.c = new Serializable(){};\n" + - " try {\n" + - " z.foo();\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation -public void test1117() throws Exception { - Map options = getCompilerOptions(); - options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); - this.runConformTest( - new String[] { - "X.java", - "interface I {\n" + - " Value CONST = null;\n" + - "}\n" + - "class Value {\n" + - " String NAME = \"VALUE\";\n" + - "}\n" + - "class B implements I {\n" + - " B(Value param) {\n" + - " Value v0 = CONST;\n" + - " Value v1 = this.CONST;\n" + - " String s2 = CONST.NAME;\n" + - " Value v3 = I.CONST;\n" + - " Value v4 = B.CONST;\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " new B(new Value());\n" + - " } catch(NullPointerException e) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS", - null, - false, - null, - options, - null); - // check the reference to I.CONST is generated as B.CONST, except for v3 still issuing I.CONST - String expectedOutput = - " // Method descriptor #8 (LValue;)V\n" + - " // Signature: (LValue;)V\n" + - " // Stack: 1, Locals: 2\n" + - " B(Value param);\n" + - " 0 aload_0 [this]\n" + - " 1 invokespecial java.lang.Object() [12]\n" + - " 4 getstatic B.CONST : Value [15]\n" + - " 7 pop\n" + - " 8 getstatic B.CONST : Value [15]\n" + - " 11 pop\n" + - " 12 getstatic B.CONST : Value [15]\n" + - " 15 getfield Value.NAME : java.lang.String [19]\n" + - " 18 pop\n" + - " 19 getstatic I.CONST : Value [25]\n" + - " 22 pop\n" + - " 23 getstatic B.CONST : Value [15]\n" + - " 26 pop\n" + - " 27 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 8]\n" + - " [pc: 4, line: 9]\n" + - " [pc: 8, line: 10]\n" + - " [pc: 12, line: 11]\n" + - " [pc: 19, line: 12]\n" + - " [pc: 23, line: 13]\n" + - " [pc: 27, line: 14]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 28] local: this index: 0 type: B\n" + - " [pc: 0, pc: 28] local: param index: 1 type: Value\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 28] local: this index: 0 type: B\n" + - " [pc: 0, pc: 28] local: param index: 1 type: Value\n"; - - File f = new File(OUTPUT_DIR + File.separator + "B.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715 -public void test1118() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " X() {\n" + - " Class> cls = null;\n" + - " foo(cls);\n" + - " }\n" + - "\n" + - " > T foo(Class pClass) {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - // javac options - JavacTestOptions.EclipseHasABug.EclipseBug177715 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169728 -public void test1119() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X & Runnable> {\n" + - " T get() {\n" + - " return null;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " \n" + - " X x1 = null; // error\n" + - " X x2 = null; // error\n" + - " X x3 = null; // ok\n" + - " X x4 = null; // ok\n" + - " \n" + - " foo1(x1); // ok\n" + - " foo1(x2); // ok\n" + - " foo1(x3); // ok\n" + - " foo1(x4); // ok\n" + - "\n" + - " foo2(x1); // error\n" + - " foo2(x2); // error\n" + - " foo2(x3); // error\n" + - " foo2(x4); // ok\n" + - " }\n" + - " \n" + - " static void foo1(X x) {\n" + - " x.get().run(); // ok\n" + - " x.get().compareTo(null); // ok\n" + - " x.get().compareTo(x.get()); // error\n" + - " }\n" + - " static void foo2(X x) {\n" + - " x.get().run(); // ok\n" + - " x.get().compareTo(null); // ok\n" + - " x.get().compareTo(x.get()); // error\n" + - " } \n" + - "}\n" + - "\n" + - "abstract class OnlyRunnable implements Runnable {}\n" + - "abstract class OnlyComparable implements Comparable {}\n" + - "abstract class ComparableRunnable implements Comparable, Runnable {}\n" + - "abstract class ComparableRunnableThrowable extends Throwable implements Comparable, Runnable {\n" + - " private static final long serialVersionUID = 1L;\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " X x1 = null; // error\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The type OnlyRunnable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " X x2 = null; // error\n" + - " ^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type OnlyComparable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " X x4 = null; // ok\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Bound mismatch: The type ComparableRunnableThrowable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + - "----------\n" + - "4. ERROR in X.java (at line 17)\n" + - " foo2(x1); // error\n" + - " ^^^^\n" + - "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + - "----------\n" + - "5. ERROR in X.java (at line 18)\n" + - " foo2(x2); // error\n" + - " ^^^^\n" + - "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + - "----------\n" + - "6. ERROR in X.java (at line 19)\n" + - " foo2(x3); // error\n" + - " ^^^^\n" + - "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + - "----------\n" + - "7. ERROR in X.java (at line 26)\n" + - " x.get().compareTo(x.get()); // error\n" + - " ^^^^^^^^^\n" + - "The method compareTo(capture#3-of ?) in the type Comparable is not applicable for the arguments (capture#4-of ?)\n" + - "----------\n" + - "8. ERROR in X.java (at line 31)\n" + - " x.get().compareTo(x.get()); // error\n" + - " ^^^^^^^^^\n" + - "The method compareTo(capture#7-of ? extends Throwable) in the type Comparable is not applicable for the arguments (capture#8-of ? extends Throwable)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166963 -public void test1120() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X() {\n" + - " System.out.println();\n" + - " this(zork);\n" + - " Zork.this.this();\n" + - " this();\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " this(zork);\n" + - " ^^^^^^^^^^^\n" + - "Constructor call must be the first statement in a constructor\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " this(zork);\n" + - " ^^^^\n" + - "zork cannot be resolved\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " Zork.this.this();\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Constructor call must be the first statement in a constructor\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " Zork.this.this();\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "5. ERROR in X.java (at line 6)\n" + - " this();\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "6. ERROR in X.java (at line 6)\n" + - " this();\n" + - " ^^^^^^^\n" + - "Constructor call must be the first statement in a constructor\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 -public void test1121() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\r\n" + - " System.out.println(T[].class);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " System.out.println(T[].class);\n" + - " ^^^^^^^^^\n" + - "Illegal class literal for the type parameter T\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 -public void test1122() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\r\n" + - " System.out.println(T[].class);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " System.out.println(T[].class);\n" + - " ^^^^^^^^^\n" + - "Illegal class literal for the type parameter T\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 - variation -public void test1123() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo() {\n" + - " Class c1 = int.class;\n" + - " Class c2 = Integer.class;\n" + - " Class c3 = int[].class;\n" + - " Class c4 = int[].class;\n" + - " Class c5 = void.class;\n" + - " Class c6 = void[].class;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Class c3 = int[].class;\n" + - " ^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " Class c6 = void[].class;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " Class c6 = void[].class;\n" + - " ^^^^^^\n" + - "void[] is an invalid type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=182192 -public void test1124() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.HashMap;\n" + - "import java.util.Map;\n" + - "\n" + - "public class X {\n" + - "\n" + - " static protected final Map myMap = new HashMap();\n" + - " private final T theGenericThing;\n" + - "\n" + - " private X(T something) {\n" + - " this.theGenericThing = something;\n" + - " }\n" + - "\n" + - " public static class InnerClassThatShowsBug extends X {\n" + - " public InnerClassThatShowsBug() {\n" + - " super(null);\n" + - " }\n" + - "\n" + - " public void printMap() {\n" + - " for (Map.Entry entry : myMap().entrySet()) {\n" + - " System.out.println(entry.getKey() + \" => \" + entry.getValue());\n" + - " }\n" + - " }\n" + - " protected Map myMap2() {\n" + - " return myMap;\n" + - " }\n" + - " public void printMap2() {\n" + - " for (Map.Entry entry : myMap2().entrySet()) {\n" + - " System.out.println(entry.getKey() + \" => \" + entry.getValue());\n" + - " }\n" + - " }\n" + - " }\n" + - "\n" + - " protected Map myMap() {\n" + - " return myMap;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " private final T theGenericThing;\n" + - " ^^^^^^^^^^^^^^^\n" + - "The field X.theGenericThing is never read locally\n" + - "----------\n" + - "2. WARNING in X.java (at line 13)\n" + - " public static class InnerClassThatShowsBug extends X {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 15)\n" + - " super(null);\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 15)\n" + - " super(null);\n" + - " ^^^^^^^^^^^^\n" + - "Access to enclosing constructor X(T) is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "5. ERROR in X.java (at line 19)\n" + - " for (Map.Entry entry : myMap().entrySet()) {\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from element type Object to Map.Entry\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 -public void test1125() { - this.runNegativeTest( - new String[] { - "X.java", - "class A {\n" + - " class B {\n" + - " T t;\n" + - " T getValue() {\n" + - " return t;\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class C extends A {\n" + - " Zork z;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " static C.B c = new C().new B();\n" + - "\n" + - " public static void main(String[] args) {\n" + - " C.B temp = new C().new B();\n" + - " String s = temp.getValue();\n" + - " System.out.println(s);\n" + - " foo(bar());\n" + - " }\n" + - "\n" + - " static C.B bar() {\n" + - " return new C().new B();\n" + - " }\n" + - "\n" + - " static void foo(C.B arg) {\n" + - " Object o = arg.getValue();\n" + - " Double d = c.getValue();\n" + - " System.out.println(o);\n" + - " System.out.println(d);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 15)\n" + - " static C.B c = new C().new B();\n" + - " ^\n" + - "C is a raw type. References to generic type C should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 18)\n" + - " C.B temp = new C().new B();\n" + - " ^\n" + - "C is a raw type. References to generic type C should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 25)\n" + - " return new C().new B();\n" + - " ^\n" + - "C is a raw type. References to generic type C should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation -public void test1126() { - this.runConformTest( - new String[] { - "X.java", - "class A {\n" + - " class B {\n" + - " T t;\n" + - " T getValue() {\n" + - " return t;\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " static A.B c = new A().new B();\n" + - "\n" + - " public static void main(String[] args) {\n" + - " A.B temp = new A().new B();\n" + - " String s = temp.getValue();\n" + - " System.out.print(s);\n" + - " foo(bar());\n" + - " }\n" + - "\n" + - " static A.B bar() {\n" + - " return new A().new B();\n" + - " }\n" + - "\n" + - " static void foo(A.B arg) {\n" + - " Object o = arg.getValue();\n" + - " Double d = c.getValue();\n" + - " System.out.print(o);\n" + - " System.out.print(d);\n" + - " }\n" + - "}\n", // ================= - }, - "nullnullnull"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation -public void test1127() { - this.runNegativeTest( - new String[] { - "X.java", - "class A {\n" + - " class B {\n" + - " T t;\n" + - " T getValue() {\n" + - " return t;\n" + - " }\n" + - " }\n" + - "}\n" + - "\n" + - "class C extends A {\n" + - "}\n" + - "\n" + - "public class X {\n" + - " static C.B c = new C().new B();\n" + - "\n" + - " public static void main(String[] args) {\n" + - " C.B temp = new C().new B();\n" + - " String s = temp.getValue();\n" + - " System.out.println(s);\n" + - " foo(bar());\n" + - " }\n" + - "\n" + - " static C.B bar() {\n" + - " return new C().new B();\n" + - " }\n" + - "\n" + - " static void foo(C.B arg) {\n" + - " Object o = arg.getValue();\n" + - " Double d = c.getValue();\n" + - " System.out.println(o);\n" + - " System.out.println(d);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " static C.B c = new C().new B();\n" + - " ^^^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " static C.B c = new C().new B();\n" + - " ^\n" + - "C is a raw type. References to generic type C should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " static C.B c = new C().new B();\n" + - " ^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "4. ERROR in X.java (at line 17)\n" + - " C.B temp = new C().new B();\n" + - " ^^^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "5. WARNING in X.java (at line 17)\n" + - " C.B temp = new C().new B();\n" + - " ^\n" + - "C is a raw type. References to generic type C should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 17)\n" + - " C.B temp = new C().new B();\n" + - " ^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "7. ERROR in X.java (at line 23)\n" + - " static C.B bar() {\n" + - " ^^^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "8. WARNING in X.java (at line 24)\n" + - " return new C().new B();\n" + - " ^\n" + - "C is a raw type. References to generic type C should be parameterized\n" + - "----------\n" + - "9. ERROR in X.java (at line 24)\n" + - " return new C().new B();\n" + - " ^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "10. ERROR in X.java (at line 27)\n" + - " static void foo(C.B arg) {\n" + - " ^^^\n" + - "The member type A.B must be qualified with a parameterized type, since it is not static\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation -public void test1128() { - this.runNegativeTest( - new String[] { - "X.java", - "class A {\n" + - " class Member {}\n" + - "}\n" + - "\n" + - "public class X extends A {\n" + - " void foo() {\n" + - " new Member();\n" + - " new X().new Member();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public class X extends A {\n" + - " ^\n" + - "A is a raw type. References to generic type A should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " new Member();\n" + - " ^^^^^^\n" + - "The member type A.Member must be qualified with a parameterized type, since it is not static\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " new X().new Member();\n" + - " ^^^^^^\n" + - "The member type A.Member must be qualified with a parameterized type, since it is not static\n" + - "----------\n"); -} -public void test1129() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "abstract class Arg1 implements Comparable, Serializable {\n" + - " private static final long serialVersionUID = 1L;\n" + - "}\n" + - "abstract class Arg2 implements Serializable, Comparable {\n" + - " private static final long serialVersionUID = 1L;\n" + - "}\n" + - "\n" + - "interface IX {}\n" + - "\n" + - "public class X {\n" + - " void foo1(boolean b, IX arg2) {\n" + - " IX o = b ? null : arg2;\n" + - " IX o2 = b ? arg2 : null;\n" + - " }\n" + - " void foo2(boolean b, IX arg1, IX arg2) {\n" + - " String s = b ? arg1 : arg2;\n" + - " }\n" + - " void foo3(boolean b, Arg1 arg1, Arg2 arg2) {\n" + - " String s = b ? arg1 : arg2;\n" + - " }\n" + - "} ", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 18)\n" + - " String s = b ? arg1 : arg2;\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from IX to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 21)\n" + - " String s = b ? arg1 : arg2;\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object&Comparable&Serializable to String\n" + - "----------\n"); -} -public void test1130() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "import java.util.List;\n" + - "\n" + - "interface IX&Serializable> {}\n" + - "\n" + - "public class X&Serializable> {\n" + - " void foo4(boolean b, List l1, List> l2) {\n" + - " String s = b ? l1.get(0) : l2.get(0);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " String s = b ? l1.get(0) : l2.get(0);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Comparable to String\n" + - "----------\n"); -} -public void test1131() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "import java.util.List;\n" + - "\n" + - "public class X&Serializable> {\n" + - " void foo4(boolean b, List l1, List> l2) {\n" + - " String s = b ? l1.get(0) : l2.get(0);\n" + - " }\n" + - "} \n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " String s = b ? l1.get(0) : l2.get(0);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Comparable to String\n" + - "----------\n"); -} -public void test1132() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - "\n" + - " public void thisDoesntCompile() {\n" + - " X myThing = new X();\n" + - " Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" + - " // myThing is unbounded, return\n" + - " // type List\n" + - " // incorrectly becomes unbounded\n" + - " }\n" + - "\n" + - " public List getList() {\n" + - " ArrayList l = new ArrayList();\n" + - " l.add(new Integer(0));\n" + - " return l;\n" + - " }\n" + - "\n" + - " public void thisMethodCompilesOk() {\n" + - " X myThing = new X();\n" + - " Integer i = myThing.getList().get(0);\n" + - " }\n" + - "\n" + - " public void thisMethodAlsoCompilesOk() {\n" + - " X myThing = new X();\n" + - " List l = myThing.getList();\n" + - " Integer i = l.get(0);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " X myThing = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Object to Integer\n" + - "----------\n" + - "3. WARNING in X.java (at line 25)\n" + - " X myThing = new X();\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 26)\n" + - " List l = myThing.getList();\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); -} -public void test1133() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "class Y {\n" + - " List foo() { return null; }\n" + - "}\n" + - "\n" + - "public class X extends Y {\n" + - " List bar() { return null; }\n" + - " \n" + - " void m(X x) {\n" + - " List l1 = x.foo();\n" + - " List l2 = x.bar();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " void m(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " List l1 = x.foo();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from List to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " List l2 = x.bar();\n" + - " ^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n"); -} -public void test1134() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "class Y {\n" + - " List foo() { return null; }\n" + - "}\n" + - "\n" + - "public class X extends Y {\n" + - " List bar() { return null; }\n" + - " \n" + - " void m(X x) {\n" + - " List l1 = x.foo();\n" + - " List l2 = x.bar();\n" + - " Zork z;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " void m(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " List l1 = x.foo();\n" + - " ^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " List l2 = x.bar();\n" + - " ^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 -public void test1135() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "class Foo {\n" + - " private T myT;\n" + - "\n" + - " public T getT() {\n" + - " return myT;\n" + - " }\n" + - "\n" + - " public void setT(T aT) {\n" + - " myT = aT;\n" + - " }\n" + - "}\n" + - "\n" + - "public class X extends Foo {\n" + - " X.Baz baz;\n" + - " public static void main(String[] args) {\n" + - " X myBar = new X();\n" + - " myBar.setT(new Baz());\n" + - " System.out.println(myBar.getT().toString());\n" + - " }\n" + - "\n" + - " private static class Baz {\n" + - " @Override\n" + - " public String toString() {\n" + - " return \"Baz\";\n" + - " }\n" + - " } \n" + - "}\n", // ================= - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "Baz" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.EclipseJustification.EclipseBug185422 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154029 -public void test1136() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List l1 = Arrays.asList(1, \"X\");\n" + - " \n" + - " B b = null;\n" + - " Cc = null;\n" + - " List l2 = Arrays.asList(b, c);\n" + - " }\n" + - "}\n" + - "class A {}\n" + - "interface I {}\n" + - "class B extends A implements I {}\n" + - "class C extends A implements I {}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List l1 = Arrays.asList(1, \"X\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Object&Comparable&Serializable is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " List l1 = Arrays.asList(1, \"X\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List&Serializable> to List\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " List l2 = Arrays.asList(b, c);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of A&I is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " List l2 = Arrays.asList(b, c);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List&I> to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154267 -public void test1137() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.awt.Container;\n" + - "import java.util.Collection;\n" + - "\n" + - "abstract class Kollection implements Collection {}\n" + - "abstract class Kontainer extends Container {\n" + - " private static final long serialVersionUID = 1L;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " private Collection foo() {\n" + - " return null;\n" + - " }\n" + - " private Kollection bar() {\n" + - " return null;\n" + - " }\n" + - "\n" + - " private void showProblem() {\n" + - " Collection result = foo();\n" + - " Collection result1 = foo();\n" + - " \n" + - " Collection result2 = (Collection)foo();\n" + - " String result3 = foo();\n" + - " String result4 = (String) foo(); \n" + - "\n" + - " Kollection result5 = bar();\n" + - " Kollection result6 = bar();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 21)\n" + - " Collection result2 = (Collection)foo();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Collection to Collection\n" + - "----------\n" + - "2. ERROR in X.java (at line 22)\n" + - " String result3 = foo();\n" + - " ^^^^^\n" + - "Type mismatch: cannot convert from Collection to String\n" + - "----------\n" + - "3. ERROR in X.java (at line 23)\n" + - " String result4 = (String) foo(); \n" + - " ^^^^^^^^^^^^^^\n" + - "Cannot cast from Collection to String\n" + - "----------\n"); -} -public void test1138() { - // binary prerequisite - this.runConformTest( - new String[] { - "p/E.java", - "package p;\n" + - "public enum E {\n" + - "}\n", // ================= - }, - ""); - this.runConformTest( - new String[] { - "X.java", - "import static p.E.*;\n" + - "public class X implements java.io.Serializable {\n" + - "}\n", // ================= - }, - "", - null, // use default class-path - false, // do not flush previous output dir content - null); // no special vm args ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186833 -public void test1139() { - this.runNegativeTest( - new String[] { - "p/X.java", - "package p;\n" + - "import p.X.Super;\n" + - "import static p.Top.*;\n" + - "\n" + - "class Top {\n" + - " static class A {}\n" + - "}\n" + - "\n" + - "public class X extends Super> {\n" + - " static class Super extends Top{\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in p\\X.java (at line 9)\r\n" + - " public class X extends Super> {\r\n" + - " ^^^^^\n" + - "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186788 -public void test1140() { - this.runNegativeTest( - new String[] { - "p/X.java", - "package p;\n" + - "import static p.X.Super;\n" + - "import static p.Top.*;\n" + - "\n" + - "class Top {\n" + - " static class A {}\n" + - "}\n" + - "\n" + - "public class X extends Super> {\n" + - " class Super extends Top{\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in p\\X.java (at line 2)\r\n" + - " import static p.X.Super;\r\n" + - " ^^^^^^^^^\n" + - "The import p.X.Super cannot be resolved\n" + - "----------\n" + - "2. ERROR in p\\X.java (at line 9)\r\n" + - " public class X extends Super> {\r\n" + - " ^^^^^\n" + - "Super cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186833 - variation -public void test1141() { - this.runNegativeTest( - new String[] { - "p/X.java", - "package p;\n" + - "import static p.Top.*;\n" + - "\n" + - "class Top {\n" + - " static class A {}\n" + - "}\n" + - "\n" + - "public class X extends p.X.Super> {\n" + - " static class Super extends Top{\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in p\\X.java (at line 8)\r\n" + - " public class X extends p.X.Super> {\r\n" + - " ^^^^^^^^^\n" + - "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 -public void test1142() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.Comparator;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " public static Comparator compound(Comparator a, Comparator b) {\n" + - " return compound(asList(a, b));\n" + - " }\n" + - "\n" + - " public static Comparator compound(Iterable> comparators) {\n" + - " return null;\n" + - " }\n" + - " public static List asList(E a, E b) {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 5)\n" + - " return compound(asList(a, b));\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBug6573446 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation -public void test1143() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Comparator;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " public static Comparator compound(Comparator a, Comparator b) {\n" + - " int i = asList(a, b);\n" + - " }\n" + - "\n" + - " public static Comparator compound(Iterable> comparators) {\n" + - " return null;\n" + - " }\n" + - " public static List asList(E a, E b) {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " int i = asList(a, b);\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to int\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation -public void test1144() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Comparator;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " Iterable> itc1;\n" + - " Iterable> itc2 = itc1;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Iterable> itc2 = itc1;\n" + - " ^^^^\n" + - "Type mismatch: cannot convert from Iterable> to Iterable>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation -public void test1145() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " Comparator compound(Comparator a, Comparator b) {\n" + - " return compound(asList(a));\n" + - " }\n" + - " Comparator compound(Iterable> c) {\n" + - " return null;\n" + - " }\n" + - " List asList(E a) {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation -public void test1146() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static Comparator compound(\n" + - " Comparator a,\n" + - " Comparator b, \n" + - " Comparator... rest) {\n" + - " int i = asList(a, b, rest);\n" + - " int j = asList2(a, b);\n" + - " return compound(asList(a, b, rest));\n" + - " }\n" + - " public static Comparator compound(Iterable> comparators) {\n" + - " return null;\n" + - " }\n" + - " public static List asList(E a, E b, E... rest) {\n" + - " return null;\n" + - " }\n" + - " public static List asList2(E a, E b) {\n" + - " return null;\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " int i = asList(a, b, rest);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to int\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " int j = asList2(a, b);\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to int\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " return compound(asList(a, b, rest));\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation -public void test1147() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo(Comparator cx, Comparator[] cxs) {\n" + - " int i = cx;\n" + - " int j = cxs;\n" + - " int k = cxs[0];\n" + - " int l = asList2(cxs[0], cxs[1]);\n" + - " }\n" + - " public static List asList2(E a, E b) {\n" + - " return null;\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " int i = cx;\n" + - " ^^\n" + - "Type mismatch: cannot convert from Comparator to int\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " int j = cxs;\n" + - " ^^^\n" + - "Type mismatch: cannot convert from Comparator[] to int\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " int k = cxs[0];\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from Comparator to int\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " int l = asList2(cxs[0], cxs[1]);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to int\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation -public void test1148() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " public static Comparator compound(Comparator a, Comparator b, Comparator... rest) {\n" + - " int i = asList(a, b, rest);\n" + - " int j = compound(asList(a, b, rest));\n" + - " compound(asList(a, b, rest));\n" + - " if (true) return compound(asList(a, b, rest));\n" + - " \n" + - " List> c = null;\n" + - " compound(c);\n" + - " return compound(c);\n" + - " }\n" + - " public static Comparator compound(Iterable> comparators) {\n" + - " return null;\n" + - " }\n" + - " public static List asList(E a, E b, E... rest) {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " int i = asList(a, b, rest);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to int\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " int j = compound(asList(a, b, rest));\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " compound(asList(a, b, rest));\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " if (true) return compound(asList(a, b, rest));\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n" + - "5. ERROR in X.java (at line 10)\n" + - " compound(c);\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n" + - "6. ERROR in X.java (at line 11)\n" + - " return compound(c);\n" + - " ^^^^^^^^\n" + - "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=198051 -public void test1149() { - String bSource = - "public class B {\n" + - " void b() throws ClassNotFoundException {\n" + - " new A();\n" + - " }\n" + - "}\n"; - runConformTest( - // test directory preparation - new String[] { /* test files */ - "A.java", - "public class A {\n" + - " A() throws T {}\n" + - " void a() throws ClassNotFoundException {\n" + - " new A();\n" + - " }\n" + - "}\n", - "B.java", - bSource - }, - // javac options - JavacTestOptions.EclipseJustification.EclipseBug234815 /* javac test options */); - runConformTest( - // test directory preparation - false /* do not flush output directory */, - new String[] { /* test files */ - "B.java", - bSource - }, - // compiler results - "" /* expected compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.EclipseJustification.EclipseBug234815 /* javac test options */); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=234815 (invalid) -public void test1149b() { - runConformTest( - new String[] { - "A.java", - "public class A {\n" + - " void foo() throws T {}\n" + - " void a() throws ClassNotFoundException {\n" + - " new A().foo();\n" + - " }\n" + - "}\n", - }, - "" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 -public void test1150() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.ref.Reference;\n"+ - "public class X {\n" + - " static class Rather {\n" + - " static class Deeply {\n" + - " static class Inside {\n" + - " }\n" + - " }\n" + - " }\n" + - " Reference x;\n" + - " Reference y; \n" + - " Reference z; \n" + - "\n" + - " public static void main(String[] args) throws Exception {\n" + - " System.out.print(X.class.getDeclaredField(\"x\").getGenericType());\n" + - " System.out.print(\"##\");\n" + - " System.out.print(X.class.getDeclaredField(\"y\").getGenericType());\n" + - " System.out.print(\"##\");\n" + - " System.out.print(X.class.getDeclaredField(\"z\").getGenericType());\n" + - " System.out.println();\n" + - " }\n" + - "}\n" - }, - "java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference" - ); - String expectedOutput = - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference;\n" + - " java.lang.ref.Reference x;\n" + - " \n" + - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference;\n" + - " java.lang.ref.Reference y;\n" + - " \n" + - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference;\n" + - " java.lang.ref.Reference z;\n"; - - 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); - } - -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation -public void test1151() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.ref.Reference;\n"+ - "public class X {\n" + - " class Other {\n" + - " class Deeply {\n" + - " class Inside {\n" + - " } \n" + - " }\n" + - " }\n" + - " Reference.Other.Deeply> t;\n" + - " Reference.Other.Deeply.Inside> u;\n" + - "\n" + - " public static void main(String[] args) throws Exception {\n" + - " System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + - " //System.out.print(\"##\");\n" + - " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) - " System.out.println();\n" + - " }\n" + - "}\n" - }, - //"java.lang.ref.Reference.Other.Deeply>##java.lang.ref.Reference.Other.Deeply$Inside>" - "java.lang.ref.Reference.Other.Deeply>" - ); - String expectedOutput = - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference.Other.Deeply;>;\n" + - " java.lang.ref.Reference t;\n" + - " \n" + - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference.Other.Deeply.Inside;>;\n" + - " java.lang.ref.Reference u;\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation -public void test1152() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.lang.ref.Reference;\n"+ - "public class X {\n" + - " class Other {\n" + - " class Deeply {\n" + - " class Inside {\n" + - " } \n" + - " }\n" + - " }\n" + - " Reference.Other.Deeply.Inside> u;\n" + - "\n" + - " public static void main(String[] args) throws Exception {\n" + - " System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + - " System.out.println();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Reference.Other.Deeply.Inside> u;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The member type X.Other.Deeply.Inside must be parameterized, since it is qualified with a parameterized type\n" + - "----------\n" ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation -public void test1153() { - // check proper decoding of binary signatures, by compiling against generated binary - this.runConformTest( - new String[] { - "p/X.java", - "package p;\n" + - "import java.lang.ref.Reference;\n" + - "public class X {\n" + - " public static class Rather {\n" + - " public static class Deeply {\n" + - " public static class Inside {\n" + - " }\n" + - " }\n" + - " }\n" + - " public class Other {\n" + - " public class Deeply {\n" + - " public class Inside {\n" + - " } \n" + - " }\n" + - " }\n" + - " public Reference x;\n" + - " public Reference y; \n" + - " public Reference z; \n" + - " public Reference.Other.Deeply> t;\n" + - " public Reference.Other.Deeply.Inside> u;\n" + - "}\n", - }, - "" - ); - this.runConformTest( - new String[] { - "Y.java", - "import java.lang.ref.Reference;\n" + - "import p.X;\n" + - "public class Y {\n" + - " Reference x;\n" + - " Reference y; \n" + - " Reference z; \n" + - " Reference.Other.Deeply> t;\n" + - " Reference.Other.Deeply.Inside> u;\n" + - " Y(X someX) {\n" + - " this.x = someX.x;\n" + - " this. y = someX.y; \n" + - " this.z = someX.z; \n" + - " this.t = someX.t;\n" + - " this.u = someX.u; \n" + - " }\n" + - " public static void main(String[] args) throws Exception {\n" + - " System.out.print(Y.class.getDeclaredField(\"x\").getGenericType());\n" + - " System.out.print(\"##\");\n" + - " System.out.print(Y.class.getDeclaredField(\"y\").getGenericType());\n" + - " System.out.print(\"##\");\n" + - " System.out.print(Y.class.getDeclaredField(\"z\").getGenericType());\n" + - " System.out.print(\"##\");\n" + - " System.out.print(Y.class.getDeclaredField(\"t\").getGenericType());\n" + - " //System.out.print(\"##\");\n" + - " //System.out.print(Y.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) - " System.out.println();\n" + - " }\n" + - "}\n" - }, - "java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference.Other.Deeply>", - null, - false, // do not flush output - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation -public void test1154() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.ref.Reference;\n" + - "public class X {\n" + - " class Other {\n" + - " class Deeply {\n" + - " class Deeper {\n" + - " class Inside {\n" + - " } \n" + - " }\n" + - " }\n" + - " }\n" + - " Reference.Deeply> t;\n" + - " Reference.Deeply.Deeper.Inside> u;\n" + - "\n" + - " public static void main(String[] args) throws Exception {\n" + - " //System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) - " //System.out.print(\"##\");\n" + - " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) - " System.out.println();\n" + - " }\n" + - "}\n" - }, - ""); - - String expectedOutput = - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference.Deeply;>;\n" + - " java.lang.ref.Reference t;\n" + - " \n" + - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference.Deeply.Deeper.Inside;>;\n" + - " java.lang.ref.Reference u;\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation -public void test1155() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "import java.lang.ref.Reference;\n" + - "public class X {\n" + - " class Other {\n" + - " class Deeply {\n" + - " class Deeper {\n" + - " class Inside {\n" + - " } \n" + - " }\n" + - " }\n" + - " }\n" + - " Reference.Other.Deeply> t;\n" + - " Reference.Other.Deeply.Deeper.Inside> u;\n" + - "\n" + - " public static void main(String[] args) throws Exception {\n" + - " System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + - " //System.out.print(\"##\");\n" + - " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) - " System.out.println();\n" + - " }\n" + - "}\n" - }, - "java.lang.ref.Reference.Other.Deeply>" ); - - String expectedOutput = - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference.Other.Deeply;>;\n" + - " java.lang.ref.Reference t;\n" + - " \n" + - " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + - " // Signature: Ljava/lang/ref/Reference.Other.Deeply.Deeper.Inside;>;\n" + - " java.lang.ref.Reference u;\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196253 -public void test1156() { - this.runConformTest( - new String[] { - "C.java", - "public class C {\n" + - " R>> xx = D.r;\n" + - "}", - "D.java", - "public class D {\n" + - " public static R>> r;\n" + - "}", - "R.java", - "public class R {}", - "X.java", - "public class X {\n" + - " public static class N {}\n" + - "}" - }, - "" - ); - this.runConformTest( - new String[] { - "C.java", - "public class C {\n" + - " R>> xx = D.r;\n" + - "}", - }, - "", - null, - false, // do not flush output - null - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202624 -public void test1157() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public void func(Class> cls) {}\n" + - " public void func() {\n" + - " func(XX.class);\n" + - " \n" + - " Class> c = XX.class;\n" + - " }\n" + - " class XX {}\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " func(XX.class);\n" + - " ^^^^\n" + - "The method func(Class>) in the type X is not applicable for the arguments (Class)\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " Class> c = XX.class;\n" + - " ^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 -public void test1158() { - this.runNegativeTest( - new String[] { - "X.java", - " class A {}\n" + - " class B extends A {}\n" + - " class C extends A{}\n" + - " \n" + - " class D {}\n" + - "\n" + - "public class X {\n" + - " void foo() {\n" + - " D d1 = null;\n" + - " D d2 = null;\n" + - " D d3 = null;\n" + - " D d4 = null;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " D d3 = null;\n" + - " ^\n" + - "Bound mismatch: The type C is not a valid substitute for the bounded parameter of the type D\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation -public void test1159() { - this.runConformTest( - new String[] { - "X.java", - "class Y> {}\n" + - "public class X> extends Y{\n" + - " void foo(X x) {}\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation -public void test1160() { - this.runNegativeTest( - new String[] { - "X.java", - "class Y> {}\n" + - "class Z> {}\n" + - "public class X> extends Z{\n" + - " void foo(X x) {}\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\r\n" + - " public class X> extends Z{\r\n" + - " ^\n" + - "Bound mismatch: The type V is not a valid substitute for the bounded parameter > of the type Z\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\r\n" + - " public class X> extends Z{\r\n" + - " ^\n" + - "Bound mismatch: The type V is not a valid substitute for the bounded parameter > of the type Z\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation -public void test1161() { - this.runConformTest( - new String[] { - "X.java", - "class Y> {}\n" + - "class Z> extends Y {}\n" + - "public class X> extends Z {\n" + - " void foo(X x) {}\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation -public void test1162() { - this.runConformTest( - new String[] { - "X.java", - "class Y> {}\n" + - "class Z> extends Y {}\n" + - "public class X> extends Z{\n" + - " void foo(Y y) {}\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203061 - variation -public void test1163() { - this.runNegativeTest( - new String[] { - "X.java", - "public final class X {\n" + - " private final Object mObj;\n" + - " private final Object mDependent = new Object() {\n" + - " {\n" + - " Object o1 = mObj;\n" + - " }\n" + - " Object o2 = mObj;\n" + - " void foo() {\n" + - " Object o3 = mObj;\n" + - " }\n" + - " };\n" + - " public X() {\n" + - " mObj = \"\";\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " private final Object mDependent = new Object() {\n" + - " ^^^^^^^^^^\n" + - "The field X.mDependent is never read locally\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " Object o1 = mObj;\n" + - " ^^^^\n" + - "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " Object o1 = mObj;\n" + - " ^^^^\n" + - "The blank final field mObj may not have been initialized\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " Object o2 = mObj;\n" + - " ^^\n" + - "The field new Object(){}.o2 is never read locally\n" + - "----------\n" + - "5. WARNING in X.java (at line 7)\n" + - " Object o2 = mObj;\n" + - " ^^^^\n" + - "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "6. ERROR in X.java (at line 7)\n" + - " Object o2 = mObj;\n" + - " ^^^^\n" + - "The blank final field mObj may not have been initialized\n" + - "----------\n" + - "7. WARNING in X.java (at line 8)\n" + - " void foo() {\n" + - " ^^^^^\n" + - "The method foo() from the type new Object(){} is never used locally\n" + - "----------\n" + - "8. WARNING in X.java (at line 9)\n" + - " Object o3 = mObj;\n" + - " ^^^^\n" + - "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203061 - variation -public void test1164() { - this.runNegativeTest( - new String[] { - "X.java", - "public final class X {\n" + - " private final Object mObj;\n" + - " private final Object mDependent = new Object() {\n" + - " {\n" + - " Object o1 = mObj;\n" + - " mObj = \"1\";\n" + - " }\n" + - " Object o2 = mObj = \"2\";\n" + - " void foo() {\n" + - " Object o3 = mObj;\n" + - " mObj = \"3\";\n" + - " }\n" + - " };\n" + - " public X() {\n" + - " mObj = \"\";\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " private final Object mDependent = new Object() {\n" + - " ^^^^^^^^^^\n" + - "The field X.mDependent is never read locally\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " Object o1 = mObj;\n" + - " ^^^^\n" + - "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " Object o1 = mObj;\n" + - " ^^^^\n" + - "The blank final field mObj may not have been initialized\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " mObj = \"1\";\n" + - " ^^^^\n" + - "Write access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "5. ERROR in X.java (at line 6)\n" + - " mObj = \"1\";\n" + - " ^^^^\n" + - "The final field X.mObj cannot be assigned\n" + - "----------\n" + - "6. WARNING in X.java (at line 8)\n" + - " Object o2 = mObj = \"2\";\n" + - " ^^\n" + - "The field new Object(){}.o2 is never read locally\n" + - "----------\n" + - "7. WARNING in X.java (at line 8)\n" + - " Object o2 = mObj = \"2\";\n" + - " ^^^^\n" + - "Write access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "8. ERROR in X.java (at line 8)\n" + - " Object o2 = mObj = \"2\";\n" + - " ^^^^\n" + - "The final field X.mObj cannot be assigned\n" + - "----------\n" + - "9. WARNING in X.java (at line 9)\n" + - " void foo() {\n" + - " ^^^^^\n" + - "The method foo() from the type new Object(){} is never used locally\n" + - "----------\n" + - "10. WARNING in X.java (at line 10)\n" + - " Object o3 = mObj;\n" + - " ^^^^\n" + - "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "11. WARNING in X.java (at line 11)\n" + - " mObj = \"3\";\n" + - " ^^^^\n" + - "Write access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n" + - "12. ERROR in X.java (at line 11)\n" + - " mObj = \"3\";\n" + - " ^^^^\n" + - "The final field X.mObj cannot be assigned\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation -public void test1165() { - this.runNegativeTest( - new String[] { - "X.java", - " interface A {}\n" + - " class B implements A {}\n" + - " class C implements A{}\n" + - " \n" + - " class D {}\n" + - "\n" + - "public class X {\n" + - " void foo() {\n" + - " D d1 = null;\n" + - " D d2 = null;\n" + - " D d3 = null;\n" + - " D d4 = null;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " D d3 = null;\n" + - " ^\n" + - "Bound mismatch: The type C is not a valid substitute for the bounded parameter of the type D\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203318 -public void test1166() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " T get() { return null; };\n" + - " void foo(X x) {\n" + - " x.get().intValue(); \n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179902 -public void test1167() { - this.runConformTest( - new String[] { - "Foo.java", - "public class Foo> {\n" + - " class Bar {\n" + - " Bar(Foo bar) {}\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 -public void test1168() { - this.runNegativeTest( - new String[] { - "example/Container.java", - "package example;\n" + - "class A {}\n" + - "class B extends A {}\n" + - "\n" + - "public interface Container> {\n" + - " > void f(\n" + - " Container a, \n" + - " Container b, \n" + - " Container c, \n" + - " Container d, \n" + - " Container e, \n" + - " Container> f, \n" + - " Container> g,\n" + - " Container> h);\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in example\\Container.java (at line 12)\n" + - " Container> f, \n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container\n" + - "----------\n" + - "2. ERROR in example\\Container.java (at line 13)\n" + - " Container> g,\n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation -public void test1169() { - this.runNegativeTest( - new String[] { - "example/Container2.java", - "package example;\n" + - "class A {}\n" + - "class B extends A {}\n" + - "\n" + - "public interface Container2> {\n" + - " > void g(\n" + - " Container2 a, \n" + - " Container2 b, \n" + - " Container2 c, \n" + - " Container2 d, \n" + - " Container2 e, \n" + - " Container2> f, \n" + - " Container2> g, \n" + - " Container2 h);\n" + - "\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in example\\Container2.java (at line 12)\n" + - " Container2> f, \n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation -public void test1170() { - this.runNegativeTest( - new String[] { - "example/Container3.java", - "package example;\n" + - "class A {}\n" + - "class B extends A {}\n" + - "\n" + - "public interface Container3> {\n" + - " > void g(\n" + - " Container3 a, \n" + - " Container3 b, \n" + - " Container3 c, \n" + - " Container3 d, \n" + - " Container3 e, \n" + - " Container3> f, \n" + - " Container3> g, \n" + - " Container3 h, \n" + - " Container3> i, \n" + - " Container3 j);\n" + - "\n" + - " > void h(\n" + - " Container3 a, \n" + - " Container3 b, \n" + - " Container3 c, \n" + - " Container3 d, \n" + - " Container3 e, \n" + - " Container3> f, \n" + - " Container3> g, \n" + - " Container3 h, \n" + - " Container3> i, \n" + - " Container3 j);\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in example\\Container3.java (at line 12)\n" + - " Container3> f, \n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "2. ERROR in example\\Container3.java (at line 13)\n" + - " Container3> g, \n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "3. ERROR in example\\Container3.java (at line 15)\n" + - " Container3> i, \n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "4. WARNING in example\\Container3.java (at line 16)\n" + - " Container3 j);\n" + - " ^\n" + - "A is a raw type. References to generic type A should be parameterized\n" + - "----------\n" + - "5. ERROR in example\\Container3.java (at line 16)\n" + - " Container3 j);\n" + - " ^\n" + - "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "6. ERROR in example\\Container3.java (at line 24)\n" + - " Container3> f, \n" + - " ^\n" + - "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "7. ERROR in example\\Container3.java (at line 25)\n" + - " Container3> g, \n" + - " ^\n" + - "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "8. ERROR in example\\Container3.java (at line 27)\n" + - " Container3> i, \n" + - " ^\n" + - "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n" + - "9. WARNING in example\\Container3.java (at line 28)\n" + - " Container3 j);\n" + - " ^\n" + - "B is a raw type. References to generic type B should be parameterized\n" + - "----------\n" + - "10. ERROR in example\\Container3.java (at line 28)\n" + - " Container3 j);\n" + - " ^\n" + - "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203905 -public void test1171() { - this.runConformTest( - new String[] { - "Function.java", - "public abstract class Function {\n" + - " public abstract B apply(A a);\n" + - "\n" + - " /** (f andThen g)(x) = g(f(x)) */\n" + - " public Function andThen(final Function g) {\n" + - " return new Function() {\n" + - " @Override\n" + - " public C1 apply(A a) {\n" + - " return g.apply(Function.this.apply(a));\n" + - " }\n" + - " };\n" + - " }\n" + - "\n" + - " /** (f compose g)(x) = f(g(x)) */\n" + - " public Function compose(final Function g) {\n" + - " return g.andThen(this);\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -public void test1172() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T field;\n" + - " void foo(X xs, X xn, boolean b) {\n" + - " (b ? xs : xn).field = xs.field;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " (b ? xs : xn).field = xs.field;\n" + - " ^^^^^^^^\n" + - "Type mismatch: cannot convert from String to capture#1-of ? extends Serializable\n" + - "----------\n"); -} -public void test1173() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T field;\n" + - " void foo(X x1, X x2, boolean b) {\n" + - " (b ? x1 : x2).field = x1.field;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " (b ? x1 : x2).field = x1.field;\n" + - " ^^^^^^^^\n" + - "Type mismatch: cannot convert from Integer to capture#1-of ? extends Number&Comparable\n" + - "----------\n"); -} -public void test1174() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T field;\n" + - " void foo(X x1, X x2, boolean b) {\n" + - " (b ? x1 : x2).field = (b ? x1 : x2).field;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " (b ? x1 : x2).field = (b ? x1 : x2).field;\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#2-of ? extends Number&Comparable to capture#1-of ? extends Number&Comparable\n" + - "----------\n"); -} -public void test1175() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T field;\n" + - " void foo(X x1, X x2, boolean b) {\n" + - " (b ? x1 : x2).field = new C();\n" + - " }\n" + - "}\n" + - "class A {}\n" + - "interface B {}\n" + - "class C extends A implements B {}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " (b ? x1 : x2).field = new C();\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from C to capture#3-of ? extends C\n" + - "----------\n"); -} -public void test1176() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " T get() { return null; }\n" + - " void method(X x1, X x2, boolean b) {\n" + - " (b ? x1 : x2).get().foo();\n" + - " (b ? x1 : x2).get().bar();\n" + - " }\n" + - "}\n" + - "class Foo {\n" + - " void foo() {/**/}\n" + - "}\n" + - "interface Bar {\n" + - " void bar();\n" + - "}\n" + - "abstract class C extends Foo implements Bar {/**/}\n" + - "\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test1177() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " T get() { return null; }\n" + - " void method(X x1, X x2, boolean b) {\n" + - " (b ? x1 : x2).get().foo();\n" + - " (b ? x1 : x2).get().bar();\n" + - " }\n" + - "}\n" + - "class Foo {\n" + - " void foo() {/**/}\n" + - "}\n" + - "interface Bar {\n" + - " void bar();\n" + - "}\n" + - "\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test1178() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " T get() { return null; }\n" + - " void method(X x1, X x2, boolean b) {\n" + - " (b ? x1 : x2).get().baz();\n" + - " }\n" + - "}\n" + - "class Foo {\n" + - " void foo() {/**/}\n" + - "}\n" + - "interface Bar {\n" + - " void bar();\n" + - "}\n" + - "abstract class C extends Foo implements Bar {\n" + - " void baz() {/**/}\n" + - "}\n" + - "abstract class D extends C {/**/}\n" + - "abstract class E extends C {/**/}\n" + - "\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test1179() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {}\n" + - "\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {}\n" + - " ^\n" + - "The type V is not an interface; it cannot be specified as a bounded parameter\n" + - "----------\n"); -} -public void test1180() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static , R extends S & T> R max1(T arg1, S arg2) {\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " }\n" + - "\n" + - " public static , S, R extends S & Comparable> R max2(T arg1, S arg2) {\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " }\n" + - "\n" + - " public static , S, R extends Comparable> R max3(T arg1, S arg2) {\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public static , R extends S & T> R max1(T arg1, S arg2) {\n" + - " ^\n" + - "Cannot specify any additional bound T when first bound is a type parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to R\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " public static , S, R extends S & Comparable> R max2(T arg1, S arg2) {\n" + - " ^^^^^^^^^^\n" + - "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to R\n" + - "----------\n" + - "5. WARNING in X.java (at line 11)\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to R\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204534 -public void test1181() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static , R extends S & T> R max(T arg1, S arg2) {\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " }\n" + - "\n" + - " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " }\n" + - "\n" + - " public static , S, R extends Comparable> R max(T arg1, S arg2) {\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " }\n" + - "\n" + - " public static void main(String[] args) {\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public static , R extends S & T> R max(T arg1, S arg2) {\n" + - " ^\n" + - "Cannot specify any additional bound T when first bound is a type parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 2)\n" + - " public static , R extends S & T> R max(T arg1, S arg2) {\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Method max(T, S) has the same erasure max(Comparable, Object) as another method in type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 3)\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to R\n" + - "----------\n" + - "4. ERROR in X.java (at line 6)\n" + - " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + - " ^^^^^^^^^^\n" + - "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + - "----------\n" + - "5. ERROR in X.java (at line 6)\n" + - " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Method max(T, S) has the same erasure max(Comparable, Object) as another method in type X\n" + - "----------\n" + - "6. WARNING in X.java (at line 7)\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to R\n" + - "----------\n" + - "7. WARNING in X.java (at line 11)\n" + - " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to R\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 -public void test1182() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^^\n" + - "The type Object is not an interface; it cannot be specified as a bounded parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation -public void test1183() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(T t) {\n" + - " t.run();\n" + - " }\n" + - " \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation -public void test1184() { - // check that unresolved first bound got erased into Object (and not Runnable) - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T get() { return null; }\n" + - " void foo(X x) {\n" + - " Runnable r = x.get();\n" + - " }\n" + - " \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " void foo(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " Runnable r = x.get();\n" + - " ^^^\n" + - "The method get() from the type X refers to the missing type Zork\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203587 -public void test1185() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(Class c) {};\n" + - " void foo(Class> c) {}\n" + - " void foo2(Class> c) {};\n" + - " void foo2(Class> c) {}\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " void foo(Class c) {};\n" + - " ^^^^^^^^^^^^^^^\n" + - "Method foo(Class) has the same erasure foo(Class) as another method in type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " void foo(Class c) {};\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 3)\n" + - " void foo(Class> c) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Method foo(Class>) has the same erasure foo(Class) as another method in type X\n" + - "----------\n" + - "4. ERROR in X.java (at line 4)\n" + - " void foo2(Class> c) {};\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Duplicate method foo2(Class>) in type X\n" + - "----------\n" + - "5. ERROR in X.java (at line 5)\n" + - " void foo2(Class> c) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Duplicate method foo2(Class>) in type X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation -public void test1186() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "\n" + - "public class X {\n" + - " void foo1(X x1, X x2) {\n" + - " x1 = (X) x2;\n" + - " }\n" + - " void foo2(X x1, X x2) {\n" + - " x1 = (X) x2;\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " x1 = (X) x2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " x1 = (X) x2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation -public void test1187() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.io.Serializable;\n" + - "public class X {\n" + - " void foo3(X x1, X x2) {\n" + - " x1 = (X) x2;\n" + - " } \n" + - " void foo4(X x1, X x2) {\n" + - " x1 = (X) x2;\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " x1 = (X) x2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X to X\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " x1 = (X) x2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation -public void test1188() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " > void foo(Integer i) {\n" + - " S a = (S) i; // error?\n" + - " }\n" + - " > void bar(Integer i) {\n" + - " U a = (U) i; // unchecked?\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " > void foo(Integer i) {\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 3)\n" + - " S a = (S) i; // error?\n" + - " ^^^^^\n" + - "Cannot cast from Integer to S\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " U a = (U) i; // unchecked?\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Integer to U\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation -public void test1189() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " > void foo(Number n) {\n" + - " S a = (S) n; // unchecked?\n" + - " }\n" + - " > void bar(Number n) {\n" + - " U a = (U) n; // unchecked?\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " > void foo(Number n) {\n" + - " ^^^^^^\n" + - "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " S a = (S) n; // unchecked?\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Number to S\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " U a = (U) n; // unchecked?\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Number to U\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation -public void test1190() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " > void foo2(Integer i) {\n" + - " S a = (S) i; // unchecked1?\n" + - " Comparable b = (Comparable) i; // unchecked2?\n" + - " } \n" + - " > void foo3(Integer i) {\n" + - " S a = (S) i; // error?\n" + - " Comparable b = (Comparable) i; // error3?\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " > void foo2(Integer i) {\n" + - " ^^^^^^^\n" + - "The type parameter U should not be bounded by the final type Integer. Final types cannot be further extended\n" + - "----------\n" + - "2. WARNING in X.java (at line 3)\n" + - " S a = (S) i; // unchecked1?\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from Integer to S\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " Comparable b = (Comparable) i; // unchecked2?\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Integer to Comparable\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " > void foo3(Integer i) {\n" + - " ^^^^^^\n" + - "The type parameter U should not be bounded by the final type String. Final types cannot be further extended\n" + - "----------\n" + - "5. ERROR in X.java (at line 7)\n" + - " S a = (S) i; // error?\n" + - " ^^^^^\n" + - "Cannot cast from Integer to S\n" + - "----------\n" + - "6. ERROR in X.java (at line 8)\n" + - " Comparable b = (Comparable) i; // error3?\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Integer to Comparable\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation -public void test1191() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo(SomeEnum en) {\n" + - " Enum myvar = en;\n" + - " SomeEnum en2 = (SomeEnum) myvar;\n" + - " if (myvar instanceof SomeEnum) {\n" + - " return;\n" + - " }\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "enum SomeEnum {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165352 -public void test1192() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo(ArrayList a) {\n" + - " Object o = (List) a; // ko\n" + - " }\n" + - " void bar(List a) {\n" + - " Object o = (ArrayList) a; // ko\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Object o = (List) a; // ko\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from ArrayList to List\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " Object o = (List) a; // ko\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from ArrayList to List\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " Object o = (ArrayList) a; // ko\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List to ArrayList\n" + - "----------\n" + - "4. WARNING in X.java (at line 7)\n" + - " Object o = (ArrayList) a; // ko\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unnecessary cast from List to ArrayList\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 - variation -public void test1193() { - this.runNegativeTest( - new String[] { - "X.java", - "class A {}\n" + - "class B extends A {}\n" + - "public class X {\n" + - " public void foo(X param) {\n" + - " X bar = (X) param; // unchecked warning vs error\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " X bar = (X) param; // unchecked warning vs error\n" + - " ^^^^^^^^^^^^\n" + - "Cannot cast from X to X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=120088 -public void test1194() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X t = new X();\n" + - " if (t.getClass() == Object.class)\n" + - " System.out.println(\"OK\");\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (t.getClass() == Object.class)\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Incompatible operand types Class and Class\n" + - "----------\n"); -} -public void test1195() { - this.runConformTest( - new String[] { - "java/lang/Class.java", - "package java.lang;\n" + - "public class Class {\n" + - " Class getSuperclass() { return null; }\n" + - " void foo() {\n" + - " boolean foo = getSuperclass() == Enum.class;\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -public void test1196() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " Class getSuperclass() { return null; }\n" + - " void foo() {\n" + - " boolean foo = getSuperclass() == Enum.class;\n" + - " }\n" + - "}\n" + - "class Y {\n" + - " void bar() {\n" + - " boolean bar = this.getClass().getSuperclass() == Enum.class;\n" + - " } \n" + - "}\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); -} -public void test1197() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void test() {\n" + - " B b = new C();\n" + - " Class cb = C.class;\n" + - " YYY y = new XXX();\n" + - " Class> cy = XXX.class;\n" + - " YYY yb = new XXX();\n" + - " Class> ybc = XXX.class;\n" + - " Class ybb = yb.getClass();\n" + - " Class> ybb2 = yb.getClass();\n" + - " Class> ybb3 = yb.getClass();\n" + - " }\n" + - "}\n" + - "\n" + - "class Obj {}\n" + - "class B extends Obj {}\n" + - "class C extends B {}\n" + - "class ZZZ {}\n" + - "class YYY extends ZZZ {}\n" + - "class XXX extends YYY {} \n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 9)\n" + - " Class ybb = yb.getClass();\n" + - " ^^^\n" + - "YYY is a raw type. References to generic type YYY should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " Class> ybb2 = yb.getClass();\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n" + - "3. ERROR in X.java (at line 11)\n" + - " Class> ybb3 = yb.getClass();\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Class>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation -public void test1198() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " interface Listener {}\n" + - " interface ErrorListener {} \n" + - " static Object createParser(Listener l) {\n" + - " System.out.println(\"FAILED\");\n" + - " return null;\n" + - " }\n" + - " static Object createParser(L l) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return null;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class A implements Listener, ErrorListener {\n" + - " }\n" + - " createParser(new A()); // error here\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation -public void test1198a() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " interface Listener {}\n" + - " interface ErrorListener {} \n" + - " static Object createParser(Listener l) {\n" + - " System.out.println(\"FAILED\");\n" + - " return null;\n" + - " }\n" + - " static Object createParser(L l) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return null;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class A implements Listener, ErrorListener {\n" + - " }\n" + - " createParser(new A()); // error here\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation -public void test1199() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " interface Listener {}\n" + - " interface ErrorListener {} \n" + - " static Object createParser(Listener l) {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return null;\n" + - " }\n" + - " static Object createParser(L l) {\n" + - " System.out.println(\"FAILED\");\n" + - " return null;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class A implements Listener {\n" + - " }\n" + - " createParser(new A()); // error here\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=205594 -public void test1200() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public class Map {\n" + - " }\n" + - "\n" + - " public Map make(K key, V value) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " public Map, X> method1() {\n" + - " X value = new X();\n" + - " Class type = X.class;\n" + - " return make(type, value);//1\n" + - " }\n" + - " public Map, X> method2() {\n" + - " X value = new X();\n" + - " Class type = X.class;\n" + - " return (Map, X>) make(type, value);//2\n" + - " }\n" + - " public Map, X> method3() {\n" + - " X value = new X();\n" + - " return make(X.class, value);//3\n" + - " }\n" + - " public Map, X> method4() {\n" + - " X value = new X();\n" + - " return (Map, X>) make(X.class, value);//4\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\r\n" + - " return make(type, value);//1\r\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.Map,X> to X.Map,X>\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\r\n" + - " return (Map, X>) make(type, value);//2\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X.Map,X> to X.Map,X>\n" + - "----------\n" + - "3. ERROR in X.java (at line 21)\r\n" + - " return make(X.class, value);//3\r\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.Map,X> to X.Map,X>\n" + - "----------\n" + - "4. ERROR in X.java (at line 25)\r\n" + - " return (Map, X>) make(X.class, value);//4\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from X.Map,X> to X.Map,X>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174282 -public void test1201() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public MyClass f() {\n" + - " SuperClass val = null;\n" + - " return (MyClass) val;\n" + - " }\n" + - "}\n" + - "class MyClass extends SuperClass {\n" + - "}\n" + - "class MyDataModel extends SuperDataModel {\n" + - "}\n" + - "class SuperClass {\n" + - "}\n" + - "class SuperDataModel {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230 -public void test1202() { - String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 - ? "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " X.foo();\n" + - " ^^^\n" + - "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " X.foo();\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " X.foo();\n" + - " ^^^\n" + - "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n" - : "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " X.foo();\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " X.foo();\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " X.foo();\n" + - " ^^^^\n" + - "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + - "----------\n"; - - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void foo() {}\n" + - " public static void bar() {\n" + - " X.foo();\n" + - " X.foo();\n" + - " }\n" + - "}\n", // ================= - }, - expectedOutput); -} - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230 - variation -// split because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 -public void test1203a() { - String[] sources = - new String[] { - "X.java", - "public class X {\n" + - " public static String foo(String one, String two) {\n" + - " return X.foo(one, two);\n" + - " }\n" + - " public String bar(String one, String two) {\n" + - " return this.bar(one, two);\n" + - " }\n" + - "}\n", // ================= - }; - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - runNegativeTest( - sources, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " return X.foo(one, two);\n" + - " ^^^\n" + - "The method foo(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " return this.bar(one, two);\n" + - " ^^^\n" + - "The method bar(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - } else { - runConformTest( - true, - sources, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " return X.foo(one, two);\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method foo(String, String) of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " return this.bar(one, two);\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method bar(String, String) of type X; it should not be parameterized with arguments \n" + - "----------\n", - null, null, - JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); - } -} - -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 -// this case is not solved as expected in 1.5 and 1.6 mode; keeping the 1.7 mode -// activated -public void test1203b() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - return; - } - String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 - ? "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " return this.foobar(one, two);\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " this.foobar(one, two);\n" + - " ^^^^^^\n" + - "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + - "----------\n" - : "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " return this.foobar(one, two);\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " this.foobar(one, two);\n" + - " ^^^^^^\n" + - "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + - "----------\n"; - - this.runNegativeTest( - new String[] { - "X.java", - "public class X extends Y {\n" + - " @Override\n" + - " public String foobar(String one, String two) {\n" + - " return this.foobar(one, two);\n" + - " }\n" + - " @SuppressWarnings(\"unused\")\n" + - " public String foobar2(String one, String two) {\n" + - " return this.foobar2(one, two);// silenced\n" + - " }\n" + - "}\n" + - "class Y {\n" + - " public String foobar(String one, String two) {\n" + - " return null;\n" + - " }\n" + - " void test(String one, String two) {\n" + - " this.foobar(one, two);\n" + - " }\n" + - "}\n", // ================= - }, - expectedOutput); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 -public void test1204() { - this.runConformTest( - new String[] { - "ExpressionGraph.java", - "import java.util.*;\n" + - "public class ExpressionGraph, V extends IVertex> {\n" + - " void foo(Set set, Collection col) {\n" + - " if (set == col) return;\n" + - " }\n" + - "}\n" + - "interface IVertex, V extends IVertex> { \n" + - " // empty\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 - variation -public void test1205() { - this.runConformTest( - new String[] { - "ExpressionGraph.java", - "import java.util.*;\n" + - "\n" + - "public class ExpressionGraph, V extends ExpressionVertex, L> extends AbstractGraph {\n" + - " void foo(Set set, Collection col) {\n" + - " if (set == col) return;\n" + - " }\n" + - "\n" + - " interface IVertex, V extends IVertex, L> extends ExpressionVertex { \n" + - " // empty\n" + - " }\n" + - " static abstract class Vertex, V extends IVertex, L> /*extends TaggableVertex*/ implements IVertex { \n" + - " // empty\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class AbstractGraph, V extends Vertex> implements Graph {\n" + - " // empty\n" + - "}\n" + - "interface Graph, V extends Vertex> { \n" + - " // empty\n" + - "}\n" + - "interface Vertex, V extends Vertex> {\n" + - " // empty\n" + - "}\n" + - "interface ExpressionVertex, V extends ExpressionVertex, L> extends Vertex {\n" + - " // empty\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 -public void test1206() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public final E throwE(E ex, Object... args) throws E {\n" + - " Object[] oar = new Object[0];\n" + - " return throwE(oar, ex, args);\n" + - " }\n" + - "\n" + - " public final E throwE(Object[] oar, E ex, Object... args) throws E {\n" + - " throw ex;\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation -public void test1207() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public final E throwE (E ex) throws E {\n" + - " throw ex;\n" + - " }\n" + - " void foo(Object[] objs) {\n" + - " throwE(objs);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + - " throwE(objs);\r\n" + - " ^^^^^^\n" + - "Bound mismatch: The generic method throwE(E) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation -public void test1208() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public final E throwE2(E ex, Object... args) throws E {\n" + - " Object[] oar = new Object[0];\n" + - " return throwE(oar, ex, args);\n" + - " }\n" + - "\n" + - " public final E throwE(Object[] oar, E ex, Object... args) throws E {\n" + - " throw ex;\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation -public void test1209() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public final E throwE (E ex, Object ... args) throws E {\n" + - " throw ex;\n" + - " }\n" + - " void foo(Object[] objs) {\n" + - " throwE(objs);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + - " throwE(objs);\r\n" + - " ^^^^^^\n" + - "Bound mismatch: The generic method throwE(E, Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation -public void test1210() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public final E throwE (Object ... args) throws E {\n" + - " return null;\n" + - " }\n" + - " void foo(Object[] objs) {\n" + - " Object[] o = throwE(objs);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " Object[] o = throwE(objs);\n" + - " ^^^^^^\n" + - "Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208030 -public void test1211() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(String t){\n" + - " System.out.println(t);\n" + - " Zork z;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(\"FAILED\");\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " new Local(){};\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " super(\"FAILED\");\n" + - " ^^^^^^^^^^^^^^^^\n" + - "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "3. ERROR in X.java (at line 12)\n" + - " new Local();\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "The constructor Local() of type Local is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " new Local(){};\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "The constructor Local() of type Local is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); - return; - } - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(String t){\n" + - " System.out.println(t);\n" + - " Zork z;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " class Local extends X {\n" + - " Local() {\n" + - " super(\"FAILED\");\n" + - " }\n" + - " };\n" + - " new Local();\n" + - " new Local(){};\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " super(\"FAILED\");\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " new Local();\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + - "----------\n" + - "4. WARNING in X.java (at line 13)\n" + - " new Local(){};\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + - "----------\n"); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 -// generic variants -public void test1212() { - Map customOptions = getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); - runNegativeTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X implements I {}\n" + - "class Y extends X implements I, J {}\n" + - "class Z {}" + - "interface I {}\n" + - "interface J {}\n" - }, - // compiler options - null /* no class libraries */, - customOptions /* custom options */, - // compiler results - "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 2)\n" + - " class Y extends X implements I, J {}\n" + - " ^\n" + - "Redundant superinterface I for the type Y, already defined by X\n" + - "----------\n", - // javac options - JavacTestOptions.SKIP /* skip javac tests - configured eclipse specific warning as error */); -} -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 -// generic variants - the 'different arguments' error overrides the -// redundant error -public void test1213() { - Map customOptions = getCompilerOptions(); - customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); - this.runNegativeTest( - new String[] { - "X.java", - "public class X implements I {}\n" + - "class Y extends X implements I, J {}\n" + - "class Z {}" + - "interface I {}\n" + - "interface J {}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " class Y extends X implements I, J {}\n" + - " ^\n" + - "The interface I cannot be implemented more than once with different arguments: I and I\n" + - "----------\n", - null /* no extra class libraries */, - true /* flush output directory */, - customOptions); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 -public void test1214() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " public interface Loader {\n" + - " public T load(final K key);\n" + - " }\n" + - " Loader loader;\n" + - " public T get(final K key) {\n" + - " T data = this.loader.load(key);\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBug5042462 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation -public void test1215() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " T cond1(boolean z, U x1, V x2) {\n" + - " return (z? x1: x2);\n" + - " }\n" + - "}\n", - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBug5042462 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 -public void test1216() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " p.A myA = new p.A();\n" + - " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + - " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + - " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + - " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + - " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + - " }\n" + - "}\n", - "p/A.java", - "package p;\n" + - "public class A {\n" + - " public static class Box {\n" + - " public T t;\n" + - " public void set(T t) { this.t = t; }\n" + - " public T get() { return this.t; }\n" + - " }\n" + - " private class P {\n" + - " public int pval;\n" + - " }\n" + - " public P p;\n" + - " public Box

box;\n" + - " public Box

getBox() { return this.box; }\n" + - " public A next;\n" + - " public A getNext() { return this;} \n" + - " public A() {\n" + - " this.box = new Box

();\n" + - " this.box.set(new P());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + - " ^^^^^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + - " ^^^^^^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + - " ^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + - " ^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "----------\n" + - "1. WARNING in p\\A.java (at line 18)\n" + - " this.box.set(new P());\n" + - " ^^^^^^^\n" + - "Access to enclosing constructor A.P() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation -public void test1217() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " p.A myA = new p.A();\n" + - " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + - " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + - " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + - " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + - " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + - " }\n" + - "}\n", - "p/A.java", - "package p;\n" + - "public class A {\n" + - " public static class Box {\n" + - " public T t;\n" + - " public void set(T t) { this.t = t; }\n" + - " public T get() { return this.t; }\n" + - " }\n" + - " protected class P {\n" + - " public int pval;\n" + - " }\n" + - " public P p;\n" + - " public Box

box;\n" + - " public Box

getBox() { return this.box; }\n" + - " public A next;\n" + - " public A getNext() { return this;} \n" + - " public A() {\n" + - " this.box = new Box

();\n" + - " this.box.set(new P());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + - " ^^^^^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + - " ^^^^^^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + - " ^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + - " ^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation -public void test1218() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " p.A myA = new p.A();\n" + - " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + - " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + - " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + - " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + - " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + - " }\n" + - "}\n", - "p/A.java", - "package p;\n" + - "public class A {\n" + - " public static class Box {\n" + - " public T t;\n" + - " public void set(T t) { this.t = t; }\n" + - " public T get() { return this.t; }\n" + - " }\n" + - " class P {\n" + - " public int pval;\n" + - " }\n" + - " public P p;\n" + - " public Box

box;\n" + - " public Box

getBox() { return this.box; }\n" + - " public A next;\n" + - " public A getNext() { return this;} \n" + - " public A() {\n" + - " this.box = new Box

();\n" + - " this.box.set(new P());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + - " ^^^^^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + - " ^^^^^^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + - " ^^^\n" + - "The type A.P is not visible\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + - " ^^^^^^^^^\n" + - "The type A.P is not visible\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209779 -public void test1219() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " final List stringList = new ArrayList();\n" + - " stringList.add(\"test1\");\n" + - " stringList.add(\"test2\");\n" + - " ((List) stringList).add(new Integer(1000));\n" + - " try {\n" + - " Object o = stringList.get(2);\n" + - " } catch (ClassCastException e) {\n" + - " System.out.print(\"[ClassCastException1]\");\n" + - " }\n" + - " try {\n" + - " String s = stringList.get(2);\n" + - " } catch (ClassCastException e) {\n" + - " System.out.print(\"[ClassCastException2]\");\n" + - " } \n" + - " try {\n" + - " for (Object obj : stringList) {\n" + - " System.out.print(obj);\n" + - " }\n" + - " } catch (ClassCastException e) {\n" + - " System.out.print(\"[ClassCastException3]\");\n" + - " } \n" + - " try {\n" + - " for (String str : stringList) {\n" + - " System.out.print(str);\n" + - " }\n" + - " } catch (ClassCastException e) {\n" + - " System.out.print(\"[ClassCastException4]\");\n" + - " }\n" + - " System.out.println();\n" + - " }\n" + - "}\n" - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "[ClassCastException2]test1test21000test1test2[ClassCastException4]" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.JavacHasABug.JavacBug6500701 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209152 -public void test1220() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public static void doIt(List list) {\n" + - " list.add(list.remove(0));\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " list.add(list.remove(0));\n" + - " ^^^\n" + - "The method add(capture#1-of ?) in the type List is not applicable for the arguments (capture#2-of ?)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209071 -public void test1221() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "public class X {\n" + - " void foo() {\n" + - " Set listSet = new HashSet();\n" + - " Set otherListSet = new HashSet();\n" + - " otherListSet.add((List) listSet); \n" + - " }\n" + - " void bar() {\n" + - " Set stringSet = new HashSet();\n" + - " Set otherStringSet = new HashSet();\n" + - " otherStringSet.add((String) stringSet); \n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new X().foo();\n" + - " new X().bar();\n" + - " }\n" + - "} \n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Set listSet = new HashSet();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " Set listSet = new HashSet();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " Set otherListSet = new HashSet();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 5)\n" + - " Set otherListSet = new HashSet();\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 6)\n" + - " otherListSet.add((List) listSet); \n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "6. ERROR in X.java (at line 11)\n" + - " otherStringSet.add((String) stringSet); \n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Set to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207959 -public void test1222() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " T get() { return null; }\n" + - " void foo2(X x2) {\n" + - " Runnable r = x2.get();\n" + - " } \n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=211718 -public void test1223() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Arrays;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " public static enum IsABug {\n" + - " TRUE,\n" + - " FALSE;\n" + - " } \n" + - " public List getPossibleBugStates() {\n" + - " String s1 = IsABug.values();\n" + - " String s2 = IsABug.valueOf(s1);\n" + - " return Arrays.asList(IsABug.values());\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " String s1 = IsABug.values();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.IsABug[] to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " String s2 = IsABug.valueOf(s1);\n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.IsABug to String\n" + - "----------\n"); -} -public void test1224() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.Collection;\n" + - "import java.util.Collections;\n" + - "public class X {\n" + - " class Request,V> {}\n" + - " class RequestMap {\n" + - " public ,W> R intersection (Collection c) {\n" + - " return null;\n" + - " }\n" + - " }\n" + - " class DeltaRequest extends Request {}\n" + - " public void test () {\n" + - " RequestMap m = new RequestMap ();\n" + - " Collection c = Collections.singleton (new DeltaRequest ());\n" + - " DeltaRequest o = m.intersection (c);\n" + - " }\n" + - "}\n" - }, - ""); -} -public void test1225() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.Collection;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " static void m(List list, Collection coll) {\n" + - " m(list, coll);\n" + - " }\n" + - "}\n" - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -public void test1226() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " class M {\n" + - " X foo() { return null; }\n" + - " }\n" + - " void bar(M m) {\n" + - " X xt = m.foo();\n" + // no unchecked warning - " Zork z;\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\r\n" + - " Zork z;\r\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -public void test1227() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Arrays;\n" + - "public class X {\n" + - " void foo() {\n" + - " Arrays.asList(String.class, Integer.class);\n" + - " }\n" + - " Zork z;\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Arrays.asList(String.class, Integer.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 -public void test1228() throws Exception { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(Y b1, U b2) {\n" + - " }\n" + - " public class Binner {\n" + - " public class BinnerInner {\n" + - " public BinnerInner $new$() {\n" + - " return new BinnerInner();\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n" - }, - ""); - // check $new$ method generic signature - String expectedOutput = - " // Method descriptor #22 ()LX$Binner$BinnerInner;\n" + - " // Signature: ()LX.Binner.BinnerInner;\n" + - " // Stack: 3, Locals: 1\n" + - " public X.Binner.BinnerInner $new$();\n" + - " 0 new X$Binner$BinnerInner [1]\n" + - " 3 dup\n" + - " 4 aload_0 [this]\n" + - " 5 getfield X$Binner$BinnerInner.this$1 : X.Binner [10]\n" + - " 8 invokespecial X$Binner$BinnerInner(X$Binner) [25]\n" + - " 11 areturn\n" + - " Line numbers:\n" + - " [pc: 0, line: 7]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 12] local: this index: 0 type: X.Binner.BinnerInner\n" + - " Local variable type table:\n" + - " [pc: 0, pc: 12] local: this index: 0 type: X.Binner.BinnerInner\n"; - - File f = new File(OUTPUT_DIR + File.separator + "X$Binner$BinnerInner.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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation -public void test1229() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(Y b1, U b2) {\n" + - " }\n" + - " public class Binner {\n" + - " public class BinnerInner {\n" + - " public BinnerInner $new$() {\n" + - " return new BinnerInner();\n" + - " }\n" + - " X root() {\n" + - " return X.this;\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n", - "Z.java", - "public class Z {\n" + - " public static void main(String[] args) {\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " String s = binString.$new$().root();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^\n" + - "The type parameter U should not be bounded by the final type Class. Final types cannot be further extended\n" + - "----------\n" + - "----------\n" + - "1. WARNING in Z.java (at line 3)\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in Z.java (at line 3)\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "3. ERROR in Z.java (at line 4)\n" + - " String s = binString.$new$().root();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation -public void test1230() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(Y b1, U b2) {\n" + - " }\n" + - " public class Binner {\n" + - " public class BinnerInner {\n" + - " public BinnerInner $new$() {\n" + - " return new BinnerInner();\n" + - " }\n" + - " X root() {\n" + - " return X.this;\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); - this.runNegativeTest( - new String[] { - "Z.java", - "public class Z {\n" + - " public static void main(String[] args) {\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " String s = binString.$new$().root();\n" + - " }\n" + - "}\n" - }, - "----------\n" + - "1. WARNING in Z.java (at line 3)\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. WARNING in Z.java (at line 3)\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "3. ERROR in Z.java (at line 4)\n" + - " String s = binString.$new$().root();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X to String\n" + - "----------\n", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation -public void test1231() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public X(Y b1, U b2) {\n" + - " }\n" + - " public class Binner {\n" + - " public class BinnerInner {\n" + - " public BinnerInner $new$() {\n" + - " return new BinnerInner();\n" + - " }\n" + - " X root() {\n" + - " return X.this;\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n", - }, - ""); - this.runConformTest( - new String[] { - "Z.java", - "public class Z {\n" + - " public static void main(String[] args) {\n" + - " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + - " X.Binner.BinnerInner binNumber = binString.$new$();\n" + - " }\n" + - "}\n" - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 -public void test1232() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface {\n" + - " public Integer getNumber();\n" + - " public SubInterface and(SuperInterface s);\n" + - " }\n" + - "}\n", - }, - ""); - -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1233() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface {\n" + - " public Integer getNumber();\n" + - " public SubInterface and(SuperInterface s);\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1234() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n" + - " void a3(G x) {} \n" + - " > void a3(T x) {}\n" + - "\n" + - " public static void ambiguousCases() { \n" + - " H hx = null;\n" + - " H hraw = null;\n" + - " new X().a3(hx);\n" + - " new X().a3(hraw);\n" + - " } \n" + - "}\n" + - "class F {} \n" + - "class G extends F {}\n" + - "class H extends G {}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " void a3(G x) {} \n" + - " ^\n" + - "G is a raw type. References to generic type G should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " H hraw = null;\n" + - " ^\n" + - "H is a raw type. References to generic type H should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " new X().a3(hx);\n" + - " ^^\n" + - "The method a3(G) is ambiguous for the type X\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " new X().a3(hraw);\n" + - " ^^\n" + - "The method a3(G) is ambiguous for the type X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1235() { - this.runConformTest( - new String[] { - "X.java", - "public class X { \n" + - " > void a3(T x) {}\n" + - " > void a3(T x) {}\n" + - "\n" + - " public static void ambiguousCases() { \n" + - " H hx = null;\n" + - " H hraw = null;\n" + - " new X().a3(hx);\n" + - " new X().a3(hraw);\n" + - " } \n" + - "}\n" + - "class F {} \n" + - "class G extends F {}\n" + - "class H extends G {}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1236() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + - " public Integer getNumber();\n" + - " public SubInterface and(SuperInterface s);\n" + - " }\n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " }\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1237() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + - " }\n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: The method and(X.SuperInterface) belongs to the raw type X.OtherSubInterface. References to generic type X.OtherSubInterface should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.OtherSubInterface to X.SubInterface\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "X.OtherSubInterface is a raw type. References to generic type X.OtherSubInterface should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1238() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + - " }\n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from X.OtherSubInterface to X.SubInterface\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1239() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface {\n" + - " public Integer getNumber();\n" + - " public SubInterface and(SuperInterface s);\n" + - " }\n" + - " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + - " \n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " }\n" + - "}\n", - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " ^^^\n" + - "The method and(X.SuperInterface) is ambiguous for the type X.CombinedSubInterface\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " public interface SubInterface extends SuperInterface {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " public SubInterface and(SuperInterface s);\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "The return type is incompatible with X.OtherSubInterface.and(X.SuperInterface), X.SubInterface.and(X.SuperInterface)\n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 16)\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " ^^^^^^^^^^^^^^\n" + - "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1240() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + - " SubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public Number getNumber();\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface {\n" + - " public Integer getNumber();\n" + - " public SubInterface and(SuperInterface s);\n" + - " }\n" + - " public interface OtherSubInterface extends SubInterface {\n" + - " public OtherSubInterface and(SuperInterface a);\n" + - " }\n" + - " public interface CombinedSubInterface extends OtherSubInterface {}\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation -public void test1241() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + - " CombinedSubInterface sub3 = sub1.and(sub2);\n" + - " }\n" + - " public interface SuperInterface {\n" + - " public SuperInterface and(SuperInterface a);\n" + - " }\n" + - " public interface SubInterface extends SuperInterface {\n" + - " }\n" + - " public interface OtherSubInterface extends SuperInterface {\n" + - " public CombinedSubInterface and(SuperInterface a);\n" + - " }\n" + - " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + - "}\n", - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=164665 -public void test1242() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.LinkedList;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " public void testCase() {\n" + - " TypedCollection collection = TypedCollectionFactory.createTypedCollection(SubTypeClass.class);\n" + - " collection.add(new SubTypeClass());\n" + - " List list = collection.list();\n" + - " assert (list.size() > 0);\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class SuperTypeAbstractClass {\n" + - "}\n" + - "\n" + - "class SubTypeClass extends SuperTypeAbstractClass {\n" + - "}\n" + - "\n" + - "interface TypedCollection {\n" + - " TypedCollection add(T object);\n" + - " List list();\n" + - "}\n" + - "\n" + - "class TypedCollectionFactory {\n" + - " public static TypedCollection createTypedCollection(Class c) {\n" + - " return new TypedCollectionImpl();\n" + - " }\n" + - "}\n" + - "\n" + - "class TypedCollectionImpl implements TypedCollection {\n" + - " private List list = new LinkedList();\n" + - " public TypedCollection add(T object) {\n" + - " list.add(object);\n" + - " return (this);\n" + - " }\n" + - " public List list() {\n" + - " return list;\n" + - " }\n" + - "}\n", // ================= - }, - // javac options - JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 -public void test1243() { - this.runConformTest( - new String[] { - "eclipse/modifier/impl/EclipseModifierBug.java", - "package eclipse.modifier.impl;\n" + - "import eclipse.modifier.Pool;\n" + - "public class EclipseModifierBug {\n" + - " static class MyEntry extends Pool.AbstractEntry { } \n" + - " static final Pool pool=new Pool() {\n" + - " @Override\n" + - " protected MyEntry delegate() {\n" + - " return new MyEntry();\n" + - " } \n" + - " };\n" + - " public static void main(String[] args) {\n" + - " MyEntry entry=pool.m(); \n" + - " }\n" + - "}", // ================= - "eclipse/modifier/Pool.java", - "package eclipse.modifier;\n" + - "public abstract class Pool> {\n" + - " static abstract class Entry> {\n" + - " E next;\n" + - " }\n" + - " static public class AbstractEntry> extends Entry {\n" + - " }\n" + - " public E m() {\n" + - " return delegate();\n" + - " }\n" + - " protected abstract E delegate();\n" + - " }\n" + - "\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation -public void test1244() { - runConformTest( - // test directory preparation - true /* flush output directory */, - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " static class MyEntry extends Pool.AbstractEntry { } \n" + - " static final Pool pool=new Pool() {\n" + - " @Override\n" + - " protected MyEntry delegate() {\n" + - " return new MyEntry();\n" + - " } \n" + - " };\n" + - " public static void main(String[] args) {\n" + - " MyEntry entry=pool.m();\n" + - " }\n" + - "}\n" + - "\n" + - "abstract class Pool> {\n" + - " private static abstract class Entry> {\n" + - " E next;\n" + - " }\n" + - " static public class AbstractEntry> extends Entry {\n" + - " }\n" + - " public E m() {\n" + - " System.out.println(\"SUCCESS\");\n" + - " return delegate();\n" + - " }\n" + - " protected abstract E delegate();\n" + - "}\n", // ================= - }, - // compiler results - null /* do not check compiler log */, - // runtime results - "SUCCESS" /* expected output string */, - "" /* expected error string */, - // javac options - JavacTestOptions.EclipseJustification.EclipseBug185422 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation -public void test1245() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "}\n" + - "class Secondary {\n" + - " static private class Private {}\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X {\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "The type Secondary.Private is not visible\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation -public void test1246() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - " static private class Private {}\n" + - " void foo(U u) {}\n" + - "}\n", // ================= - }, - // javac options - JavacTestOptions.EclipseJustification.EclipseBug185422 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 -public void test1247() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - "\n" + - " public static void test() {\n" + - " Foo foo = null;\n" + - " eval(foo); // fails\n" + - " X.> eval(foo);\n" + - " }\n" + - "\n" + - " public static > void eval(T x) {\n" + - " }\n" + - " public static interface Foo extends Iterable> {\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " eval(foo); // fails\n" + - " ^^^^\n" + - "Bound mismatch: The generic method eval(T) of type X is not applicable for the arguments (X.Foo). The inferred type X.Foo is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 - variation -public void test1248() { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "public class X {\n" + - "\n" + - " public static void test() {\n" + - " Foo foo = null;\n" + - " eval(foo); // fails\n" + - " X.> eval(foo);\n" + - " }\n" + - "\n" + - " public static > void eval(T x) {\n" + - " }\n" + - " public static interface Foo extends Iterable> {\n" + - " }\n" + - "}", // ================= - }, - // javac options - JavacTestOptions.EclipseHasABug.EclipseBug216558 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 - variation -public void test1249() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void test() {\n" + - " Foo foo = null;\n" + - " eval(foo, foo);\n" + - " X.> eval(foo, foo);\n" + - " }\n" + - " public static > void eval(T t1, T t2) {\n" + - " }\n" + - " public static interface Foo extends Iterable> {\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 -public void test1250() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " static List asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static List> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1251() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static T asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static Sub LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216608 -public void test1252() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Zork z;\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " public B getB() {\n" + - " return new B();\n" + - " }\n" + - "\n" + - " @SuppressWarnings(\"unused\")\n" + - " public void test() {\n" + - " C c = getB().getC();\n" + - " String s = getB().toString();\n" + - " }\n" + - "}\n" + - "class B {\n" + - " public C getC() {\n" + - " return new C();\n" + - " }\n" + - "}\n" + - "class C {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\r\n" + - " Zork z;\r\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 10)\r\n" + - " C c = getB().getC();\r\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The expression of type C needs unchecked conversion to conform to C\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216608 - variation -public void test1253() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " Zork z;\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " public B getB() {\n" + - " return new B();\n" + - " }\n" + - "\n" + - " @SuppressWarnings(\"unused\")\n" + - " public void test() {\n" + - " C c = getB().getC();\n" + - " String s = getB().toString();\n" + - " }\n" + - "}\n" + - "class B {\n" + - " public C getC() {\n" + - " return new C();\n" + - " }\n" + - "}\n" + - "class C {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\r\n" + - " Zork z;\r\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1254() { - this.runConformTest( - new String[] { - "X.java", - " import java.util.List;\n" + - "\n" + - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1255() { - this.runNegativeTest( - new String[] { - "X.java", - " import java.util.List;\n" + - "\n" + - "public class X {\n" + - " static XList asList(T x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub ARRAY = new Sub() { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " static XList> LIST = asList(ARRAY); \n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from XList> to XList>\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " static Sub ARRAY = new Sub() { };\n" + - " ^^^\n" + - "X.Foo.Sub is a raw type. References to generic type X.Foo.Sub should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1256() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1257() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + - "----------\n" + - "2. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1258() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1259() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " static XList> LIST = asList(ARRAY); \n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from XList> to XList>\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1260() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1261() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\r\n" + - " static XList> LIST = asList(ARRAY); \r\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from XList> to XList>\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\r\n" + - " static Sub[] ARRAY = new Sub[] { };\r\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1262() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\r\n" + - " static XList> LIST = asList(ARRAY); \r\n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from XList> to XList>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1263() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static XList asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static XList> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}\n" + - "\n" + - "class XList {\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " static XList> LIST = asList(ARRAY); \n" + - " ^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from XList> to XList>\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1264() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " static List asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static List> LIST = asList(ARRAY); \n" + - " }\n" + - " static X.Foo.Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1265() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " static List asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static List> LIST = asList(ARRAY); \n" + - " }\n" + - " static Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation -public void test1266() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " static List asList(T[] x) { return null; }\n" + - " static interface Foo {\n" + - " static interface Sub extends Foo {\n" + - " static List> LIST = asList(ARRAY); \n" + - " }\n" + - " static Foo.Sub[] ARRAY = new Sub[] { };\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216705 -public void test1267() { - this.runConformTest( - new String[] { - "X.java", - "import java.util.List;\n" + - "public class X {\n" + - " static interface Foo {\n" + - " }\n" + - " static interface SubFoo extends Foo {\n" + - " }\n" + - " static abstract class AbstractTest {\n" + - " protected static class Bar {\n" + - " }\n" + - " protected abstract List> get();\n" + - " }\n" + - " static class Test extends AbstractTest {\n" + - " @Override\n" + - " protected List> get() {\n" + - " return null;\n" + - " }\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216692 -public void test1268() { - this.runConformTest( - new String[] { - "pkg1/Foo.java", - "package pkg1;\n" + - "import java.util.Map;\n" + - "public class Foo {\n" + - " protected final Map fields = null;\n" + - " protected static class Field { }\n" + - "}\n", - "pkg2/SubFoo.java", - "package pkg2;\n" + - "import pkg1.Foo;\n" + - "public class SubFoo extends Foo {\n" + - " private Field field = null;\n" + - " private void test() {\n" + - " Field field = fields.get(\"test\");\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 -public void test1269() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1270() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TO x, final OO y) { // # 2\n" + - " System.out.println(\"#2#\");\n" + - " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#2#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1271() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.println(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 24)\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " ^^^\n" + - "The method put(Class, X.TO) in the type X is not applicable for the arguments (Class, X.OO)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1272() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.print(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " put(Integer.class, (TO)combine(FUNC2, FUNC1));\n" + - " } catch(ClassCastException e) {\n" + - " System.out.println(\"#CLASSCAST#\");\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - "#3##CLASSCAST#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1273() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static TO combine(final TO x, final OO y) { // # 2\n" + - " System.out.println(\"#2#\");\n" + - " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1274() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static TO combine(final TO x, final OO y) { // # 2\n" + - " System.out.println(\"#2#\");\n" + - " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1275() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.println(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1276() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.println(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1277() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TO x, final OO y) { // # 2\n" + - " System.out.println(\"#2#\");\n" + - " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.println(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#2#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1278() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static TO combine(final TO x, final OO y) { // # 2\n" + - " System.out.println(\"#2#\");\n" + - " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.println(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1279() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " // some functor and functor instances definitions\n" + - " static interface OO { \n" + - " public T eval(E x);\n" + - " }\n" + - " static interface TO extends OO {\n" + - " public String eval(T x);\n" + - " }\n" + - " static interface TT extends TO {\n" + - " public String eval(String x);\n" + - " }\n" + - " static final TO FUNC1 = null;\n" + - " static final TT FUNC2 = null;\n" + - "\n" + - " // some functor combinators\n" + - " static TO combine(final TT x, final TO y) { // # 1\n" + - " System.out.println(\"#1#\");\n" + - " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static TO combine(final TO x, final OO y) { // # 2\n" + - " System.out.println(\"#2#\");\n" + - " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + - " }\n" + - " static OO combine(final OO x, final OO y) { // # 3\n" + - " System.out.println(\"#3#\");\n" + - " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + - " }\n" + - " // body of the test\n" + - " static void put(Class type, TO func) {\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + - " }\n" + - "}\n", // ================= - }, - "#1#"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1280() { - this.runConformTest( - new String[] { - "X.java", - "interface OO {}\n" + - "interface TO extends OO {}\n" + - "interface TT extends TO {}\n" + - "\n" + - "public class X {\n" + - " TO combine(final TO x, final OO y) { return null; }\n" + - " void foo(TT tt, TO too) {\n" + - " combine(tt, too);\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1281() { - this.runConformTest( - new String[] { - "X.java", - "interface OO {}\n" + - "interface TO extends OO {}\n" + - "interface TT extends TO {}\n" + - "\n" + - "public class X {\n" + - " TO combine(final TO x, final OO[] y) { return null; }\n" + - " void foo(TT tt, TO[] too) {\n" + - " combine(tt, too);\n" + - " }\n" + - "}", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1282() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static interface OO {}\n" + - " static interface TO extends OO {}\n" + - " static interface TT extends TO {}\n" + - " \n" + - " TO combine(TT x, TO y) { return null; }\n" + - " void foo(TO too, OO oo) {\n" + - " combine(too, oo);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\r\n" + - " combine(too, oo);\r\n" + - " ^^^^^^^\n" + - "The method combine(X.TT, X.TO) in the type X is not applicable for the arguments (X.TO, X.OO)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation -public void test1283() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " static interface OO {}\n" + - " static interface TO extends OO {}\n" + - " static interface TT extends TO {}\n" + - " \n" + - " TO combine(TT[] x, TO[] y) { return null; }\n" + - " void foo(TO[] too, OO[] oo) {\n" + - " combine(too, oo);\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\r\n" + - " combine(too, oo);\r\n" + - " ^^^^^^^\n" + - "The method combine(X.TT[], X.TO[]) in the type X is not applicable for the arguments (X.TO[], X.OO[])\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 -public void test1284() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Thread th = Thread.currentThread();\n" + - " Z z1 = new Z(th);\n" + - " Z z2 = new Z(new Exception());\n" + - " Y y = new Y() {};\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "abstract class Y {\n" + - " I2 foo(I1 i) {\n" + - " return (I2) i;\n" + - " }\n" + - "}\n" + - "interface I1 {\n" + - "}\n" + - "interface I2 extends I1 {\n" + - " U get();\n" + - "}\n" + - "class Z implements I2 {\n" + - " W w;\n" + - " Z(W w) {\n" + - " this.w = w;\n" + - " }\n" + - " public W get() {\n" + - " return this.w;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " return (I2) i;\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from I1 to I2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation -public void test1285() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Thread th = Thread.currentThread();\n" + - " Z z1 = new Z(th);\n" + - " Z z2 = new Z(new Exception());\n" + - " Y y = new Y() {};\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " y.foo(z2).get().getThreadGroup();\n" + - " }\n" + - "}\n" + - "abstract class Y {\n" + - " I2 foo(I1 i) {\n" + - " return (I2) i;\n" + - " }\n" + - "}\n" + - "interface I1 {\n" + - "}\n" + - "interface I2 extends I1 {\n" + - " U get();\n" + - "}\n" + - "class Z implements I2 {\n" + - " W w;\n" + - " Z(W w) {\n" + - " this.w = w;\n" + - " }\n" + - " public W get() {\n" + - " return this.w;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " y.foo(z2).get().getThreadGroup();\n" + - " ^^^\n" + - "The method foo(I1) in the type Y is not applicable for the arguments (Z)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation -public void test1286() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Thread th = Thread.currentThread();\n" + - " Z z1 = new Z(th);\n" + - " Z z2 = new Z(new Exception());\n" + - " Y y = new Y() {};\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "abstract class Y {\n" + - " I2 foo(I1 i) {\n" + - " return (I2) i;\n" + - " }\n" + - "}\n" + - "interface I1 {}\n" + - "interface I2 extends I1 {\n" + - " U get();\n" + - "}\n" + - "class Z implements I2 {\n" + - " W w;\n" + - " Z(W w) {\n" + - " this.w = w;\n" + - " }\n" + - " public W get() {\n" + - " return this.w;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " return (I2) i;\n" + - " ^^^^^^^^^\n" + - "Type safety: Unchecked cast from I1 to I2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation -public void test1287() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Thread th = Thread.currentThread();\n" + - " Z z1 = new Z(th);\n" + - " Z z2 = new Z(new Exception());\n" + - " Y y = new Y() {};\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "abstract class Y {\n" + - " I2 foo(I1 i) {\n" + - " return (I2) i;\n" + - " }\n" + - "}\n" + - "interface I1 {}\n" + - "interface I2 extends I1 {\n" + - " G get();\n" + - "}\n" + - "class Z implements I2 {\n" + - " W w;\n" + - " Z(W w) {\n" + - " this.w = w;\n" + - " }\n" + - " public W get() {\n" + - " return this.w;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 14)\n" + - " return (I2) i;\n" + - " ^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from I1 to I2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation -public void test1288() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Thread th = Thread.currentThread();\n" + - " Z z1 = new Z(th);\n" + - " Z z2 = new Z(new Exception());\n" + - " Y y = new Y() {};\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "abstract class Y {\n" + - " I2 foo(I1> i) {\n" + - " return (I2) i;\n" + - " }\n" + - "}\n" + - "interface I1 {}\n" + - "interface I2 extends I1> {\n" + - " G get();\n" + - "}\n" + - "class Z implements I2 {\n" + - " W w;\n" + - " Z(W w) {\n" + - " this.w = w;\n" + - " }\n" + - " public W get() {\n" + - " return this.w;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in X.java (at line 15)\n" + - " return (I2) i;\n" + - " ^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from I1> to I2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation -public void test1289() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Map;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Thread th = Thread.currentThread();\n" + - " Z z1 = new Z(th);\n" + - " Z z2 = new Z(new Exception());\n" + - " Y y = new Y() {};\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + - " Zork z;\n" + - " }\n" + - "}\n" + - "abstract class Y {\n" + - " I2 foo(I1> i) {\n" + - " return (I2) i;\n" + - " }\n" + - "}\n" + - "interface I1 {}\n" + - "interface I2 extends I1> {\n" + - " G get();\n" + - "}\n" + - "class Z implements I2 {\n" + - " W w;\n" + - " Z(W w) {\n" + - " this.w = w;\n" + - " }\n" + - " public W get() {\n" + - " return this.w;\n" + - " }\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " y.foo(z1).get().getThreadGroup();\n" + - " ^^^\n" + - "The method foo(I1>) in the type Y is not applicable for the arguments (Z)\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + - " ^^^\n" + - "The method foo(I1>) in the type Y is not applicable for the arguments (Z)\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "4. ERROR in X.java (at line 15)\n" + - " return (I2) i;\n" + - " ^^^^^^^^^^^\n" + - "Cannot cast from I1> to I2\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation -public void test1290() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " K foo(I i) {\n" + - " return (K) i;\n" + - " }\n" + - " Zork z;\n" + - "}\n" + - "interface I {\n" + - "}\n" + - "interface J extends I {\n" + - "}\n" + - "interface K extends J {\n" + - "}", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 -public void test1291() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " public static List moreGeneric(List list) {\n" + - " List result = new ArrayList();\n" + - " result.addAll( list );\n" + - " return result;\n" + - " }\n" + - " class A {}\n" + - " class B extends A {}\n" + - " class C extends B {}\n" + - " public static void main( String[] args ) {\n" + - " List b = new ArrayList();\n" + - " List a = moreGeneric(b);\n" + - " List c = moreGeneric(b);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " List c = moreGeneric(b);\n" + - " ^^^^^^^^^^^\n" + - "Bound mismatch: The generic method moreGeneric(List) of type X is not applicable for the arguments (List). The inferred type X.B is not a valid substitute for the bounded parameter \n" + - "----------\n", - JavacTestOptions.EclipseJustification.EclipseBug218677); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 - variation -public void test1292() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " public static List moreSpecific(List list) {\n" + - " List result = new ArrayList();\n" + - " result.addAll( (List)list );\n" + - " return result;\n" + - " }\n" + - " class A {}\n" + - " class B extends A {}\n" + - " class C extends B {}\n" + - " public static void main( String[] args ) {\n" + - " List b = new ArrayList();\n" + - " List a = moreSpecific(b);\n" + - " List c = moreSpecific(b);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " result.addAll( (List)list );\n" + - " ^^^^^^\n" + - "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + - "----------\n" + - "2. ERROR in X.java (at line 14)\n" + - " List a = moreSpecific(b);\n" + - " ^^^^^^^^^^^^\n" + - "Bound mismatch: The generic method moreSpecific(List) of type X is not applicable for the arguments (List). The inferred type X.A is not a valid substitute for the bounded parameter \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 -public void test1293() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class Table {\n" + - " State s;\n" + - " Table() {\n" + - " this.s = new State();\n" + - " }\n" + - " class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation -public void test1294() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Table {\n" + - " State s;\n" + - " Table() {\n" + - " this.s = new State();\n" + - " }\n" + - " class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation -public void test1295() { - this.runNegativeTest( - new String[] { - "X.java", - "class Deejay {\n" + - " class Counter {}\n" + - "\n" + - " Deejay.Counter songCounter = new Deejay.Counter();\n" + - " Deejay.Counter genreCounter = new Deejay.Counter();\n" + - "\n" + - " java.util.List> list1 = java.util.Arrays.asList(songCounter, genreCounter);\n" + - " java.util.List> list2 = java.util.Arrays.asList(songCounter, genreCounter);\n" + - " java.util.List> list3 = java.util.Arrays.>asList(songCounter, genreCounter);\n" + - " java.util.List> list4 = java.util.Arrays.asList(new Deejay.Counter[] {songCounter, genreCounter});\n" + - " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\n" + - "}\n" + - "class Genre {}\n" + - "class Song {}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\r\n" + - " java.util.List> list1 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\r\n" + - " java.util.List> list2 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\r\n" + - " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 11)\r\n" + - " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List> to List>\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation -public void test1296() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class Table {\n" + - " Table.State s;\n" + - "\n" + - " Table() {\n" + - " this.s = new Table.State();\n" + - " }\n" + - "\n" + - " class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation -public void test1297() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " class Table {\n" + - " X.Table.State s;\n" + - "\n" + - " Table() {\n" + - " this.s = new X().new Table().new State();\n" + - " }\n" + - "\n" + - " class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation -public void test1298() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Table {\n" + - " X.Table.State s;\n" + - "\n" + - " Table() {\n" + - " this.s = new X.Table().new State();\n" + - " }\n" + - "\n" + - " class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 -public void test1299() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Table {\n" + - " X.Table.State s;\n" + - "\n" + - " Table() {\n" + - " this.s = new X.Table.State();\n" + - " }\n" + - "\n" + - " static class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation -public void test1300() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Table {\n" + - " State s;\n" + - "\n" + - " Table() {\n" + - " this.s = new State();\n" + - " }\n" + - "\n" + - " static class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation -public void test1301() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " static class Table {\n" + - " Table.State s;\n" + - "\n" + - " Table() {\n" + - " this.s = new Table.State();\n" + - " }\n" + - "\n" + - " static class State {\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation -public void test1302() { - runConformTest( - true, - new String[] { - "EMap.java", - "import java.util.ArrayList;\n" + - "import java.util.Map;\n" + - "\n" + - "public abstract class EMap implements Map {\n" + - " public abstract static class Unsettable extends EMap {\n" + - " protected class UnsettableEList> extends EList {\n" + - " }\n" + - " }\n" + - " protected class EList> extends ArrayList{\n" + - " }\n" + - "}\n", // ================= - }, - null, - "", - null, - JavacTestOptions.EclipseHasABug.EclipseBug159851); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 -public void test1303() { - this.runConformTest( - new String[] { - "X.java", - "public class X {\n" + - " interface Foo {\n" + - " T getValue();\n" + - " void doSomething(T o);\n" + - " }\n" + - " public static abstract class AbstractFoo implements Foo {\n" + - " /**\n" + - " * If this is removed ConcreteFoo no longer compiles.\n" + - " */\n" + - " public void doSomething(final String o) {\n" + - " }\n" + - " }\n" + - " public static final class ConcreteFoo extends AbstractFoo {\n" + - " public String getValue() {\n" + - " return \"I am a string\";\n" + - " }\n" + - " }\n" + - " /**\n" + - " * We lose the type infomation here so try but fail to call the doSomething(Object) method.\n" + - " */\n" + - " private static void feedFoosValueIntoFoo(final Foo foo) {\n" + - " foo.doSomething(foo.getValue());\n" + - " }\n" + - " private static void testTypedString() {\n" + - " final ConcreteFoo foo = new ConcreteFoo();\n" + - " foo.doSomething(foo.getValue());\n" + - " }\n" + - " private static void testGenericString() {\n" + - " feedFoosValueIntoFoo(new ConcreteFoo());\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " testTypedString();\n" + - " testGenericString();\n" + - " System.out.println(\"SUCCESS\");\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 - variation -public void test1304() { - this.runConformTest( - new String[] { - "X.java", - "interface Foo {\n" + - " T get();\n" + - " void doSomething(T t);\n" + - "}\n" + - "abstract class XSuper implements Foo {\n" + - " public void doSomething(String s) { System.out.println(s); }\n" + - "}\n" + - "public class X extends XSuper {\n" + - " public String get() { return \"SUCCESS\"; }\n" + - " static void doIt(Foo f) {\n" + - " f.doSomething(f.get());\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " doIt(new X());\n" + - " }\n" + - "}\n", // ================= - }, - "SUCCESS"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223334 -public void test1305() { - this.runConformTest( - new String[] { - "bug/ConflictManager.java",// ================= - "package bug;\n" + - "import java.util.*;\n" + - "public class ConflictManager {\n" + - " public List>> getConflictsSortedBySize() {\n" + - " return null;\n" + - " }\n" + - "}\n", - "bug/LayoutOrganizable.java",// ================= - "package bug;\n" + - "public class LayoutOrganizable {\n" + - " private T t;\n" + - "\n" + - " public LayoutOrganizable(T t) {\n" + - " this.t = t;\n" + - "\n" + - " }\n" + - "}\n", - "bug/LayoutOrganizer.java", - "package bug;\n" + - "import java.util.*;\n" + - "public class LayoutOrganizer {\n" + - " ConflictManager> conflictManager = new ConflictManager>();\n" + - " private boolean optimizeEqual() {\n" + - " List>>> list;\n" + - " ListIterator>>> i;\n" + - " // create sorted list of pairs\n" + - " // (#conflicts, list of LayoutOrganizable sharing this #conflicts)\n" + - " // Here is the problem...\n" + - " list = conflictManager.getConflictsSortedBySize();\n" + - " return null == list;\n" + - " }\n" + - "}\n", // ================= - }, - ""); - this.runConformTest( - new String[] { - "bug/LayoutOrganizer.java", - "package bug;\n" + - "import java.util.*;\n" + - "public class LayoutOrganizer {\n" + - " ConflictManager> conflictManager = new ConflictManager>();\n" + - " private boolean optimizeEqual() {\n" + - " List>>> list;\n" + - " ListIterator>>> i;\n" + - " // create sorted list of pairs\n" + - " // (#conflicts, list of LayoutOrganizable sharing this #conflicts)\n" + - " // Here is the problem...\n" + - " list = conflictManager.getConflictsSortedBySize();\n" + - " return null == list;\n" + - " }\n" + - "}\n", // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation -public void test1306() { - runNegativeTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.lang.reflect.Constructor;\n" + - "import java.lang.annotation.Documented;\n" + - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " Constructor c = null;\n" + - " Documented d = c.getAnnotation(Documented.class);\n" + - "}\n", // ================= - }, - // compiler results - "----------\n" + /* expected compiler log */ - "1. WARNING in X.java (at line 6)\n" + - " Constructor c = null;\n" + - " ^^^^^^^^^^^\n" + - "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " Documented d = c.getAnnotation(Documented.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " Documented d = c.getAnnotation(Documented.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to Documented\n" + - "----------\n", - // javac options - JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation -public void test1307() { - this.runNegativeTest( - new String[] { - "Y.java", - "import java.util.List;\n" + - "public class Y {\n" + - " Zork z;\n" + - " Y itself() { return this; }\n" + - " List list() { return null; }\n" + - " Y someY() { return null; }\n" + - "}\n" + - "class Z {\n" + - " void foo(Y y) {\n" + - " Z z = y.itself(); // Y cannot be converted to Z (itself() return type got erased)\n" + - " List l = y.list(); // unchecked conversion from List to List\n" + - " Y ys = y.someY(); // unchecked conversion from Y to Y\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in Y.java (at line 3)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "2. WARNING in Y.java (at line 9)\n" + - " void foo(Y y) {\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "3. ERROR in Y.java (at line 10)\n" + - " Z z = y.itself(); // Y cannot be converted to Z (itself() return type got erased)\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Y to Z\n" + - "----------\n" + - "4. WARNING in Y.java (at line 11)\n" + - " List l = y.list(); // unchecked conversion from List to List\n" + - " ^^^^^^^^\n" + - "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + - "----------\n" + - "5. WARNING in Y.java (at line 12)\n" + - " Y ys = y.someY(); // unchecked conversion from Y to Y\n" + - " ^^^^^^^^^\n" + - "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation -public void test1308() { - this.runNegativeTest( - new String[] { - "Y.java", - "@interface MyAnnotation {\n" + - "}\n" + - "class MyAccessibleObject {\n" + - " Object getAnnotation(Class c) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "class MyConstructor extends MyAccessibleObject {\n" + - " T getAnnotation(Class c) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "class X {\n" + - " void bar1(java.lang.reflect.Constructor constr, Class ann) {\n" + - " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + - " }\n" + - " void bar2(MyConstructor constr, Class ann) {\n" + - " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in Y.java (at line 9)\n" + - " T getAnnotation(Class c) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The method getAnnotation(Class) of type MyConstructor should be tagged with @Override since it actually overrides a superclass method\n" + - "----------\n" + - "2. WARNING in Y.java (at line 14)\n" + - " void bar1(java.lang.reflect.Constructor constr, Class ann) {\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "3. WARNING in Y.java (at line 15)\n" + - " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + - "----------\n" + - "4. ERROR in Y.java (at line 15)\n" + - " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + - "----------\n" + - "5. WARNING in Y.java (at line 17)\n" + - " void bar2(MyConstructor constr, Class ann) {\n" + - " ^^^^^^^^^^^^^\n" + - "MyConstructor is a raw type. References to generic type MyConstructor should be parameterized\n" + - "----------\n" + - "6. WARNING in Y.java (at line 18)\n" + - " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The method getAnnotation(Class) belongs to the raw type MyConstructor. References to generic type MyConstructor should be parameterized\n" + - "----------\n" + - "7. ERROR in Y.java (at line 18)\n" + - " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=226145 -public void test1309() { - this.runNegativeTest( - new String[] { - "EclipseGenericBug.java", - "public class EclipseGenericBug {\n" + - " static class ParametricClass {\n" + - " static interface NonParametricInterface {\n" + - " static interface ParametricInterface {\n" + - " }\n" + - " }\n" + - " }\n" + - " \n" + - " static class ParametricInstance extends ParametricClass {\n" + - " NonParametricInterface.ParametricInterface instance = null;\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=224855 -public void test1310() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.Set;\n" + - "public class X {\n" + - " public void testCast(){\n" + - " Set classes = (Set)getClasses();\n" + - " }\n" + - " public Set> getClasses() {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Set classes = (Set)getClasses();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " Set classes = (Set)getClasses();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Set> to Set\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " Set classes = (Set)getClasses();\n" + - " ^^^^^\n" + - "Class is a raw type. References to generic type Class should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209149 -public void test1311() { - String[] test = new String[] { - "X.java", - "class X {}\n" + - "class Y {}" - }; - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - this.runNegativeTest( - test, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " class Y {}\n" + - " ^\n" + - "Illegal forward reference to type parameter D\n" + - "----------\n"); - } else { - this.runConformTest(test, ""); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=226535 -public void test1312() { - this.runConformTest( - new String[] { - "X.java", - " class Tuple3f> {\n" + - " private float x, y, z;\n" + - " float getX() { return this.x; }\n" + - " float getY() { return this.y; }\n" + - " float getZ() { return this.z; }\n" + - " void set(float newX, float newY, float newZ) {\n" + - " this.x = newX;\n" + - " this.y = newY;\n" + - " this.z = newZ;\n" + - " }\n" + - " public T add(Tuple3f t) {\n" + - " this.set(this.getX() + t.getX(), this.getY() + t.getY(), this.getZ() + t.getZ());\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " T result = (T) this;\n" + - " return result;\n" + - " }\n" + - "}\n" + - "\n" + - "class Vector3f extends Tuple3f {\n" + - " float magnitude () {\n" + - " float x = this.getX(), y = this.getY(), z = this.getZ();\n" + - " return (float) Math.sqrt((x*x) + (y*y) + (z*z));\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Vector3f v = new Vector3f();\n" + - " float magn = v.add(v).add(v).magnitude();\n" + - " System.out.println((int)magn);\n" + - " }\n" + - "}\n", // ================= - }, - "0"); -} -public void test1313() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " List[] l1 = new List[1];\n" + - " List[] l2 = new List[2];\n" + - " List l3 = new List[3];\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " List[] l2 = new List[2];\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of List\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " List l3 = new List[3];\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from List[] to List\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=230070 -public void test1314() { - this.runNegativeTest( - new String[] { - "X.java", - "class B {\n" + - "}\n" + - "class Y {\n" + - " Y(K k) {\n" + - " System.out.println(k);\n" + - " }\n" + - "}\n" + - "public class X {\n" + - " static final B b = new B();\n" + - " Object foo(K toKey) {\n" + - " if (false) return new Y(b);//1\n" + - " if (false) return new Y((K) b);//2\n" + - " return new Y((K) (Object) b);//3\n" + - " }\n" + - " Object bar(K toKey) {\n" + - " if (false) return new Y(b);//4\n" + - " if (false) return new Y((K) b);//5\n" + - " return new Y((K) (Object) b);//6\n" + - " } \n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 11)\n" + - " if (false) return new Y(b);//1\n" + - " ^^^^^^^^\n" + - "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " if (false) return new Y(b);//1\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from B to K\n" + - "----------\n" + - "6. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^^^^^\n" + - "Unnecessary cast from B to K\n" + - "----------\n" + - "7. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "9. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to K\n" + - "----------\n" + - "10. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Object to K\n" + - "----------\n" + - "11. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^\n" + - "Unnecessary cast from B to Object\n" + - "----------\n" + - "12. ERROR in X.java (at line 16)\n" + - " if (false) return new Y(b);//4\n" + - " ^^^^^^^^^^^\n" + - "The constructor Y(B) is undefined\n" + - "----------\n" + - "13. WARNING in X.java (at line 17)\n" + - " if (false) return new Y((K) b);//5\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from B to K\n" + - "----------\n" + - "14. WARNING in X.java (at line 18)\n" + - " return new Y((K) (Object) b);//6\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to K\n" + - "----------\n" + - "15. WARNING in X.java (at line 18)\n" + - " return new Y((K) (Object) b);//6\n" + - " ^^^^^^^^^^\n" + - "Unnecessary cast from B to Object\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228291 -public void test1315() { - this.runNegativeTest( - new String[] { - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X extends Vector> {\n" + - " private static final long serialVersionUID = 1L;\n" + - " public Vector cast(List in) {\n" + - " return (Vector) in;\n" + - " }\n" + - " public X castSilly(Vector> in) {\n" + - " return (X) in;\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Zork z;\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=230466 -public void test1316() { - this.runConformTest( - new String[] { - "e/AbstractClass.java", // ================= - "package e;\n" + - "public abstract class AbstractClass {\n" + - " protected abstract void method1();\n" + - "}\n", - "q/AbstractTest.java", // ================= - "package q;\n" + - "import java.util.Map;\n" + - "import e.AbstractClass;\n" + - "public abstract class AbstractTest {\n" + - " protected class InnerClass extends AbstractClass{\n" + - " public void innerMethod() {\n" + - " System.out.println(\"innerMethod\");\n" + - " }\n" + - " @Override\n" + - " protected void method1() {\n" + - " System.out.println(\"method1\");\n" + - " }\n" + - " }\n" + - " protected Map records;\n" + - " public abstract void method(); \n" + - "}\n", - "w/Test.java", // ================= - "package w;\n" + - "import q.AbstractTest;\n" + - "public class Test extends AbstractTest {\n" + - " @Override\n" + - " public void method() {\n" + - " // Error here\n" + - " InnerClass inner = records.get(\"1\");\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 -public void test1317() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " void foo(String name, String value) {}\n" + - " void foo(String name, T value) {}\n" + - "\n" + - " void foo2(String name, String value) {}\n" + - " > void foo2(String name, T value) {}\n" + - "\n" + - " > T foo3(String name, T value) {}\n" + - "}\n" + - "class M {}\n" + - "class N {}\n" + - "\n" + - "class Test {\n" + - " void test() {\n" + - " new X().foo(\"HI\", null); // correctly report error\n" + - " new X().foo2(\"HI\", null); // miss ambiguous error\n" + - " \n" + - " Thread t1 = foo3(\"HI\", null);\n" + - " Thread t2 = (Thread)foo3(\"HI\", null);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " > T foo3(String name, T value) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "This method must return a result of type T\n" + - "----------\n" + - "2. ERROR in X.java (at line 15)\n" + - " new X().foo(\"HI\", null); // correctly report error\n" + - " ^^^\n" + - "The method foo(String, String) is ambiguous for the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 18)\n" + - " Thread t1 = foo3(\"HI\", null);\n" + - " ^^^^\n" + - "The method foo3(String, null) is undefined for the type Test\n" + - "----------\n" + - "4. ERROR in X.java (at line 19)\n" + - " Thread t2 = (Thread)foo3(\"HI\", null);\n" + - " ^^^^\n" + - "The method foo3(String, null) is undefined for the type Test\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation -public void test1318() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " > void foo2(String name, T value) {}\n" + - "}\n" + - "class N {}\n" + - "\n" + - "class Test {\n" + - " void test() {\n" + - " new X().foo2(\"HI\", null);\n" + - " new X().>foo2(\"HI\", null);\n" + - " new X().>>foo2(\"HI\", null);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N> is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " new X().>foo2(\"HI\", null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N is not a valid substitute for the bounded parameter >\n" + - "----------\n" + - "3. ERROR in X.java (at line 10)\n" + - " new X().>>foo2(\"HI\", null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N> is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation -public void test1319() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "public class X {\n" + - " , U extends List, W extends List> void foo2(String name, U u, T t, W w) {}\n" + - "}\n" + - "\n" + - "class Test {\n" + - " void test() {\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List> is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation -public void test1320() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "public class X {\n" + - " , U extends List, W extends List> void foo2(String name, U u, T t, W w) {}\n" + - "}\n" + - "\n" + - "class Test {\n" + - " void test() {\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List> is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation -public void test1321() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "public class X {\n" + - " , W extends List> void foo2(String name, U u, T t, W w) {}\n" + - "}\n" + - "\n" + - "class Test {\n" + - " void test() {\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List> is not a valid substitute for the bounded parameter >\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 -public void _test1322() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - "\n" + - " /** OK: Bob.class is correct. No idea about the Thingy */\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - "\n" + - " /**\n" + - " * This line will fail when compiled with the Java 5 SDK: Test.java:25:\n" + - " * doStuff(java.lang.Class,Thingy) in Test cannot be applied to\n" + - " * (java.lang.Class,Thingy) test.doStuff(Bill.class, new\n" + - " * Thingy()); ^ Note: Test.java uses unchecked or unsafe operations.\n" + - " * Note: Recompile with -Xlint:unchecked for details. 1 error\n" + - " */\n" + - " x.doStuff(Jim.class, new Thingy());\n" + - " }\n" + - " void doStuff(Class klass, Thingy thingy) {\n" + - " }\n" + - "}\n" + - "class Jim {}\n" + - "class Bob {}\n" + - "class Bob2 extends Bob {}\n" + - "class Thingy {}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " ^^^^^^\n" + - "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 15)\n" + - " x.doStuff(Jim.class, new Thingy());\n" + - " ^^^^^^^\n" + - "Bound mismatch: The generic method doStuff(Class, Thingy) of type X is not applicable for the arguments (Class, Thingy). The inferred type Jim is not a valid substitute for the bounded parameter \n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " x.doStuff(Jim.class, new Thingy());\n" + - " ^^^^^^\n" + - "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation -public void _test1323() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - " x.doStuff2(Jim.class, new Thingy());\n" + - " String s = x.doStuff2(Bob2.class, new Thingy());\n" + - " }\n" + - " T doStuff2(Class klass, Thingy thingy) { return null; }\n" + - "}\n" + - "class Jim {}\n" + - "class Bob {}\n" + - "class Bob2 extends Bob {}\n" + - "class Thingy {}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " x.doStuff2(Jim.class, new Thingy());\n" + - " ^^^^^^^^\n" + - "Bound mismatch: The generic method doStuff2(Class, Thingy) of type X is not applicable for the arguments (Class, Thingy). The inferred type Jim is not a valid substitute for the bounded parameter \n" + - "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " x.doStuff2(Jim.class, new Thingy());\n" + - " ^^^^^^\n" + - "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 5)\n" + - " String s = x.doStuff2(Bob2.class, new Thingy());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation doStuff2(Class, Thingy) of the generic method doStuff2(Class, Thingy) of type X\n" + - "----------\n" + - "4. ERROR in X.java (at line 5)\n" + - " String s = x.doStuff2(Bob2.class, new Thingy());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Bob2 to String\n" + - "----------\n" + - "5. WARNING in X.java (at line 5)\n" + - " String s = x.doStuff2(Bob2.class, new Thingy());\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + - "----------\n" + - "6. WARNING in X.java (at line 5)\n" + - " String s = x.doStuff2(Bob2.class, new Thingy());\n" + - " ^^^^^^\n" + - "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation -public void _test1324() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X x = new X();\n" + - "\n" + - " /** OK: Bob.class is correct. No idea about the Thingy */\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " x.doStuff(Bob.class, new Thingy()); // second invocation is NOT unchecked\n" + - " Zork z;\n" + - " }\n" + - " T doStuff(Class klass, Thingy thingy) { return null; }\n" + - "}\n" + - "class Jim {}\n" + - "class Bob {}\n" + - "class Thingy {}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + - "----------\n" + - "3. WARNING in X.java (at line 6)\n" + - " x.doStuff(Bob.class, new Thingy());\n" + - " ^^^^^^\n" + - "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation -public void test1325() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " U foo(X xt) {\n" + - " return null;\n" + - " }\n" + - " void bar(X x) {\n" + - " X xs2 = foo(x);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " void bar(X x) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " X xs2 = foo(x);\n" + - " ^^^^^^\n" + - "Type safety: Unchecked invocation foo(X) of the generic method foo(X) of type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 6)\n" + - " X xs2 = foo(x);\n" + - " ^^^^^^\n" + - "Type mismatch: cannot convert from Object to X\n" + - "----------\n" + - "4. WARNING in X.java (at line 6)\n" + - " X xs2 = foo(x);\n" + - " ^\n" + - "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation -public void _test1326() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " X foo(X xt, X xt2) {\n" + - " return null;\n" + - " }\n" + - " X identity() {\n" + - " return this;\n" + - " }\n" + - " void bar(X x, X xs) {\n" + - " X xs2 = foo(xs, x).identity();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " void bar(X x, X xs) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " X xs2 = foo(xs, x).identity();\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo(X, X) of type X is not applicable for the arguments (X, X). The inferred type String is not a valid substitute for the bounded parameter \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation -public void test1327() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " X foo(X xt, X xt2) {\n" + - " return null;\n" + - " }\n" + - " X identity() {\n" + - " return this;\n" + - " }\n" + - " void bar(X x, X xs) {\n" + - " X xs2 = foo(x, xs).identity();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " void bar(X x, X xs) {\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " X xs2 = foo(x, xs).identity();\n" + - " ^^^^^^^^^^\n" + - "Type safety: Unchecked invocation foo(X, X) of the generic method foo(X, X) of type X\n" + - "----------\n" + - "3. WARNING in X.java (at line 9)\n" + - " X xs2 = foo(x, xs).identity();\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " X xs2 = foo(x, xs).identity();\n" + - " ^\n" + - "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation -public void test1328() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "\n" + - "public class X {\n" + - " \n" + - " void bar(List lb, List lc) {\n" + - " String s = foo(lb, lc);\n" + - " }\n" + - " U foo(List u, List v) { return null; }\n" + - "}\n" + - "class A {}\n" + - "class B extends A {}\n" + - "class C extends A {}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " String s = foo(lb, lc);\n" + - " ^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from A to String\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232174 -public void test1329() { - this.runConformTest( - new String[] { - "com/b/p1/A.java", // ================= - "package com.b.p1;\n" + - "public class A {\n" + - " protected final class Inner {}\n" + - "}\n", - "com/b/p1/ADerivedSamePkg.java", // ================= - "package com.b.p1;\n" + - "import java.util.Map;\n" + - "public class ADerivedSamePkg extends A {\n" + - " protected void someMethod() {\n" + - " Map.Entry some = null;\n" + - " Inner x = some.getValue();\n" + - " }\n" + - "}\n", - "com/b/p2/ADerivedDifferentPkg.java", // ================= - "package com.b.p2;\n" + - "import java.util.Map;\n" + - "import com.b.p1.A;\n" + - "public class ADerivedDifferentPkg extends A {\n" + - " protected void someMethod() {\n" + - " Map.Entry some = null;\n" + - " Inner x = some.getValue(); // <-- error in this line\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231861 -public void test1330() { - this.runConformTest( - new String[] { - "p/BaseValue.java", // ================= - "package p;\n" + - "interface Value {}\n" + - "public class BaseValue implements Value {}\n", - "p/Model.java", // ================= - "package p;\n" + - "public class Model {\n" + - " public java.util.Map map = new java.util.LinkedHashMap();\n" + - "}\n", // ================= - }, - ""); - this.runConformTest( - new String[] { - "p2/Person.java", // ================= - "package p2;\n" + - "public class Person extends p.Model {\n" + - " void test() {\n" + - " this.map.put(\"name\", new p.BaseValue());\n" + - " }\n" + - "}\n", // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231861 - variation -public void test1331() { - this.runConformTest( - new String[] { - "p/BaseValue.java", // ================= - "package p;\n" + - "interface Value {}\n" + - "public class BaseValue implements Value {}\n", - "p/Model.java", // ================= - "package p;\n" + - "public class Model {\n" + - " public java.util.Map map = new java.util.LinkedHashMap();\n" + - "}\n", - "p2/Person.java", // ================= - "package p2;\n" + - "public class Person extends p.Model {\n" + - " void test() {\n" + - " this.map.put(\"name\", new p.BaseValue());\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232487 -public void test1332() throws Exception { - runConformTest( - // test directory preparation - new String[] { /* test files */ - "X.java", - "import java.util.*;\n" + - "\n" + - "public class X implements Runnable {\n" + - " public void run() {/**/}\n" + - " void foo() {\n" + - " List runnables = new ArrayList();\n" + - " for (Runnable r : runnables) {\n" + - " r.run();\n" + - " }\n" + - " Object o = runnables.get(0);\n" + - " Runnable r = runnables.get(1);\n" + - " }\n" + - "} \n", - }, - // runtime results - "" /* expected output string */); - String expectedOutput = - " // Method descriptor #8 ()V\n" + - " // Stack: 2, Locals: 4\n" + - " void foo();\n" + - " 0 new java.util.ArrayList [18]\n" + - " 3 dup\n" + - " 4 invokespecial java.util.ArrayList() [20]\n" + - " 7 astore_1 [runnables]\n" + - " 8 aload_1 [runnables]\n" + - " 9 invokeinterface java.util.List.iterator() : java.util.Iterator [21] [nargs: 1]\n" + - " 14 astore_3\n" + - " 15 goto 34\n" + - " 18 aload_3\n" + - " 19 invokeinterface java.util.Iterator.next() : java.lang.Object [27] [nargs: 1]\n" + - " 24 checkcast java.lang.Runnable [5]\n" + - " 27 astore_2 [r]\n" + - " 28 aload_2 [r]\n" + - " 29 invokeinterface java.lang.Runnable.run() : void [33] [nargs: 1]\n" + - " 34 aload_3\n" + - " 35 invokeinterface java.util.Iterator.hasNext() : boolean [35] [nargs: 1]\n" + - " 40 ifne 18\n" + - " 43 aload_1 [runnables]\n" + - " 44 iconst_0\n" + - " 45 invokeinterface java.util.List.get(int) : java.lang.Object [39] [nargs: 2]\n" + - " 50 astore_2 [o]\n" + - " 51 aload_1 [runnables]\n" + - " 52 iconst_1\n" + - " 53 invokeinterface java.util.List.get(int) : java.lang.Object [39] [nargs: 2]\n" + - " 58 checkcast java.lang.Runnable [5]\n" + - " 61 astore_3 [r]\n" + - " 62 return\n" + - " Line numbers:\n" + - " [pc: 0, line: 6]\n" + - " [pc: 8, line: 7]\n" + - " [pc: 28, line: 8]\n" + - " [pc: 34, line: 7]\n" + - " [pc: 43, line: 10]\n" + - " [pc: 51, line: 11]\n" + - " [pc: 62, line: 12]\n" + - " Local variable table:\n" + - " [pc: 0, pc: 63] local: this index: 0 type: X\n" + - " [pc: 8, pc: 63] local: runnables index: 1 type: java.util.List\n" + - " [pc: 28, pc: 34] local: r index: 2 type: java.lang.Runnable\n" + - " [pc: 51, pc: 63] local: o index: 2 type: java.lang.Object\n" + - " [pc: 62, pc: 63] local: r index: 3 type: java.lang.Runnable\n"; - - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225737 -public void test1333() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "public class X extends AbstractProject {\n" + - " public void testBug() {\n" + - " // javac compiles the following line without complaining\n" + - " BuildStepDescriptor.filter(BuildStep.PUBLISHERS, getClass());\n" + - " }\n" + - " \n" + - " public static void main(String[] args) {\n" + - " new X().testBug();\n" + - " }\n" + - "}\n" + - "interface BuildStep {\n" + - " public static final PublisherList PUBLISHERS = new PublisherList();\n" + - "}\n" + - "\n" + - "@SuppressWarnings(\"serial\")\n" + - "class PublisherList extends ArrayList> {\n" + - "}\n" + - "abstract class Publisher implements BuildStep, Describable {\n" + - "}\n" + - "interface Describable> {\n" + - "}\n" + - "abstract class Descriptor> {\n" + - "}\n" + - "abstract class BuildStepDescriptor> extends Descriptor {\n" + - " \n" + - " public static > List> filter(\n" + - " List> base,\n" + - " Class> type) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "abstract class AbstractProject

, R> {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225737 - variation -public void test1334() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X extends AbstractProject {\n" + - " public void testBug() {\n" + - " filter(getClass());//1\n" + - " filter(this.getClass());//2\n" + - " filter(X.class);//3\n" + - " }\n" + - " public static void filter(Class> type) {\n" + - " }\n" + - "}\n" + - "abstract class AbstractProject

, R> {\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 -public void test1335() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public void doesNotCompile(SomeInterface i) {\n" + - " T t = ((SomeDerivedInterface) i).getItem();\n" + - " }\n" + - " static interface SomeInterface {\n" + - " }\n" + - " static interface SomeDerivedInterface extends SomeInterface {\n" + - " T getItem();\n" + - " }\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " T t = ((SomeDerivedInterface) i).getItem();\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from X.SomeInterface to X.SomeDerivedInterface\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation -public void test1336() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " void foo(Other2.Member2 om2) {\n" + - " Other.Member m = (Other.Member) om2;\n" + - " }\n" + - "}\n" + - "class Other {\n" + - " class Member {}\n" + - "}\n" + - "class Other2 extends Other {\n" + - " class Member2 extends Other.Member {\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\r\n" + - " Other.Member m = (Other.Member) om2;\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Other2.Member2 to Other.Member\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation -public void test1337() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " void foo(Other2.Member2 om2) {\n" + - " Other.Member m = (Other.Member) om2;\n" + - " }\n" + - "}\n" + - "class Other {\n" + - " class Member {}\n" + - "}\n" + - "class Other2 extends Other {\n" + - " class Member2 extends Other.Member {\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\r\n" + - " Other.Member m = (Other.Member) om2;\r\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Other2.Member2 to Other.Member\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 -public void test1338() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " void m(Object someObject, Integer intObject) {\n" + - " Exception class1 = someObject.getClass();\n" + - " Exception class2 = intObject.getClass();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Exception class1 = someObject.getClass();\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Exception\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " Exception class2 = intObject.getClass();\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Exception\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 - variation -public void test1339() { - this.runNegativeTest( - new String[] { - "java/lang/Object.java", // ================= - "package java.lang;\n" + - "\n" + - "public class Object {\n" + - " void foo() {\n" + - " Exception e1 = getClass();\n" + - " Exception e2 = this.getClass();\n" + - " }\n" + - " public Class getClass() { return null; }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in java\\lang\\Object.java (at line 5)\n" + - " Exception e1 = getClass();\n" + - " ^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Exception\n" + - "----------\n" + - "2. ERROR in java\\lang\\Object.java (at line 6)\n" + - " Exception e2 = this.getClass();\n" + - " ^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Class to Exception\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235460 -public void test1340() { - this.runConformTest( - new String[] { - "Derived_A.java", // ================= - "import java.util.Map;\n" + - "class Base_A {}\n" + - "public class Derived_A extends Base_A {\n" + - " public Map getMap() {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - "Derived_B.java", // ================= - "class Base_B {\n" + - "}\n" + - "public class Derived_B extends Base_B {\n" + - "}\n", // ================= - }, - ""); - this.runConformTest( - new String[] { - "InternalCompilerError_Main.java", // ================= - "public class InternalCompilerError_Main {\n" + - " public static void main(String args[]) {\n" + - " Derived_A dummy = new Derived_A();\n" + - " Derived_B propPrice = (Derived_B)dummy.getMap().get(null); \n" + - " }\n" + - "}\n", // ================= - }, - "", - null, - false, - null); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235837 -public void test1341() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "public class X {\n" + - " void bar() {\n" + - " Integer i = 0;\n" + - " Double d = 0.0;\n" + - " foo((Collection) Arrays.asList(i, d));\n" + - " }\n" + - " void foo(Collection c) {}\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " foo((Collection) Arrays.asList(i, d));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from List> to Collection\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " foo((Collection) Arrays.asList(i, d));\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Number&Comparable is created for a varargs parameter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation -public void test1342() throws Exception { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "interface Adapter {\n" + - " interface Setter {}\n" + - " public Setter makeSetter();\n" + - "}\n" + - "\n" + - "public class X implements Adapter {\n" + - " public X.Setter makeSetter() {\n" + - " return new X.Setter() {};\n" + - " }\n" + - " void foo() {\n" + - " List> l = new ArrayList>();\n" + - " }\n" + - "}\n", // ================= - }, - ""); - // check X$1 - String expectedOutput = - "// Signature: Ljava/lang/Object;LAdapter$Setter;\n" + - "class X$1 implements Adapter$Setter {\n"; - - File f = new File(OUTPUT_DIR + File.separator + "X$1.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); - } - - // check X - expectedOutput = - " // Signature: ()LAdapter$Setter;\n" + - " // Stack: 3, Locals: 1\n" + - " public Adapter.Setter makeSetter();\n"; - - f = new File(OUTPUT_DIR + File.separator + "X.class"); - classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); - disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); - result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); - 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); - } -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation -public void test1343() throws Exception { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "class Adapter {\n" + - " class Setter {}\n" + - " public Setter makeSetter() { return null; }\n" + - "}\n" + - "\n" + - "public class X extends Adapter {\n" + - " public X.Setter makeSetter() {\n" + - " return new X().new Setter() {};\n" + - " }\n" + - " void foo() {\n" + - " List.Setter> l = new ArrayList.Setter>();\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation -public void test1344() throws Exception { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "class Adapter {\n" + - " class Setter {}\n" + - " public Setter makeSetter() { return null; }\n" + - "}\n" + - "\n" + - "public class X extends Adapter {\n" + - " public X.Setter makeSetter() {\n" + - " return new X().new Setter() {};\n" + - " }\n" + - " void foo() {\n" + - " List l = new ArrayList();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " public class X extends Adapter {\n" + - " ^^^^^^^\n" + - "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " public X.Setter makeSetter() {\n" + - " ^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " public X.Setter makeSetter() {\n" + - " ^^^^^^^^^^^^\n" + - "Name clash: The method makeSetter() of type X has the same erasure as makeSetter() of type Adapter but does not override it\n" + - "----------\n" + - "4. WARNING in X.java (at line 9)\n" + - " return new X().new Setter() {};\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 9)\n" + - " return new X().new Setter() {};\n" + - " ^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "6. WARNING in X.java (at line 12)\n" + - " List l = new ArrayList();\n" + - " ^^^^^^^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 12)\n" + - " List l = new ArrayList();\n" + - " ^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation -public void test1345() throws Exception { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "class Adapter {\n" + - " class Setter {}\n" + - " public Setter makeSetter() { return null; }\n" + - "}\n" + - "\n" + - "public class X extends Adapter {\n" + - " public X.Setter makeSetter() {\n" + - " return (String) new X().new Setter() {};\n" + - " }\n" + - " void foo() {\n" + - " List l = new ArrayList();\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " public class X extends Adapter {\n" + - " ^^^^^^^\n" + - "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " public X.Setter makeSetter() {\n" + - " ^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " public X.Setter makeSetter() {\n" + - " ^^^^^^^^^^^^\n" + - "Name clash: The method makeSetter() of type X has the same erasure as makeSetter() of type Adapter but does not override it\n" + - "----------\n" + - "4. ERROR in X.java (at line 9)\n" + - " return (String) new X().new Setter() {};\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from new Adapter.Setter(){} to String\n" + - "----------\n" + - "5. ERROR in X.java (at line 9)\n" + - " return (String) new X().new Setter() {};\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from String to Adapter.Setter\n" + - "----------\n" + - "6. WARNING in X.java (at line 9)\n" + - " return (String) new X().new Setter() {};\n" + - " ^\n" + - "X is a raw type. References to generic type X should be parameterized\n" + - "----------\n" + - "7. WARNING in X.java (at line 9)\n" + - " return (String) new X().new Setter() {};\n" + - " ^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 12)\n" + - " List l = new ArrayList();\n" + - " ^^^^^^^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "9. WARNING in X.java (at line 12)\n" + - " List l = new ArrayList();\n" + - " ^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" - ); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation -public void test1346() throws Exception { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "class Adapter {\n" + - " class Setter {}\n" + - "}\n" + - "\n" + - "public class X extends Adapter {\n" + - " public Adapter.Setter makeSetter() {\n" + - " return (X.Setter) \"a\";\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " public class X extends Adapter {\n" + - " ^^^^^^^\n" + - "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 7)\n" + - " public Adapter.Setter makeSetter() {\n" + - " ^^^^^^^^^^^^^^\n" + - "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 8)\n" + - " return (X.Setter) \"a\";\n" + - " ^^^^^^^^^^^^^^\n" + - "Cannot cast from String to Adapter.Setter\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236220 -public void test1347() throws Exception { - this.runNegativeTest( - new String[] { - "DeprecatedType.java", // ================= - "class Base {\n" + - " class Member {\n" + - " }\n" + - "}\n" + - "\n" + - "@Deprecated\n" + - "public class DeprecatedType extends Base {\n" + - "}\n", - "X.java", // ================= - "public class X {\n" + - " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + - " DeprecatedType.Member m2; // DeprecatedType is raw + indirect access to Member\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 2)\n" + - " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "The type DeprecatedType is deprecated\n" + - "----------\n" + - "2. WARNING in X.java (at line 2)\n" + - " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Base.Member is a raw type. References to generic type Base.Member should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 3)\n" + - " DeprecatedType.Member m2; // DeprecatedType is raw + indirect access to Member\n" + - " ^^^^^^^^^^^^^^\n" + - "The type DeprecatedType is deprecated\n" + - "----------\n" + - "4. ERROR in X.java (at line 4)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174282 - variation -public void test1348() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "abstract class AbstractOBOverlaySettings extends AbstractOverlaySettings implements RefSymbolTypeSettings {/*empty*/}\n" + - "abstract class AbstractOverlaySettings implements SymbolTypeSettings {/*empty*/}\n" + - "interface DAFDataController {/*empty*/}\n" + - "interface ReferenceableData {/*empty*/}\n" + - "enum SymbolTypes {/*empty*/}\n" + - "interface SymbolTypeSettings {/*empty*/}\n" + - "interface AllOverlaySettingsController {/*empty*/}\n" + - "interface DAFDataWithRefController extends DAFDataController {/*empty*/}\n" + - "class OBAreaOverlaySettings extends AbstractOBOverlaySettings {/*empty*/}\n" + - "interface RefSymbolTypeSettings extends SymbolTypeSettings, ReferenceableData {/*empty*/}\n" + - "public class X {\n" + - " public X() {\n" + - " DAFDataController controller00 = null;\n" + - " DAFDataWithRefController controller01 = \n" + - " (DAFDataWithRefController) controller00;\n" + - " }\n" + - " Zork z;\n" + - "}\n", // ================= - }, - "----------\n" + - "1. WARNING in X.java (at line 15)\n" + - " (DAFDataWithRefController) controller00;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from DAFDataController to DAFDataWithRefController\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 -public void test1350() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.io.IOException;\n" + - "\n" + - "interface TreeVisitor {\n" + - " public T visit(U location);\n" + - "}\n" + - "\n" + - "interface TreeVisitable {\n" + - " public T visit(TreeVisitor visitor) throws IOException;\n" + - "}\n" + - "\n" + - "abstract class Param implements TreeVisitable {\n" + - " public final Param lookforParam(final String name) {\n" + - " TreeVisitor visitor = new TreeVisitor() {\n" + - " public Param visit(Param location) {\n" + - " return null;\n" + - " }\n" + - " };\n" + - " return visit(visitor);\n" + - " }\n" + - "\n" + - " public abstract T visit(TreeVisitor visitor);\n" + - "}\n" + - "\n" + - "class StructParam extends Param {\n" + - " public T visit(TreeVisitor visitor) {\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " StructParam p = new StructParam();\n" + - " p.lookforParam(\"abc\");\n" + - " System.out.println(\"done\");\n" + - " }\n" + - "}\n", // ================= - }, - "done"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation -public void test1351() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.io.IOException;\n" + - "\n" + - "interface IFoo {\n" + - " T foo(T t) throws IOException;\n" + - "}\n" + - "interface JFoo {\n" + - " T foo(T t) throws Exception;\n" + - "}\n" + - "abstract class Foo implements IFoo, JFoo {}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f = createFoo();\n" + - " try {\n" + - " f.foo(null);\n" + - " } catch(IOException e) {\n" + - " }\n" + - " System.out.println(\"done\");\n" + - " }\n" + - " static Foo createFoo() {\n" + - " return new Foo() {\n" + - " public T foo(T t) {\n" + - " return t;\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n", // ================= - }, - "done"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation -public void test1352() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.io.IOException;\n" + - "\n" + - "interface IFoo {\n" + - " T foo(T t) throws IOException;\n" + - "}\n" + - "interface JFoo {\n" + - " T foo(T t) throws Exception;\n" + - "}\n" + - "abstract class Foo implements IFoo, JFoo {}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f = createFoo();\n" + - " try {\n" + - " f.foo(null);\n" + - " } catch(IOException e) {\n" + - " }\n" + - " System.out.println(\"done\"); //dd\n" + - " }\n" + - " static Foo createFoo() {\n" + - " return new Foo() {\n" + - " public T foo(T t) {\n" + - " return t;\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n", // ================= - }, - "done"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation -public void test1353() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.io.IOException;\n" + - "\n" + - "interface IFoo {\n" + - " T foo(T t) throws IOException;\n" + - "}\n" + - "interface JFoo {\n" + - " T foo(T t);\n" + - "}\n" + - "abstract class Foo implements IFoo, JFoo {}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Foo f = createFoo();\n" + - " try {\n" + - " f.foo(null);\n" + - " } catch(IOException e) {\n" + - " }\n" + - " System.out.println(\"done\"); //dd\n" + - " }\n" + - " static Foo createFoo() {\n" + - " return new Foo() {\n" + - " public T foo(T t) {\n" + - " return t;\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " } catch(IOException e) {\n" + - " ^^^^^^^^^^^\n" + - "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 -public void test1354() { - this.runConformTest( - new String[] { - "X.java", // ================= - "interface Operation extends CheckedOperation {\n" + - " void op(In o);\n" + - "}\n" + - "\n" + - "interface CheckedOperation {\n" + - " void op(In o) throws E;\n" + - "}\n" + - "\n" + - "class ToUpper implements Operation {\n" + - " public void op(String o) {\n" + - " System.out.print(\"[\"+o.toUpperCase()+\"]\");\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new ToUpper().op(\"hello world 1\"); // Works\n" + - " Operation t = new ToUpper();\n" + - " t.op(\"hello world 2\"); // Doesn\'t work: Exception in thread \"main\" java.lang.NoSuchMethodError: Operation.op(Ljava/lang/String;)V\n" + - " }\n" + - "}\n", // ================= - }, - "[HELLO WORLD 1][HELLO WORLD 2]"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 - variation -public void test1355() { - this.runConformTest( - new String[] { - "X.java", // ================= - "interface Operation extends CheckedOperation {\n" + - " void op(In o) throws RuntimeException;\n" + - "}\n" + - "\n" + - "interface CheckedOperation {\n" + - " void op(In o) throws E;\n" + - "}\n" + - "\n" + - "class ToUpper implements Operation {\n" + - " public void op(String o) {\n" + - " System.out.print(\"[\"+o.toUpperCase()+\"]\");\n" + - " }\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " new ToUpper().op(\"hello world 1\"); // Works\n" + - " Operation t = new ToUpper();\n" + - " t.op(\"hello world 2\"); // Doesn\'t work: Exception in thread \"main\" java.lang.NoSuchMethodError: Operation.op(Ljava/lang/String;)V\n" + - " }\n" + - "}\n", // ================= - }, - "[HELLO WORLD 1][HELLO WORLD 2]"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 - variation -public void test1356() { - this.runConformTest( - new String[] { - "X.java", // ================= - "class Activator {\n" + - "}\n" + - "interface Child extends Parent {\n" + - " Activator get(T value);\n" + - "}\n" + - "interface Parent {\n" + - " Activator get(T value) throws RuntimeException;\n" + - "}\n" + - "public class X {\n" + - " static class Impl implements Child {\n" + - " public Activator get(T value) {\n" + - " System.out.println(\"done\");\n" + - " return null;\n" + - " }\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " Child c = new Impl();\n" + - " try {\n" + - " c.get(true);\n" + - " } catch (Throwable t) { \n" + - " t.printStackTrace();\n" + - " }\n" + - " }\n" + - "}\n", // ================= - }, - "done"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 -public void _test1357() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.*;\n" + - "@interface Ann { Class value(); }\n" + - "\n" + - "/**\n" + - " * @see Private - Private is not visible here\n" + - " */\n" + - "@Ann(X.Private.class) // Private is not visible here\n" + - "public abstract class X implements Map {\n" + - " /**\n" + - " * @see Private - Private is visible here\n" + - " */\n" + - " private static interface Private {}\n" + - " Private field;\n" + - "}\n" + - "class Secondary {\n" + - " private static interface SecondaryPrivate {}\n" + - "}\n", // ================= - }, - "done"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation -public void _test1358() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "import java.util.List;\n" + - "public abstract class X implements List {\n" + - " /**\n" + - " * @see Inter.Private - Private is visible here\n" + - " */\n" + - " class Inter {\n" + - " private class Private {}\n" + - " }\n" + - " Inter.Private field;\n" + - "}\n", // ================= - }, - "done"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation -public void test1359() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " class M1 {\n" + - " private class Private {\n" + - " }\n" + - " }\n" + - " void foo() {\n" + - " M1.Private p;\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 -public void test1360() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static T getValue(final Object bean, final String property) {\n" + - " return (T)new Object();\n" + - " }\n" + - " public void testGenerics() {\n" + - " int value = getValue(new Object(), \"\");\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation -public void test1361() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static T getValue(T t) {\n" + - " return t;\n" + - " }\n" + - " public void testGenerics() {\n" + - " int value = getValue(0);\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation -public void test1362() { - this.runConformTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static T getValue(T t1, T t2) {\n" + - " return t1;\n" + - " }\n" + - " public void testGenerics() {\n" + - " getValue(0, this);\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation -public void test1363() { - this.runNegativeTest( - new String[] { - "X.java", // ================= - "public class X {\n" + - " public static T getValue(T t1, T t2) {\n" + - " return t1;\n" + - " }\n" + - "\n" + - " public void testGenerics(Comparable s) {\n" + - " int i = getValue(0, s);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " int i = getValue(0, s);\n" + - " ^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Comparable&Serializable> to int\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 -public void test1364() { - this.runNegativeTest( - new String[] { - "Status.java", // ================= - "import java.util.HashMap;\n" + - "import java.util.Map;\n" + - "\n" + - "public enum Status {\n" + - " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + - "\n" + - " private static Map mapping;\n" + - "\n" + - " private Status(final byte newValue) {\n" + - "\n" + - " if (Status.mapping == null) {\n" + - " Status.mapping = new HashMap();\n" + - " }\n" + - "\n" + - " Status.mapping.put(newValue, this);\n" + - " }\n" + - "}\n", // ================= - }, - "----------\n" + - "1. ERROR in Status.java (at line 11)\n" + - " if (Status.mapping == null) {\n" + - " ^^^^^^^\n" + - "Cannot refer to the static enum field Status.mapping within an initializer\n" + - "----------\n" + - "2. ERROR in Status.java (at line 12)\n" + - " Status.mapping = new HashMap();\n" + - " ^^^^^^^\n" + - "Cannot refer to the static enum field Status.mapping within an initializer\n" + - "----------\n" + - "3. ERROR in Status.java (at line 15)\n" + - " Status.mapping.put(newValue, this);\n" + - " ^^^^^^^\n" + - "Cannot refer to the static enum field Status.mapping within an initializer\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239203 -public void test1365() { - this.runConformTest( - new String[] { - "C.java", // ================= - "class A {\n" + - "}\n" + - "\n" + - "class B {\n" + - "}\n" + - "\n" + - "public class C {\n" + - " > A foo(Class clazz) {\n" + - " A ret = bar(\"bla\");\n" + - " return ret;\n" + - " }\n" + - "\n" + - " > A bar(String clazzName) {\n" + - " return null;\n" + - " }\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 -public void test1366() { - this.runConformTest( - new String[] { - "X.java", // ================= - "import java.io.IOException;\n" + - "\n" + - "interface IServiceAction {\n" + - " Response execute(Request parameter) throws Fault;\n" + - "}\n" + - "\n" + - "interface IServiceOperation extends IServiceAction {\n" + - " Response execute(Request parameter) throws Fault;\n" + - "}\n" + - "\n" + - "public class X {\n" + - " public String execute(String parameter) throws IOException {\n" + - " return serviceOperation.execute(parameter);\n" + - " }\n" + - "\n" + - " private final IServiceOperation serviceOperation = null;\n" + - "}\n", // ================= - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239439 -public void test1367() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "public class X {\n" + - " private static Map var;\n" + - " static {\n" + - " var= new HashMap();\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " private static Map var;\n" + - " ^^^\n" + - "Map cannot be resolved to a type\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " var= new HashMap();\n" + - " ^^^\n" + - "Map cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 4)\n" + - " var= new HashMap();\n" + - " ^^^^^^^\n" + - "HashMap cannot be resolved to a type\n" + - "----------\n"); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 -public void test1370() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + - " public NonPublicInterfaceImplementor selfCall() {\n" + - " return this;\n" + - " }\n" + - "}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public static void main(String[] args) {\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation -public void test1371() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + - " public E selfCall() {\n" + - " return null;\n" + - " }\n" + - "}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public static void main(String[] args) {\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation -public void test1372() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + - " public E selfCall() {\n" + - " return null;\n" + - " }\n" + - "}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public static void main(String[] args) {\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation -public void test1373() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + - " public NonPublicInterfaceImplementor next;\n" + - "}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public static void main(String[] args) {\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().next);\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation -public void test1374() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + - " public NonPublicInterfaceImplementor next;\n" + - "}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public static void main(String[] args) {\n" + - " NonPublicInterfaceImplementor impl = new NonPublicInterfaceImplementor();\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(impl.next);\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation -public void test1375() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + - " public NonPublicInterfaceImplementor next;\n" + - "}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public static void main(String[] args) {\n" + - " NonPublicInterfaceImplementor impl = new NonPublicInterfaceImplementor();\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(impl.next.next);\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation -public void test1376() { - this.runConformTest( - new String[] { - "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "interface NonPublicInterface {}\n", - "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class NonPublicInterfaceImplementor implements NonPublicInterface {}\n", - "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- - "package restricted;\n" + - "public class UnuseableOutsideRestrictedWithECJ {\n" + - " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + - "}\n", - "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- - "package usesrestricted;\n" + - "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + - "import restricted.NonPublicInterfaceImplementor;\n" + - "public class CannotCompileInEcj {\n" + - " public NonPublicInterfaceImplementor next;\n" + - " public void foo() {\n" + - " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(next);\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - ""); -} - -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=241502 -public void test1378() { - this.runConformTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "//the remote-usable interface\n" + - "class RemoteException extends Throwable {}\n" + - " \n" + - "interface RemoteStore {\n" + - " public abstract

P get(Class

c) throws RemoteException;\n" + - "}\n" + - "\n" + - "//the interface for local use\n" + - "interface Store extends RemoteStore{\n" + - " public

P get(Class

c) ;\n" + - "}\n" + - "\n" + - "//the implementation\n" + - "class StoreImpl implements Store {\n" + - " public

P get(Class

c) {\n" + - " System.out.print(\"[get]\");\n" + - " return null;\n" + - " }\n" + - "}\n" + - "\n" + - "class Persistent {\n" + - "}\n" + - "\n" + - "public class X {\n" + - "public static void main(String[] args) {\n" + - " try {\n" + - " RemoteStore t = new StoreImpl();\n" + - " t.get(Object.class); //works\n" + - " t.get(Persistent.class); //works\n" + - " } catch (RemoteException e) {\n" + - " e.printStackTrace();\n" + - " }\n" + - " Store t = new StoreImpl();\n" + - " t.get(Object.class); //works\n" + - " t.get(Persistent.class); //NoSuchMethodError\n" + - "} \n" + - "}\n",//----------------------------------------------------------------------- - }, - "[get][get][get][get]"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 -public void test1418() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "class Box, V extends U> {\n" + - " V value;\n" + - " Box next;\n" + - " Box(V value) {\n" + - " this.value = value;\n" + - " }\n" + - " Box() {}\n" + - "}\n" + - "class A extends Box {}\n" + - "class B extends Box {}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Box, Box> a = new Box, Box>(new Box(new A()));\n" + - " Box b = a;\n" + - " b.value.next = new Box(new B());\n" + - " A c = a.value.next.value;\n" + - " String s = b.value;\n" + - " b.value.next.next = new Box(new B());\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " b.value.next = new Box(new B());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Box to Box\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " String s = b.value;\n" + - " ^^^^^^^\n" + - "Type mismatch: cannot convert from capture#6-of ? to String\n" + - "----------\n" + - "3. ERROR in X.java (at line 18)\n" + - " b.value.next.next = new Box(new B());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Box to Box\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 - variation -public void test1419() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "class Box, V extends U> {\n" + - " private V value;\n" + - " Box next;\n" + - " Box(V value) {\n" + - " this.value = value;\n" + - " }\n" + - " Box() {}\n" + - " V getValue() { return this.value; }\n" + - "}\n" + - "class A extends Box {}\n" + - "class B extends Box {}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Box, Box> a = new Box, Box>(new Box(new A()));\n" + - " Box b = a;\n" + - " b.getValue().next = new Box(new B());\n" + - " A c = a.getValue().next.getValue();\n" + - " String s = b.getValue();\n" + - " b.getValue().next.next = new Box(new B());\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. ERROR in X.java (at line 16)\n" + - " b.getValue().next = new Box(new B());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Box to Box\n" + - "----------\n" + - "2. ERROR in X.java (at line 18)\n" + - " String s = b.getValue();\n" + - " ^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from capture#6-of ? to String\n" + - "----------\n" + - "3. ERROR in X.java (at line 19)\n" + - " b.getValue().next.next = new Box(new B());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from Box to Box\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 - variation -public void test1420() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "class Box, V extends U> {\n" + - " V value;\n" + - " Box next(V v) { return new Box(v); }\n" + - " Box(V value) {\n" + - " this.value = value;\n" + - " }\n" + - " Box() {/**/}\n" + - "}\n" + - "class A extends Box {/**/}\n" + - "class B extends Box {/**/}\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Box, Box> a = new Box, Box>(new Box(new A()));\n" + - " Box b = a;\n" + - " b.value.next(new Box(new B()));\n" + - " b.value.next(b.value);\n" + - " }\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " b.value.next(new Box(new B()));\n" + - " ^^^^\n" + - "The method next(capture#4-of ?) in the type Box is not applicable for the arguments (Box)\n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " b.value.next(b.value);\n" + - " ^^^^\n" + - "The method next(capture#10-of ?) in the type Box is not applicable for the arguments (capture#8-of ?)\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 -public void test1421() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "public class X {\n" + - " public interface ID { };\n" + - " public abstract class DomainObject {};\n" + - " public interface DAO> { };\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type parameter DomainObject is hiding the type X.DomainObject\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 - variation -public void test1422() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "public class X {\n" + - " public interface ID { };\n" + - " public abstract class DomainObject {};\n" + - " public interface DAO> { };\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type parameter DomainObject is hiding the type X.DomainObject\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 -public void test1423() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "public class X {\n" + - " public interface ID { };\n" + - " public abstract class DomainObject {};\n" + - " public interface DAO> { };\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type parameter DomainObject is hiding the type X.DomainObject\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO> {};\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 - variation -public void test1424() { - this.runNegativeTest( - new String[] { - "X.java", //----------------------------------------------------------------------- - "public class X {\n" + - " public interface ID { };\n" + - " public abstract class DomainObject {};\n" + - " public interface DAO> { };\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - "}\n",//----------------------------------------------------------------------- - }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type parameter DomainObject is hiding the type X.DomainObject\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - " ^^^^^^^^^^^^\n" + - "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); -} +/******************************************************************************* + * Copyright (c) 2000, 2009 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.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 extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Integer w = new X().get(new Integer(12));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class XS {\n" + + " Txs get(Txs t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + public void test0002() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Integer w = new X().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 {\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 extends X {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends X {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class 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 implements X {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X implements X {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class 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 {\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 {\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 {\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 {\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 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Object.java (at line 2)\n" + + " public class Object {\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> {\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X();\n" + + " ^^^\n" + + "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); + } + + public void test0011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X();\n" + + " ^^^\n" + + "Foo cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = new X().foo(\"SUCCESS\");\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().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 {\n" + + " T foo(T t) throws T {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().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 {\n" + + " String foo() throws T {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().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 {\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().bar(new Exception());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0017() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\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().bar(new Exception());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " new X().bar(new Exception());\n" + + " ^^^\n" + + "The method bar(IOException) in the type X is not applicable for the arguments (Exception)\n" + + "----------\n"); + } + public void test0018() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) {\n" + + " System.out.println(t);\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X() {\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 {\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() {\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 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 {\n" + + " void foo(Y y) {\n" + + " System.out.print(\"SUCC\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " new Y() {\n" + + " @Override\n" + + " public void pre() {\n" + + " foo(this);\n" + + " }\n" + + " }.print(\"ESS\");\n" + + " }\n" + + "}\n" + + "class Y

{\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 is not applicable for the arguments (String)\n" + + "----------\n"); + } + public void test0021() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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().foo(new Object());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\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 is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().foo(new Object());\n" + + " ^^^\n" + + "The method foo(String) in the type X is not applicable for the arguments (Object)\n" + + "----------\n"); + } + + public void test0022() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " System.out.println(t);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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(new EX());\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " new X(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 {\n" + + " String foo() throws T {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(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 {\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(new Exception());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0027() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\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(new Exception());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " new X(new Exception());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(Exception) is undefined\n" + + "----------\n"); + } + + public void test0028() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = new X(\"SU\").t;\n" + + " System.out.print(s);\n" + + " s = new X(\"failed\").t = \"CC\";\n" + + " System.out.print(s);\n" + + " s = new X(\"\").t += \"ESS\";\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0029() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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().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 {\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().foo(\"SUCCESS\"));\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + public void test0031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(\"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 {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(\"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 {\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\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\n" + + "----------\n"); + } + + public void test0034() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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\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\n" + + "----------\n"); + } + + public void test0035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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\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\n" + + "----------\n"); + } + + public void test0036() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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 {\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 {\n" + + " void foo(E e){}\n" + + " void foo(T t){}\n" + + " public static void main(String[] args) {\n" + + " X 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\n" + + "----------\n"); + } + + public void test0039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l1){}\n" + + " void foo(L l2){}\n" + + " void foo(L l){}\n" + + "}\n" + + "\n" + + "class L {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(L l1){}\n" + + " ^^^^^^^^^^^^\n" + + "Method foo(L) 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 l2){}\n" + + " ^^^^^^^^^^^^\n" + + "Method foo(L) 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" + + "Method foo(L) has the same erasure foo(L) as another method in type X\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 should be parameterized\n" + + "----------\n"); + } + + public void test0040() { + this.runConformTest( + new String[] { + "X.java", + "public class 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 {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n", + }, + "SUCCESS"); + } + + // ** + public void test0042() { + String[] test = new String[] { + "X.java", + "public class X {}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + test, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Illegal forward reference to type parameter U\n" + + "----------\n"); + } else { + this.runConformTest(test, ""); + } + } + + public void test0043() { + this.runConformTest( + new String[] { + "X.java", + "public class X , U extends T> {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class L{}\n", + }, + "SUCCESS"); + } + + public void test0044() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends L {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class L {}\n", + }, + "SUCCESS"); + } + + public void test0045() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public Z var;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public Z var;\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public Z 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 var;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public Object var;\n" + + " ^^^^^^\n" + + "The type Object is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public Object var;\n" + + " ^\n" + + "T cannot be resolved to a type\n" + + "----------\n"); + } + public void test0047() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new MX(\"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 {\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 as private thus non inherited) + public void test0048() { + this.runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " private T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new 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", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 10)\n" + + " new X(this) {\n" + + " ^\n" + + "X is a raw type. References to generic type X 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 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", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + public void test0049() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new 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 {\n" + + " static class N {}" + + "}\n" + + "class Y {\n" + + " static class N {}" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\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 extends Super {}\n" + + "class Y extends Super {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends Super {}\n" + + " ^\n" + + "M cannot be resolved to a type\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 implements Base {\n" + + " static class InnerTest implements Inner {}\n" + + "}\n"+ + "interface Base {\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 {}\n" + + "class Y extends X {\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 {}\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 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

{\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0053() { + this.runConformTest( + new String[] { + "X.java", + "public class X 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(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new 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

{\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 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(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new 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

{\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(this) {\n" + + " ^\n" + + "X is a raw type. References to generic type X 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 is not applicable for the arguments (T)\n" + + "----------\n"); + } + + public void test0055() { + this.runConformTest( + new String[] { + "X.java", + "public class X 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 xs = new X(\"SUCCESS\");\n" + + " System.out.println(xs.t);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\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 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 xs = new X(\"SUCCESS\");\n" + + " System.out.println((X)xs.t);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\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

\n" + + "----------\n"); + } + + public void test0057() { + this.runConformTest( + new String[] { + "X.java", + "public class X 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> 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

{\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 {\n" + + "}\n" + + "// Valid Type Syntax\n" + + "class Y {\n" + + " X 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 {\n" + + "}\n" + + "// Invalid Valid Type Syntax (not enough parameters)\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^\n" + + "Incorrect number of arguments for type X; 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 {\n" + + "}\n" + + "// Invalid Valid Type Syntax (too many parameters)\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^\n" + + "Incorrect number of arguments for type X; 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 {\n" + + "}\n" + + "// Invalid Valid Type Syntax (primitive cannot be parameters)\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " X 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 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 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 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 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 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 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 {\n" + + "}\n" + + "// Valid Type Syntax\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "" + ); + } + public void test0063() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X 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 xs = new X(args);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\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 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 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 should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " X xs = new X(args);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(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

\n" + + "----------\n"); + } + // raw type: variable map to its strict erasure + public void test0064() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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\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 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 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 {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " X xioe = new X(); // ok\n" + + " \n" + + " X x2 = xioe;\n" + + " X 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 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 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 should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " X xioe2 = x; // unsafe\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\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> {\n" + + " A1 a1;\n" + + "}\n" + + "// Valid Parameterized Type Declaration\n" + + "class X2{\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1> {\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{\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 {\n" + + " A1 a1;\n" + + "}\n" + + "// Invalid Parameterized Type Declaration\n" + + "class X2 {\n" + + " ^^\n" + + "A2 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in test\\X1.java (at line 3)\n" + + " public class X1 {\n" + + " ^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "3. ERROR in test\\X1.java (at line 7)\n" + + " class X2 expected after this token\n" + + "----------\n" + ); + } + + // JSR14-V10[2.4]: Not terminated consecutive declaration + public void test0069() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1 {\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1>\" 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> {\n" + + " A1 a1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1> {\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>> {\n" + + " A1 a1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1>> {\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>> {\n" + + " A1 a1;\n" + + "}\n" + + "// Valid Parameterized Type Declaration\n" + + "class X2 {\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1>> {\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 > 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

{\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 > extends p.A {\n" + + " ^^^\n" + + "The type A 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 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

{\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 extends p.A {\n" + + " ^^^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X 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 extends p.A {\n" + + " X() {\n" + + " super(null);\n" + + " }\n"+ + " X(T t) {\n" + + " super(t);\n" + + " }\n" + + " X(X 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 xs = new X(args);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A

{\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 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 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 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 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 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 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 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 should be parameterized\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " X xs = new X(args);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String[]) is undefined\n" + + "----------\n"); + } + public void test0078() { + this.runNegativeTest( + new String[] { + "X.java", + "import p.A;\n" + + "public class X {\n" + + " X(A a, A b) {\n" + + " }\n" + + " void foo(A 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 as = new A(null);\n" + + " as.print(\"hello\");\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A

{\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

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\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

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\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

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

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

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

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\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 as = new A(null);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor A(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 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

\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>>> {\n" + + " A a;\n" + + " public static void main(String[] args) {\n" + + " X>>> x = new X>>>();\n" + + " x.a = new X1>>();\n" + + " x.a.a1 = new X2>();\n" + + " x.a.a1.a2 = new X3();\n" + + " x.a.a1.a2.a3 = \"SUCCESS\";\n" + + " System.out.println(x.a.a1.a2.a3);\n" + + " }\n" + + "}\n" + + "class X1>> {\n" + + " A a1;\n" + + "}\n" + + "class X2> {\n" + + " A a2;\n" + + "}\n" + + "class X3 {\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>> {}\n" + + "class X1> {}\n" + + "class X2 {}\n" + + "class X3>> {}\n" + + " ^^^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 3)\n" + + " class X1> {}\n" + + " ^^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 4)\n" + + " class X2 {}\n" + + " ^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 5)\n" + + " class X3 expected after this token\n" + + "----------\n" + ); + } + // TODO (david) remove errors: insert dimension to complete array type + public void test0081() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X> {}\n" + + "class X1 {}\n" + + "class X2 {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X> {}\n" + + " ^^\n" + + "Syntax error, insert \">>\" to complete ReferenceType2\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 3)\n" + + " class X1 {}\n" + + " ^\n" + + "Syntax error, insert \">>\" to complete ReferenceType2\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 4)\n" + + " class X2>\" 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 {}\n" + + "class X1> {}\n" + + "class X3 {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, insert \">>>\" to complete ReferenceType3\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 3)\n" + + " class X1>>\" 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>> {}\n" + + "class X2> {}\n" + + "class X3 {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X>>\" to complete ReferenceType3\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 2)\n" + + " public class X\" to complete ReferenceType1\n" + + "----------\n"); + } + public void test0084() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(AX a, AX b) {\n" + + " }\n" + + " void foo(AX 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 as = new AX(null);\n" + + " as.print(a);\n" + + " as.bar(a);\n" + + " }\n" + + "}\n" + + "class AX

{\n" + + " AX(AX

ax){}\n" + + " AX(P p){}\n" + + " void print(P p){}\n" + + " void foo(AX rawAx){}\n" + + " void bar(AX

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\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

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\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

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

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

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

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

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

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

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

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\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

should be parameterized\n" + + "----------\n" + + "14. ERROR in X.java (at line 13)\n" + + " AX as = new AX(null);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor AX(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 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\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

should be parameterized\n" + + "----------\n"); + } + + public void test0085() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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

{\n" + + " \n" + + " P p;\n" + + "}\n", + }, + "null"); + } + + public void test0086() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " ax.p = new AX();\n" + + " System.out.println(ax2);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

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

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

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

should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " ax.p = new AX();\n" + + " ^\n" + + "Type safety: The field p from the raw type AX is assigned a value of type AX. 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 {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " AX ax3 = new AX();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

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 {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " AX ax3 = new AX();\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + "", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + + public void test0089() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T q;\n" + + " public static void main(String[] args) {\n" + + " X xss = new X();\n" + + " 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 {\n" + + " T q;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X xss = new X();\n" + + " X> xxs = new X>();\n" + + " xxs.q = xss;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X[] xs) {\n" + + " xs[0] = new X();\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + + public void test0091() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X[] xs) {\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo() {\n" + + " X xs = new X(\"\");\n" + + " X 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(\"SUCCESS\").foo();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " X xs2 = (X) xs;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X 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 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. 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 {\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

{\n" + + " AX

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 extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " I w = new X().get(new I());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class S {}\n" + + "class I implements C {}\n" + + "interface C {}\n" + + "class XS {\n" + + " Txs get(Txs t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0095() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " I w = new X().get(new I());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class S {}\n" + + "class I implements C {}\n" + + "interface C {}\n" + + "class XS {\n" + + " Txs get(Txs t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0096() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X {}\n" + + " ^\n" + + "Cycle detected: the type X 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 extends X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X {}\n" + + " ^\n" + + "Cycle detected: the type X 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 {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " ax.p = new AX();\n" + + " ax.q = new AX();\n" + + " ax.r = new AX();\n" + + " ax.s = new AX();\n" + + " System.out.println(ax2);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + " AX q;\n" + + " AX r;\n" + + " BX s;\n" + + "}\n" + + "\n" + + "class BX {\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

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

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

should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " ax.p = new AX();\n" + + " ^\n" + + "Type safety: The field p from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " ax.q = new AX();\n" + + " ^\n" + + "Type safety: The field q from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " ax.r = new AX();\n" + + " ^\n" + + "Type safety: The field r from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " ax.s = new AX();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AX 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 > {\n" + + " public static void main(String[] args) {\n" + + " AX ax;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X x) {\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X > {\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 {\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 AX());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P foo() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X(new AX());\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X x = new X(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n"); + } + + // wilcard may not pass parameter bound check + public void test0101() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 AX());\n" + + " x.t.foo(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\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 {\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 x = new X>(new AX());\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends AX is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "Bound mismatch: The type AX 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

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 {\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

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX 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 {\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

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

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() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX 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 [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 [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\n"; + + 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); + } + } + + // wildcard bound check + public void test0104() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 AX());\n" + + " x.t.foo(\"SUCC\");\n" + + " x.t.bar(\"ESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX 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 {\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "BX is a raw type. References to generic type BX should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X> 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

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 should be parameterized\n" + + "----------\n"); + } + public void test0105() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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 AX());\n" + + " x.t.foo(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\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 {\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

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX 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 is = new ArrayList();\n" + + " is.iterator();\n" + + " }\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " Iterable is = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to Iterable\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Iterable is = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n", + null, + true, + customOptions); + } + // class literal: Integer.class of type Class + 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 {}\n" + + "class Y extends X implements AX {}\n" + + "interface AX

{}\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 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 {}\n" + + "interface AX

{}\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

should be parameterized\n" + + "----------\n" + + "2. 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 and AX\n" + + "----------\n"); + } + public void test0111() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AX {}\n" + + "class Y extends X implements AX {}\n" + + "interface AX

{}\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 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

should be parameterized\n" + + "----------\n"); + } + // test member types + public void test0112() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " void foo(X.MX.MMX mx) {}\n" + + " class MX {\n" + + " class MMX {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " void foo(X.MX.MMX mx) {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Thread is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " void foo(X.MX.MMX mx) {}\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " class MX {\n" + + " class MMX {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type Runnable is not a valid substitute for the bounded parameter of the type X.MX\n" + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " class MX {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " class MX {\n" + + " class MMX {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type Iterable 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 {}\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + } + public void test0113() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo() {\n" + + " new X().new MX();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0114() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + " }\n" + + " void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0115() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().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 {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().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 .MX.MMX>>{\n" + + " public static void main(String [] args) {\n" + + " \n" + + " new X.MX.MMX>>().new MX();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X.MX.MMX mx) {\n" + + " }\n" + + " \n" + + " class MX {\n" + + " class MMX {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " new X.MX.MMX>>().new MX();\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " new X.MX.MMX>>().new MX();\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + // test generic method with recursive parameter bound > + 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());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // test generic method + public void test0118a() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class A {}\n" + + "\n" + + "public class X {\n" + + " static , U> void foo() {}\n" + + " void bar(A a) {\n" + + " foo();\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); + } + // test binary member types ** + public void _test0119() { + this.runConformTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " public static void main(String [] args) {\n" + + " \n" + + " new X.MX.MMX>>().new MX();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X.MX.MMX mx) {\n" + + " }\n" + + " void foo2(X.MX.MMX mx) {\n" + + " }\n" + + " void foo3(X.MX.MMX>> mx) {\n" + + " }\n" + + " \n" + + " class MX {\n" + + " class MMX {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS" + ); + + // TODO (philippe) bounds checks are done before binaryType X is finished creating its type variables + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // test generic method + public void test0120() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " String s = new X().foo(\"SUCCESS\");\n" + + " }\n" + + " T foo (U u) {\n" + + " System.out.println(u);\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // test generic method + public void test0120a() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " > U foo() {\n" + + " return null;\n" + + " }\n" + + " > V bar() {\n" + + " return foo();\n" + + " }\n" + + "}" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6302954 /* javac test options */); + } + // substitute array types + public void test0121() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo(args);\n" + + " }\n" + + " \n" + + " void foo(T[] ts) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // generic method with most specific common supertype: U --> String + public void test0122() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo(args, new X>());\n" + + " }\n" + + " void foo(U[] us, X> xxu) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // invalid parameterized type + public void test0123() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T ts;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T ts;\n" + + " ^\n" + + "The type T is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // generic method with indirect type inference: BX --> AX + public void test0124() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(AX aw) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new BX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX {\n" + + "}\n" + + "class BX extends AX {\n" + + "}\n", + }, + "SUCCESS"); + } + // generic method with indirect type inference: CX --> AX + public void test0125() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(AX aw) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new CX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX {\n" + + "}\n" + + "class BX extends AX {\n" + + "}\n" + + "class CX extends BX {\n" + + "}\n", + }, + "SUCCESS"); + } + // variation on test0125 with typo: CX extends B instead of BX. + public void test0126() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(AX aw) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new CX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX {\n" + + "}\n" + + "class BX extends AX {\n" + + "}\n" + + "class CX extends B {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo(new CX());\n" + + " ^^^\n" + + "The method foo(AX) in the type X is not applicable for the arguments (CX)\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " class CX extends B {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // 57784: test generic method + public void test0127() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.Arrays.asList(new Object[] {\"1\"});\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // 58666: special treatment for Object#getClass declared of type: Class + // but implicitly converted to Class for free. + public void test0128() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " Class c1 = x.getClass();\n" + + " Class c2 = x.getClass();\n" + + " String s = \"hello\";\n" + + " Class c3 = s.getClass();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Class c1 = x.getClass();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Class c3 = s.getClass();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + // variation on test0128 + public void test0129() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + "\n" + + " public static void main(String[] args) {\n" + + " XY xy = new XY();\n" + + " Class c1 = xy.getClass();\n" + + " Class c2 = xy.getClass();\n" + + " String s = \"hello\";\n" + + " Class c3 = s.getClass();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class XY extends X {\n" + + " public Class getClass() {\n" + + " return super.getClass();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Class c1 = xy.getClass();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Class c3 = s.getClass();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " public Class getClass() {\n" + + " ^^^^^^^^^^\n" + + "Cannot override the final method from Object\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " public Class getClass() {\n" + + " ^^^^^^^^^^\n" + + "The method getClass() of type XY should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + } + // getClass on array type + public void test0130() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + "\n" + + " public static void main(String[] args) {\n" + + " X[] x = new X[0];\n" + + " Class c = x.getClass();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // 58979 + public void test0131() { + this.runNegativeTest( + new String[] { + "ArrayList.java", + " interface List {\n" + + " List foo();\n" + + "}\n" + + "\n" + + " class ArrayList implements List {\n" + + " public List foo() {\n" + + " List lt = this;\n" + + " lt.bar();\n" + + " return this;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ArrayList.java (at line 8)\n" + + " lt.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type List\n" + + "----------\n"); + } + public void test0132() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " .Z> foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " .Z> foo() {}\n" + + " ^\n" + + "The type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " .Z> foo() {}\n" + + " ^\n" + + "W cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " .Z> foo() {}\n" + + " ^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); + } + // bridge method + public void test0133() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new Y();\n" + + " System.out.println(x.foo());\n" + + " }\n" + + " T foo() {return null;}\n" + + " void foo(T t) {}\n" + + "}\n" + + "class Y extends X {\n" + + " String foo() {return \"SUCCESS\";}\n" + + " void foo(String s) {}\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0134() { + this.runConformTest( + new String[] { + "Z.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Z { \n" + + " T t;\n" + + " public static void main(String[] args) {\n" + + " foo(new Z().set(new ArrayList()));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Z set(T t) {\n" + + " this.t = t;\n" + + " return this;\n" + + " }\n" + + " T get() { \n" + + " return this.t; \n" + + " }\n" + + " \n" + + " static void foo(Z za) {\n" + + " za.get().isEmpty();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0135() { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z { \n" + + " public static void main(String[] args) {\n" + + " foo(new Z());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " static void foo(Z zs) {\n" + + " }\n" + + "}\n" + + "\n" + + "class ZA {\n" + + " void foo() {}\n" + + "}\n" + + "\n" + + "class ZB extends ZA {\n" + + "}" + }, + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " foo(new Z());\n" + + " ^^^\n" + + "The method foo(Z) in the type Z is not applicable for the arguments (Z)\n" + + "----------\n" + + "2. ERROR in Z.java (at line 6)\n" + + " static void foo(Z zs) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super String is not a valid substitute for the bounded parameter of the type Z\n" + + "----------\n"); + } + public void test0136() { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z { \n" + + " public static void main(String[] args) {\n" + + " foo(new Z());\n" + + " }\n" + + " static void foo(Z zs) {\n" + + " zs.foo();\n" + + " }\n" + + "}\n" + + "class ZA {\n" + + "}\n" + + "class ZB extends ZA {\n" + + " void foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " foo(new Z());\n" + + " ^^^\n" + + "The method foo(Z) in the type Z is not applicable for the arguments (Z)\n" + + "----------\n" + + "2. ERROR in Z.java (at line 5)\n" + + " static void foo(Z zs) {\n" + + " ^^^^^^^^^^\n" + + "Bound mismatch: The type ? super ZA is not a valid substitute for the bounded parameter of the type Z\n" + + "----------\n" + + "3. ERROR in Z.java (at line 6)\n" + + " zs.foo();\n" + + " ^^^\n" + + "The method foo(Z) in the type Z is not applicable for the arguments ()\n" + + "----------\n"); + } + public void test0137() { + this.runConformTest( + new String[] { + "Z.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Z { \n" + + " T t;\n" + + " public static void main(String[] args) {\n" + + " foo(new Z().set(new ArrayList()));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Z set(T t) {\n" + + " this.t = t;\n" + + " return this;\n" + + " }\n" + + " T get() { \n" + + " return this.t; \n" + + " }\n" + + " \n" + + " static void foo(Z za) {\n" + + " za.get().isEmpty();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // unbound wildcard still remembers its variable bound: Z behaves like Z + public void test0138() { + this.runConformTest( + new String[] { + "Z.java", + "public class Z {\n" + + " T t;\n" + + " Z(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Z> zax = new Z>(new AX());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void baz(Z zu){\n" + + " zu.t.foo(null);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // extending wildcard considers its bound prior to its corresponding variable + public void test0139() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x.get().afoo();\n" + + " x.get().bfoo();\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends BX is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " x.get().afoo();\n" + + " ^^^^\n" + + "The method afoo() is undefined for the type capture#1-of ? extends BX\n" + + "----------\n"); + } + // extending wildcard considers its bound prior to its corresponding variable + public void test0140() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x.get().afoo();\n" + + " x.get().bfoo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX extends AX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "SUCCESS"); + } + // super wildcard considers its variable for lookups + public void test0141() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x.get().afoo();\n" + + " x.get().bfoo();\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX extends AX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " x.get().bfoo();\n" + + " ^^^^\n" + + "The method bfoo() is undefined for the type capture#2-of ? super BX\n" + + "----------\n"); + } + public void test0142() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x = identity(x);\n" + + " }\n" + + "

X

identity(X

x) {\n" + + " return x;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX extends AX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " x = identity(x);\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The generic method identity(X

) of type X is not applicable for the arguments (X). The inferred type capture#2-of ? extends X is not a valid substitute for the bounded parameter

\n" + + "----------\n"); + } + public void test0143() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class xx = null;\n" + + " Class xo = xx;\n" + + " Class xo2 = xx;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Class xo2 = xx;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + public void test0144() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class xx = null;\n" + + " Class xo = xx;\n" + + " X x = get(xx);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " static

P get(Class

cp) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // 59641: check assign/invoke with wildcards + public void test0145() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " XList lx = new XList();\n" + + " X x = lx.get();\n" + + " lx.add(null);\n" + + " lx.add(x);\n" + + " lx.slot = x;\n" + + " lx.addAll(lx);\n" + + " } \n" + + "}\n" + + "class XList {\n" + + " E slot;\n" + + " void add(E e) {}\n" + + " E get() { return null; \n" + + " }\n" + + " void addAll(XList le) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lx.add(x);\n" + + " ^^^\n" + + "The method add(capture#3-of ?) in the type XList is not applicable for the arguments (X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " lx.slot = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to capture#4-of ?\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " lx.addAll(lx);\n" + + " ^^^^^^\n" + + "The method addAll(XList) in the type XList is not applicable for the arguments (XList)\n" + + "----------\n"); + } + // 59628 + public void test0146() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.AbstractList;\n" + + "public class X extends AbstractList {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public int size() { return 0; }\n" + + " public Object get(int index) { return null; }\n" + + "}\n" + }, + "SUCCESS"); + } + // 59723 + public void test0147() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " char[][] tokens = new char[0][];\n" + + " ArrayList list = new ArrayList();\n" + + " list.toArray(tokens);\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n" + }, + "SUCCESS"); + } + // bridge method + public void test0148() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AX{\n" + + " \n" + + " String foo(String s) {\n" + + " System.out.println(s);\n" + + " return s;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " T foo(T t) {\n" + + " return null;\n" + + " }\n" + + " void bar(T t) {\n" + + " foo(t);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // method compatibility + public void test0149() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements java.util.Collection {\n" + + " public Object[] toArray(Object[] a) {\n" + + " return a;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements java.util.Collection {\n" + + " public Object[] toArray(Object[] a) {\n" + + " return a;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Object[] toArray(Object[] a) {\n" + + " ^^^^^^^^\n" + + "Type safety: The return type Object[] for toArray(Object[]) from the type X needs unchecked conversion to conform to T[] from the type Collection\n" + + "----------\n"); + } + public void test0150() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " \n" + + " void foo(T[] ta, List lt) {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(args, new ArrayList());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo(args, new ArrayList());\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(T[], List) of type X is not applicable for the arguments (String[], ArrayList). The inferred type String is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } + public void test0151() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " \n" + + " X(T[] ta, List lt) {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X(args, new ArrayList());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X(T[] ta, List lt) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " new X(args, new ArrayList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic constructor X(T[], List) of type X is not applicable for the arguments (String[], ArrayList). The inferred type String is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } + // 60556 + public void test0152() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " List x(List list) {\n" + + " return Collections.unmodifiableList(list);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0153() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0154() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0155() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0156() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public static AX bar(AX a) {\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type AX\n" + + "----------\n"); + } + public void test0157() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX as = new AX();\n" + + " AX a = bar(ax, as);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a, AX b) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " AX a = bar(ax, as);\n" + + " ^^^\n" + + "The method bar(AX, AX) in the type X is not applicable for the arguments (AX, AX)\n" + + "----------\n"); + } + public void test0158() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX as = new AX();\n" + + " AX a = bar(ax, as);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a, AX b) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0159() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"SUCCESS\");\n" + + " AX a = bar(ax, as);\n" + + " }\n" + + " public static T bar(AX a, AX b) {\n" + + " return a.get();\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to T\n" + + "----------\n"); + } + public void test0160() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = foo(new AX(\"aaa\"));\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0161() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " boolean b = foo(new AX(\"aaa\")).equals(args);\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + " String bar() {\n" + + " return \"bbb\";\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0162() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + " String bar() {\n" + + " return \"bbb\";\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type Object\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0163() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + " String bar() {\n" + + " return \"bbb\";\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type Object\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0164() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo(new AX(\"SUCCESS\"));\n" + + " }\n" + + " static List foo(AX a) {\n" + + " System.out.println(a.get());\n" + + " List v = null;\n" + + " if (a == null) v = foo(a); \n" + + " return v;\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0165() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " if (a == null) {\n" + + " AX as = bar(a);\n" + + " String s = as.get();\n" + + " }\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E get() { return null; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0166() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX a = bar(ax, true);\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX bar(AX a, boolean recurse) {\n" + + " if (recurse) {\n" + + " AX as = bar(a, false);\n" + + " String s = as.get();\n" + + " }\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0167() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX a = bar();\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX bar() {\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0168() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX a = bar();\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX, U> bar() {\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AX a = bar();\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from AX,Thread> to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor AX(Object) belongs to the raw type AX. References to generic type AX should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX,U>\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n"); + } + public void test0169() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX a = bar(new X());\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX bar(T t) {\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AX a = bar(new X());\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AX to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor AX(Object) belongs to the raw type AX. References to generic type AX should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n"); + } + // Expected type inference for cast operation + public void test0170() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"\");\n" + + " ax = (AX)bar(ax);\n" + // shouldn't complain about unnecessary cast + " }\n" + + " public static T bar(AX a) {\n" + + " return a.get();\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to T\n" + + "----------\n"); + } + // Expected type inference for cast operation + public void test0171() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"\");\n" + + " ax = (AX)bar(ax);\n" + // shouldn't complain about unnecessary cast as return type inference do not + " }\n" + // work on cast conversion + " public static T bar(AX a) {\n" + + " return a.get();\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to T\n" + + "----------\n"); + } + // Expected type inference for cast operation + public void test0172() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"SUCCESS\");\n" + + " ax = (AX)bar(ax);\n" + // no warn for unsafe cast, since forbidden cast + " }\n" + + " public static String bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from String to AX\n" + + "----------\n"); + } + // Expected type inference for return statement + public void test0173() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static T bar(AX a) {\n" + + " return null;\n" + + " } \n" + + " public static AX foo() {\n" + + " AX ax = new AX(new X());\n" + + " return bar(ax);\n" + // use return type of enclosing method for type inference + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + + "\n" + }, + "SUCCESS"); + } + // Expected type inference for field declaration + public void test0174() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Object o = foo;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static T bar(AX a) {\n" + + " return null;\n" + + " } \n" + + " static AX foo = bar(new AX(new X()));\n" + // use field type for type inference + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + + "\n" + }, + "SUCCESS"); + } + // 60563 + public void test0175() { + this.runConformTest( + new String[] { + "X.java", + " interface A {\n" + + " T[] m1(T x); \n" + + " }\n" + + " public class X { \n" + + " public static void main(String[] args) {\n" + + " new X().m2(new A(){ \n" + + " public X[] m1(X x) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " });\n" + + " }\n" + + " void m2(A x) { \n" + + " m3(x.m1(new X())); \n" + + " }\n" + + " void m3(X[] x) {\n" + + " } \n" + + " }\n" + }, + "SUCCESS"); + } + // unsafe raw return value + public void test0176() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Vector valuesOf(Hashtable h) {\n" + + " return new Vector();\n" + + " }\n" + + " Vector data;\n" + + " \n" + + " public void t() {\n" + + " Vector v = (Vector) data.elementAt(0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " return new Vector();\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Vector needs unchecked conversion to conform to Vector\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " return new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " Vector v = (Vector) data.elementAt(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Vector\n" + + "----------\n", + null, + true, + customOptions); + } + // cast to type variable allowed, can be diagnosed as unnecessary + public void test0177() { + Map options = getCompilerOptions(); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " return (T) t;\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + options /* custom options - happen to be the default not changed by the test suite */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 4)\n" + + " return (T) t;\n" + + " ^^^^^\n" + + "Unnecessary cast from T to T\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); + } + // reject instanceof type variable or parameterized type + public void test0178() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " if (t instanceof X) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + // ok + " return t;\n" + + " } else if (t instanceof T) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + + " return t;\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (t instanceof X) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type X. Use instead its raw form X since generic type information will be erased at runtime\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " } else if (t instanceof X) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type X. Use instead its raw form X since generic type information will be erased at runtime\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " } else if (t instanceof T) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter T. Use instead its erasure Object since generic type information will be erased at runtime\n" + + "----------\n", + null, + true, + customOptions); + } + // 61507 + public void test0179() { + this.runConformTest( + new String[] { + "X.java", + "class U {\n" + + " static T notNull(T t) { return t; }\n" + + "}\n" + + "public class X {\n" + + " void t() {\n" + + " String s = U.notNull(null);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().t();\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0180() { + this.runConformTest( + new String[] { + "X.java", + "class U {\n" + + " static T notNull(T t) { return t; }\n" + + "}\n" + + "public class X {\n" + + " void t() {\n" + + " String s = U.notNull(\"\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().t();\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=61507 - variation computing most specific type with 'null' + public void test0181() { + this.runConformTest( + new String[] { + "X.java", + "class U {\n" + + " static T notNull(T t, V vt) { return t; }\n" + + "}\n" + + "class V {}\n" + + "\n" + + "public class X {\n" + + " void t() {\n" + + " String s = U.notNull(null, new V());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().t();\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0182() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X foo() {\n" + + " return (X) this;\n" + + " }\n" + + " X bar() {\n" + + " return (AX) new X();\n" + + " }\n" + + " X bar(Object o) {\n" + + " return (AX) o;\n" + + " }\n" + + " X foo(Object o) {\n" + + " return (AX) o;\n" + + " } \n" + + " X baz(Object o) {\n" + + " return (AX) null;\n" + + " }\n" + + " X baz2(BX bx) {\n" + + " return (X) bx;\n" + + " } \n" + + "}\n" + + "class AX extends X {}\n" + + "class BX extends AX {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (X) this;\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return (AX) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to AX\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " return (AX) o;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " return (AX) o;\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " return (AX) null;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from null to AX\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " return (X) bx;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from BX to X\n" + + "----------\n"); + } + public void test0183() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " \n" + + " {\n" + + " Dictionary d;\n" + + " Object o;\n" + + " \n" + + " Object a1 = (Hashtable) d;\n" + + " Object a2 = (Hashtable) o;\n" + + "\n" + + " Object a3 = (Hashtable) d;\n" + + " Object a4 = (Hashtable) o;\n" + + " \n" + + " abstract class Z1 extends Hashtable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " Z1 z1;\n" + + " Object a5 = (Hashtable) z1;\n" + + "\n" + + " abstract class Z2 extends Z1 {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " Object a6 = (Z2) z1;\n" + + "\n" + + " abstract class Z3 extends Hashtable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " Z3 z3;\n" + + " Object a7 = (Hashtable) z3;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Object a1 = (Hashtable) d;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Dictionary to Hashtable\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Object a2 = (Hashtable) o;\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to Hashtable\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " Object a2 = (Hashtable) o;\n" + + " ^^^^^^^^^\n" + + "Hashtable is a raw type. References to generic type Hashtable should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " Object a3 = (Hashtable) d;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Dictionary to Hashtable\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Object a3 = (Hashtable) d;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Dictionary to Hashtable\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " Object a4 = (Hashtable) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Hashtable\n" + + "----------\n" + + "7. WARNING in X.java (at line 13)\n" + + " Object a4 = (Hashtable) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to Hashtable\n" + + "----------\n" + + "8. WARNING in X.java (at line 19)\n" + + " Object a5 = (Hashtable) z1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Z1 to Hashtable\n" + + "----------\n" + + "9. WARNING in X.java (at line 24)\n" + + " Object a6 = (Z2) z1;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from Z1 to Z2\n" + + "----------\n" + + "10. WARNING in X.java (at line 26)\n" + + " abstract class Z3 extends Hashtable {\n" + + " ^^^^^^^^^\n" + + "Hashtable is a raw type. References to generic type Hashtable should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 30)\n" + + " Object a7 = (Hashtable) z3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Z3 to Hashtable\n" + + "----------\n" + + "12. WARNING in X.java (at line 30)\n" + + " Object a7 = (Hashtable) z3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Z3 to Hashtable\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62292 - parameterized message send + public void test0184() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized message send - variation on 184 with non-static generic method + public void test0185() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // message send parameterized with type not matching parameter bounds + public void test0186() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T foo(T t, U u) {\n" + + " ^^^^^^\n" + + "The type parameter U 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" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(T, U) of type X is not applicable for the arguments (String, null). The inferred type X is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } + // invalid type argument arity for parameterized message send + public void test0187() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T foo(T t, U u) {\n" + + " ^^^^^^\n" + + "The type parameter U 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" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " ^^^\n" + + "Incorrect number of type arguments for generic method foo(T, U) of type X; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized invocation of non generic method with incorrect argument count + public void test0188() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " ^^^\n" + + "The method foo() in the type X is not applicable for the arguments (String, null)\n" + + "----------\n"); + } + // parameterized invocation of non generic method + public void test0189() { + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 + ? "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo());\n" + + " ^^^\n" + + "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo());\n" + + " ^^^^^^^\n" + + "The method println(boolean) in the type PrintStream is not applicable for the arguments (void)\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " System.out.println(new X().foo());\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo());\n" + + " }\n" + + "}\n", + }, + expectedOutput); + } + // parameterized allocation + public void test0190() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized allocation - wrong arity + public void test0191() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incorrect number of type arguments for generic constructor X(T) of type X; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized allocation - non generic target constructor + // ** + public void test0192() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"FAILED\");\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " new X(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // parameterized allocation - argument type mismatch + public void test0193() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new X(null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X(new X(null));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(String) of type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + // parameterized invocation - argument type mismatch + public void test0194() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo(T t) {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(new X()));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo(new X()));\n" + + " ^^^\n" + + "The parameterized method foo(String) of type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + // parameterized qualified allocation + public void test0195() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized qualified allocation - wrong arity + public void test0196() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new MX(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incorrect number of type arguments for generic constructor MX(T) of type X.MX; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized qualified allocation - non generic target constructor + // ** + public void test0197() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new MX(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor MX(String) of type X.MX is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"FAILED\");\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " new X().new MX(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X.MX(String) of type X.MX; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // parameterized qualified allocation - argument type mismatch + public void test0198() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(new X());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new MX(new X());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor MX(String) of type X.MX is not applicable for the arguments (X)\n" + + "----------\n"); + } + // parameterized explicit constructor call + public void test0199() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"SUCCESS\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized explicit constructor call - wrong arity + public void test0200() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Incorrect number of type arguments for generic constructor X(T) of type X; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized explicit constructor call - non generic target constructor + // ** + public void test0201() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " Zork z;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + + "----------\n"); + } + // parameterized explicit constructor call - argument type mismatch + public void test0202() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(new X(null));\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new X(null));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(String) of type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62822 - supertypes partially resolved during bound check + public void test0203() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " demo.AD ad;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "demo/AD.java", + "package demo;\n" + + "public interface AD extends LIST {}\n", + "demo/ADXP.java", + "package demo;\n" + + "public interface ADXP extends BIN {}\n", + "demo/ANY.java", + "package demo;\n" + + "public interface ANY {}\n", + "demo/BL.java", + "package demo;\n" + + "public interface BL extends ANY {}\n", + "demo/LIST.java", + "package demo;\n" + + "public interface LIST extends ANY {}\n", + "demo/BIN.java", + "package demo;\n" + + "public interface BIN extends LIST {}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62806 + public void test0204() { + this.runConformTest( + new String[] { + "Function.java", + "public abstract class Function {\n" + + " public abstract Y eval(X x);\n" + + "\n" + + "}\n", + "FunctionMappedComparator.java", + "import java.util.*;\n" + + "public class FunctionMappedComparator implements Comparator {\n" + + " /*\n" + + " * \'Function\' is highlighted as an error here - the message is:\n" + + " * The type Function is not generic; it cannot be parameterized with arguments \n" + + " */\n" + + " protected Function function;\n" + + " protected Comparator comparator;\n" + + " public FunctionMappedComparator(Function function,Comparator comparator ) {\n" + + " this.function=function;\n" + + " this.comparator=comparator;\n" + + " }\n" + + "\n" + + " public int compare(X x1, X x2) {\n" + + " return comparator.compare(function.eval(x1),function.eval(x2));\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63555 - reference to static type parameter allowed inside type itself + public void test0205() { + this.runConformTest( + new String[] { + "Alpha.java", + "public class Alpha {\n" + + " static class Beta {\n" + + " T obj;\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63555 - variation on static method type parameter + public void test0206() { + this.runConformTest( + new String[] { + "Alpha.java", + "public class Alpha {\n" + + " static void Beta(T t) {\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63590 - disallow parameterized type in catch/throws clause + public void test0207() { + this.runNegativeTest( + new String[] { + "Alpha.java", + "public class Alpha extends RuntimeException {\n" + + " public static void main(String[] args) {\n" + + " new Object() {\n" + + " public void m() throws Alpha {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.m();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Alpha.java (at line 1)\n" + + " public class Alpha extends RuntimeException {\n" + + " ^^^^^\n" + + "The serializable class Alpha does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in Alpha.java (at line 1)\n" + + " public class Alpha extends RuntimeException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The generic class Alpha may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. ERROR in Alpha.java (at line 4)\n" + + " public void m() throws Alpha {\n" + + " ^^^^^\n" + + "Cannot use the parameterized type Alpha either in catch block or throws clause\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63590 - disallow parameterized type in catch/throws clause + public void test0208() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends RuntimeException {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new X();\n" + + " } catch(X e) {\n" + + " System.out.println(\"X\");\n" + + " } catch(X> e) {\n" + + " System.out.println(\"X>\");\n" + + " } catch(RuntimeException e) {\n" + + " System.out.println(\"RuntimeException\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends RuntimeException {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends RuntimeException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The generic class X may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " } catch(X e) {\n" + + " ^\n" + + "Cannot use the parameterized type X either in catch block or throws clause\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " } catch(X> e) {\n" + + " ^\n" + + "Cannot use the parameterized type X> either in catch block or throws clause\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63556 - should resolve all occurrences of A to type variable + public void test0209() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {}\n" + + "class X2, B> {}\n" + + "class X3> {}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68006 - Invalid modifier after parse + public void test0210() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Map m){\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Map m){\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n"); + } + // test compilation against binaries + public void test0211() { + this.runConformTest( + new String[] { + "p/Top.java", + "package p;\n" + + "public interface Top {}\n", + }, + ""); + + this.runConformTest( + new String[] { + "p/Super.java", + "package p;\n" + + "public class Super implements Top{\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // check type variable equivalence + public void test0212() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X{\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " X _recurse; \n" + + " public List toList(){\n" + + " List result = new ArrayList();\n" + + " result.addAll(_recurse.toList()); // should be applicable\n" + + " return result;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0213() { + this.runConformTest( + new String[] { + "X.java", + "public class X>{\n" + + " T test;\n" + + " public Comparable getThis(){\n" + + " return test;\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68133 - verify error + public void test0214() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " ArrayList l;\n" + + " switch (args.length) {\n" + + " case 1:\n" + + " l = new ArrayList();\n" + + " System.out.println(l);\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68133 variation + public void test0215() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.ArrayList i; \n" + + " outer: {\n" + + " if (args == null) {\n" + + " i = null;\n" + + " break outer;\n" + + " }\n" + + " return;\n" + + " }\n" + + " System.out.println(i); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 aload_0 [args]\n" + + " 1 ifnonnull 9\n" + + " 4 aconst_null\n" + + " 5 astore_1 [i]\n" + + " 6 goto 10\n" + + " 9 return\n" + + " 10 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 13 aload_1 [i]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [22]\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 20 ldc [28]\n" + + " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + + " 25 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 6, line: 7]\n" + + " [pc: 9, line: 9]\n" + + " [pc: 10, line: 11]\n" + + " [pc: 17, line: 12]\n" + + " [pc: 25, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 26] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 6, pc: 9] local: i index: 1 type: java.util.ArrayList\n" + + " [pc: 10, pc: 26] local: i index: 1 type: java.util.ArrayList\n" + + " Local variable type table:\n" + + " [pc: 6, pc: 9] local: i index: 1 type: java.util.ArrayList\n" + + " [pc: 10, pc: 26] local: i index: 1 type: java.util.ArrayList\n"; + + 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); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68998 parameterized field constants + public void test0216() { + this.runConformTest( + new String[] { + "test/cheetah/NG.java", + "package test.cheetah;\n" + + "public class NG extends G {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + " public boolean test() {\n" + + " return o == null;\n" + + " }\n" + + "}\n", + "test/cheetah/G.java", + "package test.cheetah;\n" + + "public class G {\n" + + " protected Object o;\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69135 - unnecessary cast operation + public void test0217() { + Map customOptions = getCompilerOptions(); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " ArrayList l= new ArrayList();\n" + + " String string = (String) l.get(0);\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 5)\n" + + " String string = (String) l.get(0);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=64154 visibility issue due to invalid use of parameterized binding + public void test0218() { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " private final T _data;\n" + + " private X(T data){\n" + + " _data = data;\n" + + " }\n" + + " public T getData(){\n" + + " return _data;\n" + + " }\n" + + " public static X create(E data) {\n" + + " return new X(data);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " create(new Object());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=64154 variation + public void test0219() { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " private final T _data;\n" + + " private X(T data){\n" + + " _data = data;\n" + + " }\n" + + " public T getData(){\n" + + " return _data;\n" + + " }\n" + + " public static E create(E data) {\n" + + " return new X(data)._data;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " create(new Object());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141 unsafe wildcard operation tolerates wildcard with lower bounds + public void test0220() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " ArrayList al = new ArrayList();\n" + + " al.add(new Integer(1)); // (1)\n" + + " Integer i = al.get(0); // (2)\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Integer i = al.get(0); // (2)\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? super Integer to Integer\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141 variation + public void test0221() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " ArrayList al = new ArrayList();\n" + + " al.add(new Integer(1)); // (1)\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " al.add(new Integer(1)); // (1)\n" + + " ^^^\n" + + "The method add(capture#1-of ? extends Integer) in the type ArrayList is not applicable for the arguments (Integer)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141: variation + public void test0222() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " XList lx = new XList();\n" + + " lx.slot = new Integer(1);\n" + + " Integer i = lx.slot;\n" + + " } \n" + + "}\n" + + "class XList {\n" + + " E slot;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Integer i = lx.slot;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? super Integer to Integer\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69251- instantiating wildcards + public void test0223() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " static final Map> classes \n" + + " = new HashMap>();\n" + + " \n" + + " static final Map> classes2 \n" + + " = new HashMap();\n" + + " \n" + + " class MX {\n" + + " E get() { return null; }\n" + + " void foo(E e) {}\n" + + " }\n" + + " \n" + + " void foo() {\n" + + " MX> mx1 = new MX>();\n" + + " MX mx2 = new MX();\n" + + " mx1.foo(mx2.get());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " = new HashMap();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from HashMap to Map>\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " = new HashMap();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " MX mx2 = new MX();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " MX mx2 = new MX();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 18)\n" + + " mx1.foo(mx2.get());\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68998 variation + public void test0224() { + this.runNegativeTest( + new String[] { + "test/cheetah/NG.java", + "package test.cheetah;\n" + + "public class NG extends G {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + " public boolean test() {\n" + + " return o == null;\n" + + " }\n" + + "}\n", + "test/cheetah/G.java", + "package test.cheetah;\n" + + "public class G {\n" + + " protected final Object o;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in test\\cheetah\\NG.java (at line 2)\n" + + " public class NG extends G {\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\cheetah\\G.java (at line 2)\n" + + " public class G {\n" + + " ^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69353 - prevent using type parameter in catch block + public void test0225() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo() throws T {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().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 (T t) {\n" + + " }\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " } catch (T t) {\n" + + " ^\n" + + "Cannot use the type parameter T in a catch block\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " } catch (T t) {\n" + + " ^\n" + + "The parameter t is hiding another local variable defined in an enclosing type scope\n" + + "----------\n" + + "3. WARNING in X.java (at line 19)\n" + + " class EX extends Exception {\n" + + " ^^\n" + + "The serializable class EX does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69170 - invalid generic array creation + public void test0226() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " Object x1= new T[0];\n" + + " Object x2= new X[0]; \n" + + " Object x3= new X[0]; \n" + + " Object x4= new X[0]; \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object x1= new T[0];\n" + + " ^^^^^^^^\n" + + "Cannot create a generic array of T\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object x2= new X[0]; \n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Object x3= new X[0]; \n" + + " ^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69359 - unsafe cast diagnosis + public void test0227() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + " public class X {\n" + + " List list() { return null; }\n" + + " void m() { List l = (List)list(); } // unsafe cast\n" + + " void m0() { List l = list(); } // unsafe conversion\n" + + " void m1() { for (X a : list()); } // type mismatch\n" + + " void m2() { for (Iterator i = list().iterator(); i.hasNext();); } // unsafe conversion\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " void m4() { Collection c = null; List l = (List)c; } // ok\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + "}\n" , + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " List list() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " void m() { List l = (List)list(); } // unsafe cast\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " void m() { List l = (List)list(); } // unsafe cast\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " void m0() { List l = list(); } // unsafe conversion\n" + + " ^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void m1() { for (X a : list()); } // type mismatch\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to X\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " void m2() { for (Iterator i = list().iterator(); i.hasNext();); } // unsafe conversion\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 8)\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Collection to List\n" + + "----------\n" + + "10. WARNING in X.java (at line 9)\n" + + " void m4() { Collection c = null; List l = (List)c; } // ok\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 9)\n" + + " void m4() { Collection c = null; List l = (List)c; } // ok\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "13. WARNING in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to Collection\n" + + "----------\n" + + "15. ERROR in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to List\n" + + "----------\n" + + "16. WARNING in X.java (at line 11)\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "17. WARNING in X.java (at line 11)\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "18. ERROR in X.java (at line 11)\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to List\n" + + "----------\n"); + } + // conversion from raw to X is safe (no unsafe warning) + public void test0228() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.*;\n" + + " public class X {\n" + + " List list = new ArrayList();\n" + + " }\n", + }, + ""); + } + // can resolve member through type variable + public void test0229() { + runConformTest( + true, + new String[] { + "X.java", + " public class X {\n" + + " T.MXC f;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " class XC {\n" + + " class MXC {}\n" + + " }\n", + }, + null, + "SUCCESS", + null, + JavacTestOptions.JavacHasABug.JavacBug6569404); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69375 - equivalence of wildcards + public void test0230() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " List li= null;\n" + + " List ln= null;\n" + + " ln = li;\n" + + " li= ln;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " li= ln;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69170 - variation + public void test0231() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " Object x1= new X[0]; \n" + + " Object x2= new X[0]; \n" + + " Object x3= new X[0]; \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object x2= new X[0]; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Object x3= new X[0]; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - generic cast should be less strict + public void test0232() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " private T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Object someVal = cont.getVal(); // no cast \n" + + " System.out.println(cont.getVal()); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0233() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " private T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Number someVal = cont.getVal();// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0234() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Object someVal = cont.val; // no cast \n" + + " System.out.println(cont.val); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0235() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Number someVal = cont.val;// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0236() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Object someVal = (cont).val; // no cast \n" + + " System.out.println((cont).val); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0237() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Number someVal = (cont).val;// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0238() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " Container next;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont = new Container();\n" + + " cont.next = new Container();\n" + + " cont.next.setVal(new Integer(0));\n" + + " badMethod(cont.next);\n" + + " Object someVal = cont.next.val; // no cast \n" + + " System.out.println(cont.next.val); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0239() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " Container next;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont = new Container();\n" + + " cont.next = new Container();\n" + + " cont.next.setVal(new Integer(0));\n" + + " badMethod(cont.next);\n" + + " Number someVal = cont.next.val;// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69713 NPE due to length pseudo field + public void test0240() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String[] elements = null;\n" + + " \n" + + " public X() {\n" + + " String s = \"a, b, c, d\";\n" + + " elements = s.split(\",\");\n" + + " if(elements.length = 3) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if(elements.length = 3) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int to boolean\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69776 - missing checkcast on cast operation + public void test0241() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " private static final Map classes = new HashMap();\n" + + " public static void main(String[] args) throws Exception {\n" + + " classes.put(\"test\", X.class);\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " Object o = clazz.newInstance();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // 69776 - variation + public void test0242() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " private static final Map classes = new HashMap();\n" + + " public static void main(String[] args) throws Exception {\n" + + " classes.put(\"test\", X.class);\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " final Class clazz2 = (Class) classes.get(\"test\");\n" + + " final Class clazz3 = (Class) classes.get(\"test\");\n" + + " Object o = clazz.newInstance();\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " final Class clazz2 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " final Class clazz2 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " final Class clazz3 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " final Class clazz3 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n"); + } + public void test0243() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() {\n" + + " System.out.println(\"Did NOT add bridge method\");\n" + + " return this;\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " X x = new A();\n" + + " x.foo();\n" + + " System.out.print(\" + \");\n" + + " I i = new A();\n" + + " i.foo();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public I foo();\n" + + "}\n" + + "class A extends X implements I {\n" + + " public A foo() {\n" + + " System.out.print(\"Added bridge method\");\n" + + " return this;\n" + + " }\n" + + "}\n" + }, + "Added bridge method + Added bridge method"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() { return this; }\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "SubTypes.java", + "class A extends X {\n" + + " @Override public A foo() { return this; }\n" + + "}\n" + + "class B extends X {\n" + + " @Override public X foo() { return new X(); }\n" + + " @Override public B foo() { return this; }\n" + + "}\n" + + "class C extends A {\n" + + " @Override public X foo() { return new X(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SubTypes.java (at line 5)\n" + + " @Override public X foo() { return new X(); }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type B\n" + + "----------\n" + + "2. ERROR in SubTypes.java (at line 6)\n" + + " @Override public B foo() { return this; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type B\n" + + "----------\n" + + "3. ERROR in SubTypes.java (at line 9)\n" + + " @Override public X foo() { return new X(); }\n" + + " ^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n"); + } + // generic method of raw type + public void test0244() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " T foo(G g) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X rx = new X();\n" + + " rx.foo(\"hello\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " rx.foo(\"hello\");\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n"); + } + // generic method of raw type + public void test0245() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " T foo(G g) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X rx = new X();\n" + + " rx.foo(\"hello\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " rx.foo(\"hello\");\n" + + " ^^^\n" + + "The method foo(Object) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236242); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 parameterized type compatibility + public void test0246() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " class MX {\n" + + " }\n" + + " void foo() {\n" + + " MX> mx2 = new MX();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " MX> mx2 = new MX();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.MX to X.MX>\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " MX> mx2 = new MX();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 variation + public void test0247() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " void foo() {\n" + + " MX> mx2 = new MX(); // wrong\n" + + " MX> mx3 = new MX>(); // wrong\n" + + " MX> mx4 = new MX>(); // wrong\n" + + " MX mx5 = new MX(); // ok\n" + + " MX mx6 = new MX(); // ok\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " }\n" + + "}\n" + + "\n" + + "class MX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " MX> mx2 = new MX(); // wrong\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX to MX>\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " MX> mx2 = new MX(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " MX> mx3 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " MX> mx4 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " MX mx5 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " MX mx5 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 7)\n" + + " MX mx6 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 7)\n" + + " MX mx6 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 8)\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "10. ERROR in X.java (at line 8)\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "11. WARNING in X.java (at line 8)\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 9)\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "13. ERROR in X.java (at line 9)\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "14. WARNING in X.java (at line 9)\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70247 check type variable is bound during super type resolution + public void test0248() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X extends Vector>{}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends Vector>{}\n" + + " ^^^^^^\n" + + "The type X cannot extend or implement Vector>. A supertype may not specify any wildcard\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70247 variation + public void test0249() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X implements List>{}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X implements List>{}\n" + + " ^^^^\n" + + "The type X cannot extend or implement List>. A supertype may not specify any wildcard\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70295 Class is compatible with Class + public void test0250() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(Object o) {\n" + + " X.class.isAssignableFrom(o.getClass());\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69800 '? extends Object' is not compatible with A + public void test0251() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " static class A {\n" + + " }\n" + + " A test() throws Exception {\n" + + " Class clazz = null;\n" + + " return clazz.newInstance(); // ? extends Object\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return clazz.newInstance(); // ? extends Object\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? extends Object to X.A\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69799 NPE in foreach checkcast + // effective result may change depending upon + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=148241 + // ** + public void test0252() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set channel = channels.get(0);\n" + + " for (Iterator iter = channel.iterator(); iter.hasNext();) {\n" + + " Set element;\n" + + " element = (Set) iter.next();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Set channel = channels.get(0);\n" + + " ^^^^^^^^\n" + + "channels cannot be resolved\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " element = (Set) iter.next();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to Set\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70243 unsafe cast when wildcards + public void test0253() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List li= new ArrayList();\n" + + " List ls= li; \n" + + " List x2= (List)ls;//unsafe\n" + + " x2.add(new Float(1.0));\n" + + " \n" + + " Integer i= li.get(0);//ClassCastException!\n" + + " \n" + + " List ls2 = (List)ls;\n" + + " List ls3 = (List) li;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " List x2= (List)ls;//unsafe\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " List ls2 = (List)ls;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " List ls3 = (List) li;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70053 missing checkcast in string concatenation + public void test0254() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " System.out.print(\"S\" + x.a() + \"U\" + x.b().get(0) + \"C\" + x.a() + \"C\");\n" + + " System.out.println(new StringBuilder(\"E\").append(x.a()).append(\"S\").append(x.b().get(0)).append(\"S\").append(x.a()).append(\"!\")); \n" + + " }\n" + + " String a() { return \"\"; }\n" + + " List b() { \n" + + " ArrayList als = new ArrayList(1);\n" + + " als.add(a());\n" + + " return als;\n" + + " }\n" + + "}\n" + }, + "SUCCESS!"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69351 generic type cannot extend Throwable + public void test0255() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Throwable {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends Throwable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Throwable {\n" + + " ^^^^^^^^^\n" + + "The generic class X may not subclass java.lang.Throwable\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70616 - reference to binary Enum + public void test0256() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + "\n" + + " Enum ex = null;\n" + + " String s = ex.name();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Enum ex = null;\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type Enum\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70618 - reference to variable allowed in parameterized super type + public void test0257() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public abstract class M extends java.util.AbstractList {}\n" + + "}\n" + + "class Y extends T {}\n" + + "class Z {\n" + + " class M extends T {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " class Y extends T {}\n" + + " ^\n" + + "Cannot refer to the type parameter T as a supertype\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class M extends T {}\n" + + " ^\n" + + "Cannot refer to the type parameter T as a supertype\n" + + "----------\n"); + } + public void test0258() { + this.runConformTest( + new String[] { + "X.java", + "abstract class X implements java.util.Map {\n" + + " static abstract class M implements Entry {}\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70767 - NPE compiling code with explicit constructor invocation + public void test0259() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X(E e) {\n" + + " this();\n" + + " }\n" + + " \n" + + " X() {\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0260() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "}\n" + + "\n" + + "class XC extends X {\n" + + " class MXC extends MX {\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0261() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " X xi = (X) new X();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X xi = (X) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); + } + public void test0262() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " X xe = (X) new X();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X xe = (X) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n"); + } + public void test0263() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " XC xe = (XC) new X();\n" + + " }\n" + + "}\n" + + "class XC extends X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " XC xe = (XC) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to XC\n" + + "----------\n"); + } + public void test0264() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " XC xe = (XC) new X();\n" + + " }\n" + + "}\n" + + "class XC extends X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " XC xe = (XC) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to XC\n" + + "----------\n"); + } + public void test0265() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " XC xcu = (XC) new X();\n" + + " XC xcu1 = (XC) new X(); \n" + + " XC xcu2 = (XC) new X(); \n" + + " }\n" + + "}\n" + + "class XC extends X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " XC xcu = (XC) new X();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to XC\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " XC xcu1 = (XC) new X(); \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XC to XC\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " XC xcu2 = (XC) new X(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to XC\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " XC xcu2 = (XC) new X(); \n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + public void test0266() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " X xe = new X();\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0267() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(X xany) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0268() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " X[] foo() {\n" + + " ArrayList list = new ArrayList();\n" + + " return list.toArray(new X[list.size()]);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X[] foo() {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " ArrayList list = new ArrayList();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " ArrayList list = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to ArrayList\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " ArrayList list = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70975 - test compilation against binary generic method + public void test0269() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " U[] bar(U[] u) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " return null; }\n" + + "\n" + + " static String[] foo() {\n" + + " X xs = new X();\n" + + " return xs.bar(new String[0]);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String [] args) {\n" + + " X xs = new X();\n" + + " String[] s = xs.bar(new String[0]);\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70969 - lub(List, List) --> List + public void test0270() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public void test(boolean param) {\n" + + " ArrayList ls = (param) \n" + + " ? new ArrayList()\n" + + " : new ArrayList();\n" + + " \n" + + " X x = param ? new XY() : new XZ();\n" + + " XY y = (XY) new XZ();\n" + + " }\n" + + "}\n" + + "class XY extends X {}\n" + + "class XZ extends X {}\n" + }, + + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " XY y = (XY) new XZ();\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from XZ to XY\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - parameter bound > should be allowed + public void test0271() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - variation + public void test0272() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + "}\n" + + "\n" + + "class XY implements Cloneable {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - variation + public void test0273() { + this.runConformTest( + new String[] { + "X.java", + "public class X & Cloneable> {\n" + + "}\n" + + "\n" + + "class XY {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 + public void test0274() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " l.add(\"asdf\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method useList(List) of type Y has the same erasure as useList(List) of type X but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0275() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "Type safety: The return type List for useList(List) from the type Y needs unchecked conversion to conform to List from the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method useList(List) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " l.add(\"asdf\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0276() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public void useList(List l) {}\n" + + "}\n" + + "class Y extends X {\n" + + " public void useList(List l) {\n" + + " super.useList(l);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void useList(List l) {}\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void useList(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method useList(List) of type Y has the same erasure as useList(List) of type X but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0277() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public void useList(List l) {}\n" + + "}\n" + + "class Y extends X {\n" + + " public void useList(List l) {\n" + + " super.useList(l);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public void useList(List l) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method useList(List) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " super.useList(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0278() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public Class getDeclaringClass() { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public Class getDeclaringClass() { return null; }\n" + + "}\n" + + "interface I {\n" + + " public Class getDeclaringClass();\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69901 + public void test0279() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements ISomething {\n" + + " public Class getSomething() { return null; }\n" + + "}\n" + + "class Y {}\n" + + "interface ISomething {\n" + + " public Class getSomething();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Class getSomething() { return null; }\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public Class getSomething() { return null; }\n" + + " ^^^^^\n" + + "Type safety: The return type Class for getSomething() from the type X needs unchecked conversion to conform to Class from the type ISomething\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62822 + public void test0280() { + this.runConformTest( + new String[] { + "X.java", + "interface X, T2 extends Z> {}\n" + + "interface Y {}\n" + + "interface Z {}\n" + }, + ""); + } + public void test0281() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X, T2 extends Z> {}\n" + + "interface Y {}\n" + + "interface Z {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X, T2 extends Z> {}\n" + + " ^^\n" + + "Bound mismatch: The type T2 is not a valid substitute for the bounded parameter of the type Y\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " interface Y {}\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + } + public void test0282() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y.Member {}\n" + + "class Y { static class Member {} }\n" + }, + ""); + this.runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X extends p1.Y.Member {}\n" + + "class Y { static class Member {} }\n" + }, + ""); + } + public void test0283() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y.Missing {}\n" + + "class Y { static class Member {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y.Missing {}\n" + + " ^^^^^^^^^\n" + + "Y.Missing cannot be resolved to a type\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X extends Y.Missing {}\n" + + "class Y { static class Member {} }\n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public class X extends Y.Missing {}\n" + + " ^^^^^^^^^\n" + + "Y.Missing cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72083 + public void test0284() { + this.runConformTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A , T2 extends B> {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B , T4 extends B> {}\n" + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A , T2 extends A> {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B , T4 extends A> {}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73530 + public void test0285() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " public static void main(String[] args){\n" + + " Vector v = new Vector();\n" + + " Integer[] array1 = new Integer[5];\n" + + " array1[0] = new Integer(17);\n" + + " array1[1] = new Integer(42);\n" + + " v.add(array1);\n" + + " Integer twentyfour = v.get(0)[1]; // responsible for the crash\n" + + " System.out.println(twentyfour);\n" + + " }\n" + + "}" + }, + "42"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72644 + // TODO (philippe) we need a way to test these 2 methods & find them 'equivalent'... right isEquivalentTo return false + public void test0286() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(Class c) {return null;}\n" + + "}\n" + + "class Y extends X {\n" + + " T foo(Class c) {return null;}\n" + + "}" + }, + ""); + } + public void test0287() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public class A {\n" + + " \n" + + " public class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.A.B bs;\n" + + " ^^^^^\n" + + "The member type X.A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); + } + public void test0288() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class A {\n" + + " \n" + + " public static class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0289() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public class A {\n" + + " \n" + + " public class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.A.B bs;\n" + + " ^^^^^^^^^^^^^\n" + + "The member type X.A must be parameterized, since it is qualified with a parameterized type\n" + + "----------\n"); + } + public void test0290() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class A {\n" + + " \n" + + " public class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.A.B bs;\n" + + " ^^^^^^^^^^^^^\n" + + "The member type X.A cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n"); + } + // ensure bound check deals with supertype (and their enclosing type) + public void test0291() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "}\n" + + "class SX extends X.MX {\n" + + " SX(X x){\n" + + " x.super();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^^\n" + + "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " class MX {\n" + + " ^^^^^^^^\n" + + "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " class SX extends X.MX {\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Thread is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " class SX extends X.MX {\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type X.MX\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " SX(X x){\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + public void test0292() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y.Z zo;\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73837 + public void test0293() { + this.runConformTest( + new String[] { + "B.java", //--------------------------- + "public class B{\n"+ + " public B(X str,D dValue){}\n"+ + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" , + "D.java", //--------------------------- + "public class D{}\n", + }, + "SUCCESS"); + + this.runConformTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + " public B test(Z zValue,D yValue){ return new B(zValue,yValue); }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73837 variation + public void test0294() { + this.runConformTest( + new String[] { + "B.java", //--------------------------- + "public class B{\n"+ + " public B(X str, B dValue){}\n"+ + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" , + "D.java", //--------------------------- + "public class D{}\n", + }, + "SUCCESS"); + + this.runNegativeTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + " public B test(Z zValue,B> yValue){ return new B(zValue,yValue); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in C.java (at line 2)\n" + + " public B test(Z zValue,B> yValue){ return new B(zValue,yValue); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor B(Z, B>) is undefined\n" + + "----------\n", + null, + false, // do not flush output + null); + } + // non-static method #start() gets its type substituted when accessed through raw type + public void test0295() { + this.runNegativeTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + "\n" + + " void bar() {\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " }\n" + + "}\n", + "B.java", //--------------------------- + "public class B{\n" + + " X get(B bx) { return null; }\n" + + " B> start() { return null; }\n" + + "}", + "D.java", //--------------------------- + "public class D{}\n", + }, + "----------\n" + + "1. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method get(B) belongs to the raw type B. References to generic type B should be parameterized\n" + + "----------\n" + + "2. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "4. ERROR in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^\n" + + "The method get(B) is undefined for the type Object\n" + + "----------\n" + + "5. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in B.java (at line 3)\n" + + " B> start() { return null; }\n" + + " ^\n" + + "D is a raw type. References to generic type D should be parameterized\n" + + "----------\n"); + } + // static method #start() gets its type does not get substituted when accessed through raw type + public void test0296() { + this.runNegativeTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + "\n" + + " void bar() {\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " }\n" + + "}\n", + "B.java", //--------------------------- + "public class B{\n" + + " X get(B bx) { return null; }\n" + + " static B> start() { return null; }\n" + + "}", + "D.java", //--------------------------- + "public class D{}\n", + }, + "----------\n" + + "1. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^\n" + + "The static method start() from the type B should be accessed in a static way\n" + + "----------\n" + + "2. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^\n" + + "The static method start() from the type B should be accessed in a static way\n" + + "----------\n" + + "4. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "5. ERROR in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^\n" + + "The method get(B) in the type B is not applicable for the arguments (B>)\n" + + "----------\n" + + "6. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^\n" + + "The static method start() from the type B should be accessed in a static way\n" + + "----------\n" + + "7. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in B.java (at line 3)\n" + + " static B> start() { return null; }\n" + + " ^\n" + + "D is a raw type. References to generic type D should be parameterized\n" + + "----------\n"); + } + public void test0297() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "import java.util.HashMap;\n" + + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map map = new HashMap();\n" + + " \n" + + " map.put(\"foo\", \"bar\");\n" + + " \n" + + " // Error reported on the following line\n" + + " Iterator> i = map.entrySet().iterator();\n" + + " while (i.hasNext()) {\n" + + " Map.Entry entry = i.next();\n" + + " System.out.println(entry.getKey() + \", \" + entry.getValue());\n" + + " }\n" + + " }\n" + + "}\n", + }, + "foo, bar"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72644 + public void test0298() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X implements Map {\n" + + " private Map backingMap;\n" + + " public int size() { return 0; }\n" + + " public boolean isEmpty() { return false; }\n" + + " public boolean containsKey(Object key) { return false; }\n" + + " public boolean containsValue(Object value) { return false; }\n" + + " public V get(Object key) { return null; }\n" + + " public V put(String key, V value) { return null; }\n" + + " public V remove(Object key) { return null; }\n" + + " public void clear() { }\n" + + " public Set keySet() { return null; }\n" + + " public Collection values() { return null; }\n" + + " public void putAll(Map t) { }\n" + + " public Set> entrySet() {\n" + + " return this.backingMap.entrySet();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X implements Map {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Map.putAll(Map)\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " public void putAll(Map t) { }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method putAll(Map) of type X has the same erasure as putAll(Map) of type Map but does not override it\n" + + "----------\n"); + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public abstract class X implements java.util.Map {\n" + + " public void putAll(java.util.Map t) { }\n" + + "}\n", + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "public abstract class X implements java.util.Map {\n" + + " public void putAll(java.util.Map t) { }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void putAll(java.util.Map t) { }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method putAll(Map) of type X has the same erasure as putAll(Map) of type Map but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74244 + public void test0299() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(Boolean.class == boolean.class ? \"FAILED\" : \"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74119 + public void test0300() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " static interface I extends Visitible {\n" + + " }\n" + + " static interface Visitible {\n" + + " void acceptVisitor(Visitor visitor);\n" + + " }\n" + + " static interface Visitor {\n" + + " void visit(T t);\n" + + " }\n" + + " static class C implements I {\n" + + " public void acceptVisitor(Visitor visitor) {\n" + + " visitor.visit(this); // should be ok\n" + + " visitor.visit((I) this); // (2) This is a workaround\n" + + " }\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74320: check no complaint for unused private method + public void test0301() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "import java.util.List;\n" + + "public class X {\n" + + " public static void reverse(List list) { \n" + + " rev(list);\n" + + " }\n" + + " private static void rev(List list) {\n" + + " }\n" + + " Zork foo() {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Zork foo() {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74514 + public void test0302() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "import java.util.ArrayList;\n" + + "import java.util.Enumeration;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public void test02() {\n" + + " List l= new ArrayList();\n" + + " for (Iterator i= l.iterator(); i.next(); ) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " for (Iterator i= l.iterator(); i.next(); ) {\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from String to boolean\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74544 + public void test0303() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Y ys = new Y();\n" + + " Y.Member m = ys.new Member();\n" + + " m.foo();\n" + + " } \n" + + " }\n" + + " class Y {\n" + + " class Member {\n" + + " void foo(){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " }\n" + + "\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74592 + public void test0304() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {}\n" + + "class Y extends X {}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74420 + public void test0305() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " T x;\n" + + " T foo(U u) { return u; }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74096 + public void test0306() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "public class X> {\n" + + " static int CONSTANT = 1;\n" + + " private int i = 1;\n" + + " private int i() {return i;}\n" + + " private static class M { private static int j = 2; }\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " public int foo2(T t) { return T.CONSTANT; }\n" + // why is this allowed? + "}\n" + + "class Y extends Zork {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " ^^^^^\n" + + "Read access to enclosing field X.M.j is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + // 5: operator + cannot be applied to int,.j + // 5: incompatible type, found : , required: int + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72583 + public void test0307() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " static T foo(T t1, T t2){ return t1; }\n" + + " public static void main(String[] args) {\n" + + " IX s = null;\n" + + " foo(new Object(), s);\n" + + " }\n" + + "}\n" + + "interface IX {}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73696 + public void test0308() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class Member {}\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " p.X.Member m;\n" + + " p.X.Member ms = m;\n" + + "}\n" + }); + } + public void test0309() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class Member {\n" + + " class Sub {}\n" + + " }\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " p.X.Member.Sub s;\n" + + " p.X.Member.Sub es = s;\n" + + "}\n" + }); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75156 - should report name clash + public void test0310() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X extends X2 {\n" + + " void foo(List lx) { }\n" + + "}\n" + + "\n" + + "abstract class X2 {\n" + + " void foo(List lo) { }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(List lx) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75156 variation - should report name clash and ambiguity + public void test0311() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X extends X2 {\n" + + " void foo(List lx) { }\n" + + " void bar(){\n" + + " this.foo((List)null);\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class X2 {\n" + + " void foo(List lo) { }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(List lx) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " this.foo((List)null);\n" + + " ^^^\n" + + "The method foo(List) is ambiguous for the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " this.foo((List)null);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); + } + // 75156 variation - should report name clash instead of final method override + public void test0312() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X extends X2 {\n" + + " void foo(List lx) { }\n" + + "}\n" + + "\n" + + "abstract class X2 {\n" + + " final void foo(List lo) { }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(List lx) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73963 + public void test0313() { + this.runConformTest( + new String[] { + "X.java", + "import java.net.Inet6Address;\n" + + "import java.net.InetAddress;\n" + + "import java.util.AbstractList;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "void takeAbstract(AbstractList arg) { }\n" + + "\n" + + "void takeList(List arg) { }\n" + + "\n" + + "void construct() {\n" + + " AbstractList a= new ArrayList();\n" + + " takeAbstract(a);\n" + + " takeAbstract(new ArrayList()); // a inlined: error 1:\n" + + "//The method takeAbstract(AbstractList) in the type A\n" + + "// is not applicable for the arguments (ArrayList)\n" + + " \n" + + " List l= new ArrayList();\n" + + " takeList(l);\n" + + " takeList(new ArrayList()); // l inlined: ok\n" + + " \n" + + " ArrayList aw= new ArrayList();\n" + + " takeAbstract(aw);\n" + + " takeAbstract(new ArrayList()); // aw inlined: error 2:\n" + + "//The method takeAbstract(AbstractList) in the type A\n" + + "// is not applicable for the arguments (ArrayList)\n" + + "\n" + + " takeList(aw);\n" + + " takeList(new ArrayList()); //aw inlined: ok\n" + + "}\n" + + "}" + }, + ""); + } + public void test0314() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class XMember {}\n" + + "\n" + + " // with toplevel element type\n" + + " void foo() {\n" + + " XIter> iter = fooSet().iterator();\n" + + " }\n" + + " XSet> fooSet() { return null; }\n" + + "\n" + + " // with member element type\n" + + " void bar() {\n" + + " XIter> iter = barSet().iterator();\n" + + " }\n" + + " XSet> barSet() { return null; }\n" + + "\n" + + " \n" + + "}\n" + + "\n" + + "class XSet {\n" + + " XIter iterator() { return null; }\n" + + "}\n" + + "class XIter {\n" + + "}\n" + + "class XElement {\n" + + "}\n" + }, + ""); + } + public void test0315() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class XMember {}\n" + + "\n" + + " // with member element type\n" + + " void bar() {\n" + + " XIter> iter = barSet().iterator();\n" + + " }\n" + + " XSet> barSet() { return null; }\n" + + "\n" + + " \n" + + "}\n" + + "\n" + + "class XSet {\n" + + " XIter iterator() { return null; }\n" + + "}\n" + + "class XIter {\n" + + "}\n" + + "class XElement {\n" + + "}\n" + }, + ""); + } + public void test0316() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " E element() { return null; }\n" + + " \n" + + " void bar(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " void foo(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " void baz(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " abstract class XM implements List, Runnable {}\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 19)\n" + + " abstract class XM implements List, Runnable {}\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0317() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " E element() { return null; }\n" + + " \n" + + " void foo(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " void baz(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " interface XI extends Runnable {}\n" + + " \n" + + " class XM {\n" + + " void foo() {}\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75548 + public void test0318() { + this.runConformTest( + new String[] { + "MyCache.java", + "class Cache {\n" + + "}\n" + + "\n" + + "class Index {\n" + + " public Index(Cache parentCache) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class MyCache extends Cache {\n" + + " class AnIndex extends Index {\n" + + " public AnIndex() {\n" + + " super(MyCache.this); // <-- Eclipse cannot find the constructor!\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76729 + public void test0319() { + this.runConformTest( + new String[] { + "test/Test1.java", + "package test;\n" + + "\n" + + "class A\n" + + "{}\n" + + "\n" + + "class B\n" + + "{}\n" + + "\n" + + "public interface Test1, D extends A>\n" + + "{}\n" + + "\n" + + "class AbstractA extends A {};\n" + + "class AbstractB extends B {};\n" + + "\n" + + "class Test2 implements Test1\n" + + "{}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74032 + public void test0320() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "class TestElement extends ArrayList implements Runnable {\n" + + " public void run() {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public X(E element) {\n" + + " element.run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new TestElement());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74032 - variation with wildcard + public void test0321() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "class TestElement extends ArrayList implements Runnable {\n" + + " static final long serialVersionUID = 1l;\n" + + " public void run() {\n" + + " // empty\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " E element;\n" + + " public X(E element) {\n" + + " this.element = element;\n" + + " element.run();\n" + + " }\n" + + " public X(X x) {\n" + + " x.element.run();\n" + // should be able to bind to #run() + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new TestElement());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75134 + public void test0322() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "\n" + + " A v2;\n" + + " X(A a) { v2 = a; }\n" + + " \n" + + " void func() {\n" + + " List> l = new ArrayList>();\n" + + " }\n" + + "\n" + + " class B {\n" + + " T v1;\n" + + " B(T b) { v1 = b; }\n" + + " }\n" + + " \n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76359 - also check warnings for raw conversion + public void test0323() { + this.runNegativeTest( + new String[] { + "X.java", + "class G {\n" + + " class Member {}\n" + + "}\n" + + "public class X {\n" + + " G g = new G();\n" + + " G.Member gsm = g.new Member();\n" + + " G.Member gm = null;\n" + + " G.Member gtm = gm;\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " G g = new G();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type G needs unchecked conversion to conform to G\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " G g = new G();\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " G.Member gm = null;\n" + + " ^^^^^^^^\n" + + "G.Member is a raw type. References to generic type G.Member should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " G.Member gtm = gm;\n" + + " ^^\n" + + "Type safety: The expression of type G.Member needs unchecked conversion to conform to G.Member\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72998 + public void test0324() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " private TreeNode root;\n" + + "\n" + + " public void doSomething() {\n" + + " for (TreeNode child : root.children()) {\n" + + " // root.children() should work??\n" + + " }\n" + + " }\n" + + "\n" + + " public void doSomethingElse() {\n" + + " for (Iterator> it = root.children().iterator(); it.hasNext();) {\n" + + " // this also should work\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class TreeNode {\n" + + " private Set> children;\n" + + " \n" + + " public Set> children() {\n" + + " return children;\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0325() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo1() {\n" + + " X.Item i = new X().new Item();\n" + + " }\n" + + " void foo2() {\n" + + " X.Item j = new X.Item();\n" + // allowed per grammar + " }\n" + + " void foo3() {\n" + + " X.Item k = new X.Item();\n" + + " }\n" + + " static void foo4() {\n" + + " X.Item k = new X.Item();\n" + + " }\n" + + " class Item {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X.Item i = new X().new Item();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Item to X.Item\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.Item j = new X.Item();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Item using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^^^^^^^\n" + + "No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instance of type X (e.g. x.new A() where x is an instance of X).\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75400 + public void test0326() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public I.A foo() {\n" + + " return a;\n" + + " }\n" + + "} \n" + + "interface I {\n" + + " A a = new A();\n" + + " class A {\n" + + " }\n" + + "}\n" + + "\n" + + "class XM {\n" + + " A a = new A();\n" + + " class A {\n" + + " }\n" + + "} \n" + + "\n" + + "class XMSub extends XM {\n" + + " public XM.A foo() {\n" + + " return a;\n" + + " }\n" + + "} \n" + + "\n" + }, + ""); + } + // wildcard captures bound and variable superinterfaces + public void test0327() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " \n" + + " T element() { return null; }\n" + + " void baz(X x) {\n" + + " x.element().foo();\n" + + " x.element().bar();\n" + + " }\n" + + "}\n" + + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // wildcard captures bound and variable superinterfaces + public void test0328() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x1 = new X(new Foo());\n" + + " baz(x1);\n" + + " X x2 = new X(new Bar());\n" + + " baz(x2);\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class Foo implements IFoo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "class Bar implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " baz(x1);\n" + + " ^^^\n" + + "The method baz(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " X x2 = new X(new Bar());\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " X x2 = new X(new Bar());\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); + } + // wildcard captures bound and variable superinterfaces + public void test0329() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class FooBar implements IFoo, IBar {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "FOOBAR" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // wildcard captures bound superclass and variable superclass + public void test0330() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class Foo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n", + }, + "FOOBAR"); + } + // wildcard captures bound superclass and variable superclass + public void test0331() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class Foo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "FOOBAR" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // wildcard considers bound superclass or variable superclass + public void test0332() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + // captures Foo & IBar + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " baz(new X(new FooBar()));\n" + + " baz(new X(new Bar()));\n" + + " }\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "\n" + + "class Bar implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" + + "\n" + + "class Foo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " baz(new X(new Bar()));\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); + } + // receveir generic cast matches receiver type (not declaring class) + public void test0333() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { this.element = element; }\n" + + " T element() { return this.element; }\n" + + " public static void main(String[] args) {\n" + + " new X(new XB()).element().afoo();\n" + + " }\n" + + "}\n" + + "\n" + + "class XA {\n" + + " void afoo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class XB extends XA {\n" + + " void bfoo() {}\n" + + "}\n" , + }, + "SUCCESS"); + } + // check cannot allocate type parameters + public void test0334() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X() {\n" + + " new E();\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new E();\n" + + " ^\n" + + "Cannot instantiate the type E\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to the type parameter E as a supertype\n" + + "----------\n"); + } + // variation - check cannot allocate type parameters + public void test0335() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + // firstBound is class, still cannot be instantiated + " public X() {\n" + + " new E();\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type parameter E should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new E();\n" + + " ^\n" + + "Cannot instantiate the type E\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to the type parameter E as a supertype\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74669 + public void test0336() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IMyInterface {\n" + + "}\n" + + "class MyClass {\n" + + "\n" + + " public Type myMethod(Object obj, Class type) {\n" + + " return null;\n" + + " }\n" + + " public static Type myStaticMethod(Object obj, Class type) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public IMyInterface getThis() {\n" + + " if (true)\n" + + " return new MyClass().myMethod(this, IMyInterface.class);\n" + + " else\n" + + " return MyClass.myStaticMethod(this, IMyInterface.class);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public Type myMethod(Object obj, Class type) {\n" + + " ^^^^\n" + + "The type parameter Type is hiding the type Type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public Type myMethod(Object obj, Class type) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " public static Type myStaticMethod(Object obj, Class type) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " return new MyClass().myMethod(this, IMyInterface.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to IMyInterface\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " return new MyClass().myMethod(this, IMyInterface.class);\n" + + " ^^^^^^^\n" + + "MyClass is a raw type. References to generic type MyClass should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77078 + public void test0337() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " public void foo() {\n" + + " Vector objectVector = new Vector() {\n" + + " protected void bar() {\n" + + " baz(this); /* ERROR */\n" + + " }\n" + + " };\n" + + " baz(objectVector);\n" + + " baz(new Vector());\n" + + " }\n" + + " public void baz(Vector mysteryVector) { }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77052 + public void test0338() { + this.runConformTest( + new String[] { + "X.java", + "interface M { }\n" + + "\n" + + "class N { \n" + + " M> pni = null;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " N var1 = null;\n" + + "\n" + + " M> var2 = var1.pni;\n" + + " // Above line reports as error in Eclipse. \n" + + " // \"var2\" is underlined and the error message is: \n" + + " // Type mismatch: cannot convert from M> to M>\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77052 - variation + public void test0339() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "class X {\n" + + " static class Entry {}\n" + + " void foo() {\n" + + " Iterator> i = entrySet().iterator();\n" + + " }\n" + + " Set> entrySet() { return null; }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76313 + public void test0340() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T data;\n" + + " private X(T data){ this.data=data; }\n" + + " public static X createObject(S data){\n" + + " System.out.println(data);\n" + + " return new X(data);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X res=X.createObject(\"Hallo\");\n" + + " }\n" + + "}\n", + }, + "Hallo"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77118 + public void test0341() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object getItem() { return null; }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " public String getItem() { return null; }\n" + + "}\n", + "Z.java", + "public class Z extends X {\n" + + " public Comparable getItem() { return null; }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77142 - check no raw unsafe warning is issued when accessing generic method from raw type + public void test0342() { + this.runNegativeTest( + new String[] { + "Test.java", + "class MyClass {\n" + + " \n" + + " private T thing;\n" + + " { Zork z; }\n" + + " \n" + + " public\n" + + " MyClass(T thing) {\n" + + " this.thing = thing;\n" + + " }\n" + + " \n" + + " public static MyClass\n" + + " factoryMakeMyClass(U thing) {\n" + + " return new MyClass(thing);\n" + + " }\n" + + "}\n" + + "\n" + + "class External {\n" + + "\n" + + " public static MyClass\n" + + " factoryMakeMyClass(U thing) {\n" + + " return new MyClass(thing);\n" + + " }\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " public static void\n" + + " test()\n" + + " {\n" + + " // No problem with this line:\n" + + " MyClass foo = External.factoryMakeMyClass(\"hi\");\n" + + " \n" + + " // This line gives me an error:\n" + + " // Type mismatch: cannot convert from MyClass to MyClass\n" + + " MyClass bar = MyClass.factoryMakeMyClass(\"hi\");\n" + + " MyClass bar2 = MyClass.factoryMakeMyClass(\"hi\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " { Zork z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74588 + public void test0343() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T m;\n" + + "\n" + + " class Y {\n" + + " void test() {\n" + + " new Y() {\n" + + " void test() {\n" + + " System.out.println(X.this.m);\n" + + " }\n" + + " }.test();\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + ""); + } + // checking scenario where generic type and method share the same type parameter name + public void test0344() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public abstract class X {\n" + + " \n" + + " public abstract T bar(T t);\n" + + "\n" + + " static void foo(X x) {\n" + + " x.bar(null);\n" + + " \n" + + " class R implements Runnable {\n" + + " public void run() {\n" + + " }\n" + + " }\n" + + " X xr = new X(){ \n" + + " public T bar(T t) { \n" + + " return t; \n" + + " }\n" + + " };\n" + + " IOException e = xr.bar(new IOException());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract T bar(T t);\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " static void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " x.bar(null);\n" + + " ^^^\n" + + "The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " X xr = new X(){ \n" + + " ^^^^^^\n" + + "The type new X(){} must implement the inherited abstract method X.bar(T)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 + public void test0345() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " X1 o1 = new X1();\n" + + " ((J)o1).get();\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 implements I {\n" + + " public X1 get() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I extends J {\n" + + " I get();\n" + + "}\n" + + "\n" + + "interface J {\n" + + " J get();\n" + + "}", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 + public void test0346() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " X1 o1 = new X1(new Integer(4));\n" + + " System.out.println(o1.get().t);\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 implements I {\n" + + " T t;\n" + + " X1(T arg) {\n" + + " t = arg;\n" + + " }\n" + + " public X1 get() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I extends J {\n" + + " I get();\n" + + "}\n" + + "\n" + + "interface J {\n" + + " J get();\n" + + "}" + , + }, + "4"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 + public void test0347() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " X1 o = new X1(new Integer(4));\n" + + " System.out.println(o.get().t);\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 implements I {\n" + + " T t;\n" + + " X1(T arg) {\n" + + " t = arg;\n" + + " }\n" + + " public X1 get() {\n" + + " return this;\n" + + " }\n" + + "} \n" + + "\n" + + "interface I extends K, L {\n" + + " I get();\n" + + "}\n" + + "\n" + + "interface J {\n" + + " J get();\n" + + "}\n" + + "\n" + + "interface K extends J {\n" + + "}\n" + + "\n" + + "interface L {\n" + + " K get();\n" + + "}", + }, + "4"); + } + // checking scenario where generic type and method share the same type parameter name + public void test0348() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public abstract class X {\n" + + " public abstract T bar(T t);\n" + + " static void foo(X x) {\n" + + " x.bar(null);\n" + + " class R implements Runnable {\n" + + " public void run() {}\n" + + " }\n" + + " X xr = new X(){ \n" + + " public T bar(T t) { return t; }\n" + + " };\n" + + " IOException e = xr.bar(new IOException());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public abstract T bar(T t);\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " static void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " x.bar(null);\n" + + " ^^^\n" + + "The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " public T bar(T t) { return t; }\n" + + " ^^^^^^^^\n" + + "The method bar(T) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236242); + } + // test wildcard compatibilities + public void test0349() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " static void foo(X out, X1 in) {\n" + + " out.element = in.element;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class X1{\n" + + " U element;\n" + + "}\n", + }, + "SUCCESS"); + } + // test wildcard compatibilities + public void test0350() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " static void foo(X out, X1 in) {\n" + + " out.element = in.element;\n" + + " }\n" + + "}\n" + + "class X1{\n" + + " U element;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " out.element = in.element;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? to capture#1-of ?\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75328 + public void test0351() { + this.runConformTest( + new String[] { + "X.java", + "interface Intf, I extends Comparable> { \n" + + " public void f(Intf val);\n" + + "}\n" + + "\n" + + "public class X , P extends Comparable> implements Intf {\n" + + "\n" + + " public void f(Intf val) { } \n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77051 + public void test0352() { + this.runConformTest( + new String[] { + "X.java", + "interface C { }\n" + + "interface PC extends C { } \n" + + "interface PO { \n" + + " C proc1();\n" + + " C proc2();\n" + + " C proc3();\n" + + "}\n" + + "abstract class X implements PO {\n" + + " public C proc1() { return result1; }\n" + + " private final PC result1 = null;\n" + + " public C proc2() { return result2; }\n" + + " private final PC result2 = null;\n" + + " public C proc3() { return result3; }\n" + + " private final PC result3 = null;\n" + + "}\n", + }, + ""); + } + public void test0353() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " T foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + ""); + } + public void test0354() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " S foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + ""); + } + public void test0355() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " S foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " S foo(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " S foo(Class c) { return null; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + public void test0356() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " T foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo(Class c) { return null; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + public void test0357() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " T foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo(Class c) { return null; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76720 + public void test0358() { + this.runConformTest( + new String[] { + "MyClass.java", + "public class MyClass {}\n", + "A.java", + "public interface A {}\n", + "B.java", + "public interface B extends A {}\n", + "C.java", + "public class C implements B {}\n", // compile against sources + "D.java", + "public class D implements A{}\n", // compile against sources + }, + ""); + // compile against generated binaries + this.runConformTest( + new String[] { + "C.java", + "public class C implements B {}\n", + "D.java", + "public class D implements A{}\n", + }, + "", + null, + false, + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76790 + public void test0359() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " class List1 extends LinkedList {};\n" + + " public static void main (String[] args) {\n" + + " Map> x = new HashMap>();\n" + + " Map> m = new HashMap>();\n" + + " }\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76786 + public void test0360() { + this.runConformTest( + new String[] { + "Test.java", + "import java.lang.Comparable;\n" + + "public class Test {\n" + + " private static final class X implements Comparable> {\n" + + " public int compareTo(X arg0) { return 0; }\n" + + " };\n" + + " private static class Y {};\n" + + " private static final class Z extends Y implements Comparable> {\n" + + " public int compareTo(Z arg0) { return 0; }\n" + + " };\n" + + " public static void doSomething(Comparable a, Comparable b) {}\n" + + " public static void doSomethingElse(Z a, Z b) {\n" + + " doSomething(a, b);\n" + + " }\n" + + " private static final class W { };\n" + + " public static void main(String[] args) {\n" + + " doSomething(new X(), new X());\n" + + " doSomething(new Z(), new Z());\n" + + " doSomethingElse(new Z(), new Z());\n" + + " doSomethingElse(new Z(), new Z());\n" + + " // The next line won\'t compile. It\'s the generic, String>(), new Z, String>());\n" + + " }\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75525 + public void test0361() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.AbstractSet;\n" + + "import java.util.Iterator;\n" + + "import java.util.Map.Entry;\n" + + "public class Test extends AbstractSet> {\n" + + " public Iterator> iterator() {\n" + + " return new Iterator>() {\n" + + " public boolean hasNext() {return false;}\n" + + " public Entry next() {return null;}\n" + + " public void remove() {} \n" + + " };\n" + + " }\n" + + " public int size() {return 0;}\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72643 + public void test0362() { + Map customOptions= getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Test {\n" + + " public void a() {\n" + + " List list1 = new ArrayList();\n" + + " List list2 = new ArrayList();\n" + + " compare(list1, list2);\n" + + " }\n" + + " private void compare(List list1, List list2) {\n" + + " // do some comparing logic...\n" + + " }\n" + + "}\n" + + "\n" + }, + "", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76434 + public void test0363() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " Set> m_values;\n" + + " X(Map values) {\n" + + " m_values = values.entrySet();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " m_values = values.entrySet();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Set> to Set>\n" + + "----------\n"); + } + // check param type equivalences + public void test0364() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " \n" + + " void bar1(MX> mxcs, MX> mxco) {\n" + + " mxco = mxcs;\n" + // wrong + " }\n" + + " void bar1(Class cs, Class co) {\n" + + " co = cs;\n" + // ok + " }\n" + + " \n" + + "}\n" + + "class MX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " mxco = mxcs;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n"); + } + // check param type equivalences + public void test0365() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " class MX {\n" + + " }\n" + + " \n" + + " MX createMX() { return new MX(); }\n" + + "\n" + + " void foo(X x, MX mx) {\n" + + " mx = x.createMX();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " mx = x.createMX();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.MX to X.MX\n" + + "----------\n"); + } + // check param type equivalences + public void test0366() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " \n" + + " void foo1(MX> target, MX value) {\n" + + " target= value; // foo1 - wrong\n" + + " }\n" + + " void foo2(MX> target, MX> value) {\n" + + " target= value; // foo2 - wrong\n" + + " }\n" + + " void foo3(MX> target, MX> value) {\n" + + " target= value; // foo3 - wrong\n" + + " }\n" + + " void foo4(MX> target, MX> value) {\n" + + " target= value; // foo4 - wrong\n" + + " }\n" + + " void foo5(MX target, MX value) {\n" + + " target= value; // foo5\n" + + " }\n" + + " void foo6(MX target, MX value) {\n" + + " target= value; // foo6\n" + + " }\n" + + " void foo7(MX> target, MX> value) {\n" + + " target= value; // foo7 - wrong\n" + + " }\n" + + " void foo8(MX> target, MX> value) {\n" + + " target= value; // foo8 - wrong\n" + + " }\n" + + " void foo9(MX target, MX value) {\n" + + " target= value; // foo9\n" + + " }\n" + + " void foo10(MX target, MX value) {\n" + + " target= value; // foo10 - wrong\n" + + " }\n" + + " void foo11(MX target, MX value) {\n" + + " target= value; // foo11 - wrong\n" + + " }\n" + + " void foo12(MX target, MX value) {\n" + + " target= value; // foo12\n" + + " }\n" + + "}\n" + + "\n" + + "class MX {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo1(MX> target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " target= value; // foo1 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX to MX>\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " target= value; // foo2 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " target= value; // foo3 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " target= value; // foo4 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " void foo5(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " void foo5(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 18)\n" + + " void foo6(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 18)\n" + + " void foo6(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 21)\n" + + " void foo7(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 21)\n" + + " void foo7(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "12. ERROR in X.java (at line 22)\n" + + " target= value; // foo7 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "13. WARNING in X.java (at line 24)\n" + + " void foo8(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 24)\n" + + " void foo8(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "15. ERROR in X.java (at line 25)\n" + + " target= value; // foo8 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "16. ERROR in X.java (at line 31)\n" + + " target= value; // foo10 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX to MX\n" + + "----------\n" + + "17. ERROR in X.java (at line 34)\n" + + " target= value; // foo11 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX to MX\n" + + "----------\n"); + } + // check param type equivalences + public void test0367() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " \n" + + " void foo1(MX target, MX> value) {\n" + + " target= value; // foo1\n" + + " }\n" + + " void foo2(MX target, MX> value) {\n" + + " target= value; // foo2\n" + + " }\n" + + " void foo3(MX target, MX> value) {\n" + + " target= value; // foo3\n" + + " }\n" + + "}\n" + + "\n" + + "class MX {\n" + + "}\n" , + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo1(MX target, MX> value) {\n" + + " ^^\n" + + "MX is a raw type. References to generic type MX should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " void foo3(MX target, MX> value) {\n" + + " ^^\n" + + "MX is a raw type. References to generic type MX should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " target= value; // foo3\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX\n" + + "----------\n"); + } + // check param type equivalences + public void test0368() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " static class MX {\n" + + " }\n" + + " \n" + + " MX createMX() { return new MX(); }\n" + + "\n" + + " void foo(X x, MX mx) {\n" + + " mx = x.createMX();\n" + + " }\n" + + "}\n" , + }, + ""); + } + // bound check for Enum + public void test0369() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " > T foo(T t) { return null; }\n" + + "}\n", + }, + ""); + } + // decoding raw binary type + public void test0370() { + this.runConformTest( + new String[] { + "p/B.java", + "package p;\n" + + "import java.util.Map;\n" + + "public class B {\n" + + " public static Map foo(byte[] byteArray, Object o, Class c) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + ""); + + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "import p.B;\n" + + "\n" + + "public class X {\n" + + " {\n" + + " Map map = B.foo(null, null, null);\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + } + // X is not compatible with X + public void test0371() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(XC target, XC value) {\n" + + " target = value;\n" + + " }\n" + + "}\n" + + "class XC {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " target = value;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from XC to XC\n" + + "----------\n"); + } + public void test0372() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void foo(Iterator> iter) {\n" + + " new XA.MXA(iter.next());\n" + + " }\n" + + "}\n" + + "class XA {\n" + + " static class MXA implements Entry {\n" + + " MXA(Entry e) {\n" + + " }\n" + + " public K getKey() {\n" + + " return null;\n" + + " }\n" + + " public V getValue() {\n" + + " return null;\n" + + " }\n" + + " public V setValue(V value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); + } + public void test0373() { + this.runConformTest( + new String[] { + "XA.java", + "import java.util.Map.Entry;\n" + + "\n" + + "public class XA {\n" + + " static class MXA implements Entry {\n" + + " MXA(Entry e) {\n" + + " }\n" + + " public K getKey() {\n" + + " return null;\n" + + " }\n" + + " public V getValue() {\n" + + " return null;\n" + + " }\n" + + " public V setValue(V value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); + // compile against binaries + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void foo(Iterator> iter) {\n" + + " new XA.MXA(iter.next());\n" + + " }\n" + + "}\n" , + }, + "", + null, + false, + null); + } + // wildcard with no upper bound uses type variable as upper bound + public void test0374() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo1(X target, X value) {\n" + + " target = value; // foo1\n" + + " }\n" + + " void foo2(X target, X value) {\n" + + " target = value; // foo2\n" + + " } \n" + + "}\n", + }, + ""); + } + public void test0375() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo1(X target, X value) {\n" + + " target = value; // foo1\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " target = value; // foo1\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); + } + public void test0376() { + this.runConformTest( + new String[] { + "XA.java", + "import java.util.Map.Entry;\n" + + "\n" + + "public class XA {\n" + + " XA self() { return this; } \n" + + " static class MXA implements Entry {\n" + + " MXA(Entry e) {\n" + + " }\n" + + " public K getKey() {\n" + + " return null;\n" + + " }\n" + + " public V getValue() {\n" + + " return null;\n" + + " }\n" + + " public V setValue(V value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); + // compile against binaries + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void foo(Iterator> iter) {\n" + + " new XA.MXA(iter.next());\n" + + " }\n" + + "}\n" , + }, + "", + null, + false, + null); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76601 + public void test0377() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static void main (String[] args) {\n" + + " final String val = (args == null||args.length==0 ? \"SUCC\" : args[0]) + \"ESS\";\n" + + " class AllegedBoundMismatch> {\n" + + " String field = val;\n" + + " }\n" + + " System.out.println(new Object() {\n" + + " AllegedBoundMismatch> trial = new AllegedBoundMismatch>();\n" + + " }.trial.field);\n" + + " }\n" + + "}\n" + + "class Q {}\n" + + "interface SubI extends SuperI> {}\n" + + "interface SuperI {}" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76219 + public void test0378() { + this.runConformTest( + new String[] { + "BB.java", + "interface AA> { \n" + + " public boolean m(AA that); \n" + + " public Z z(); \n" + + " public boolean b(); \n" + + "}\n" + + "abstract class BB> implements AA { \n" + + " public boolean m(AA wht) { return wht.z().b(); } \n" + + "}\n"} + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71612 + public void test0379() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.AbstractSet;\n" + + "import java.util.Iterator;\n" + + "public class Test extends AbstractSet{\n" + + " public static void main(String[] args) {\n" + + " Test t=new Test();\n" + + " t.add(null);\n" + + " }\n" + + " public boolean add(Runnable run) {\n" + + " System.out.println(\"success\");\n" + + " return true;\n" + + " }\n" + + " public Iterator iterator() {return null;}\n" + + " public int size() {return 0;}\n" + + "}" + } + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77327 + public void test0380() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "public class Test {\n" + + " List wsn= null; // Contravariance\n" + + " List wsi= wsn; // should work!\n" + + "}\n" + } + ); + } + + public void test0381() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + + "class Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Class s) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + + "class Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Class s) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + public void test0382() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y implements I {}\n" + + "interface I { void foo(Class s); }\n" + + "class Y { void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Class)\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I {}\n" + + "interface I { void foo(Class s); }\n" + + "class Y { void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n"); + } + public void test0383() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y implements I { public void foo(Class s) {} }\n" + + "interface I { void foo(Class s); }\n" + + "class Y { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I { public void foo(Class s) {} }\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Class)\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I { public void foo(Class s) {} }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 1)\n" + + " public class X extends Y implements I { public void foo(Class s) {} }\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method foo(Class) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + /* + X.java:1: X is not abstract and does not override abstract method foo(java.lang.Class) in I + public class X extends Y implements I { public void foo(Class s) {} } + ^ + */ + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y implements I {}\n" + + "interface I { void foo(Class s); }\n" + + "class Y { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Class)\n" + + "----------\n"); + /* + X.java:1: X is not abstract and does not override abstract method foo(java.lang.Class) in I + public class X extends Y implements I {} + ^ + */ + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I {}\n" + // NOTE: X is abstract + "interface I { void foo(Class s); }\n" + + "class Y { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n"); + /* + X.java:1: name clash: foo(java.lang.Class) in Y and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other + public abstract class X extends Y implements I {} + ^ + */ + } + public void test0384a() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " java.util.List foo3(java.util.List t) { return t; }\n" + + " Class foo4() { return null; }\n" + + " Class[] foo5() { return null; }\n" + + "}\n" + + "class Y {\n" + + " java.util.List foo3(java.util.List t) { return t; }\n" + + " Class foo4() { return null; }\n" + + " Class[] foo5() { return null; }\n" + + "}\n" + }, + ""); + } + public void test0384b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " @Override Class foo() { return null; }\n" + + " @Override Class[] foo2() { return null; }\n" + + "}\n" + + "class Y {\n" + + " Class foo() { return null; }\n" + + " Class[] foo2() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Override Class foo() { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with Y.foo()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @Override Class[] foo2() { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with Y.foo2()\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77496 + public void test0385() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface IDoubles { List getList(); }\n" + + "class A implements IDoubles {\n" + + " public List getList() { return null; }\n" + + "}\n" + + "class B {\n" + + " public List getList() { return null; }\n" + + "}\n" + + "class C extends B implements IDoubles {\n" + + " void use() { List l= getList(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public List getList() { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with IDoubles.getList()\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class C extends B implements IDoubles {\n" + + " ^\n" + + "The return type is incompatible with IDoubles.getList(), B.getList()\n" + + "----------\n"); + /* + X.java:3: A is not abstract and does not override abstract method getList() in IDoubles + class A implements IDoubles { + ^ + X.java:4: getList() in A cannot implement getList() in IDoubles; attempting to use incompatible return type + found : java.util.List + required: java.util.List + public List getList() { return null; } + ^ + X.java:9: C is not abstract and does not override abstract method getList() in IDoubles + class C extends B implements IDoubles { + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77325 + public void test0386() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private U u;\n" + + " private V v;\n" + + " public X(U u,V v) { this.u= u; this.v= v; }\n" + + " public R getU() { return (R)u; } // Warning\n" + + " public R getV() { return (R)v; } // Warning\n" + + " Object o;\n" + + " public T getT() { return (T)o; } // Warning\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public R getU() { return (R)u; } // Warning\n" + + " ^^^^\n" + + "Type safety: Unchecked cast from U to R\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public R getV() { return (R)v; } // Warning\n" + + " ^^^^\n" + + "Type safety: Unchecked cast from V to R\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " public T getT() { return (T)o; } // Warning\n" + + " ^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - generic varargs method + public void test0387() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X\n" + + "{\n" + + "\n" + + " public boolean test1()\n" + + " {\n" + + " test2(\"test\", null, 0);\n" + + " }\n" + + "\n" + + " public List test2(final List list, final String... strings)\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " test2(\"test\", null, 0);\n" + + " ^^^^^\n" + + "The method test2(List, String...) in the type X is not applicable for the arguments (String, null, int)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0388() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X\n" + + "{\n" + + "\n" + + " public boolean test01()\n" + + " {\n" + + " test02(null, null, \"test\");\n" + + " return false;\n" + + " }\n" + + "\n" + + " public List test02(final List list, final String... strings)\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0389() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " String s = foo(\"hello\");\n" + + " return s != null;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0390() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " String s = foo(null, \"hello\");\n" + + " return s != null;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0391() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " String[] s = foo(null, new String[]{ \"hello\" });\n" + + " return s != null;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String[] s = foo(null, new String[]{ \"hello\" });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from String to String[]\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0392() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " foo(null, \"hello\");\n" + // no inference on expected type + " return true;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78049 - chech invalid array initializer + public void test0393() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " foo(null, \"hello\");\n" + // no inference on expected type + " return true;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78027 + public void test0394() { + this.runConformTest( + new String[] { + "X.java", + "public class X \n" + + "{\n" + + "}\n" + + "\n" + + "interface ITest\n" + + "{ \n" + + "}\n" + + "\n" + + "abstract class Test implements ITest\n" + + "{\n" + + " protected Manager m_manager;\n" + + " \n" + + " public ITest get()\n" + + " {\n" + + " return m_manager.getById(getClass(), new Integer(1));\n" + + " }\n" + + " \n" + + " public static class Manager\n" + + " {\n" + + " public > T getById(Class cls, Integer id)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74119 - variation + public void test0395() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " \n" + + " void foo(X xnpe) {\n" + + " xnpe.element = new java.io.IOException();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " xnpe.element = new java.io.IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from IOException to capture#1-of ? super NullPointerException\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78139 - downcast generic method inference + public void test0396() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "\n" + + "public class X\n" + + "{\n" + + " public static List emptyList() {\n" + + " return new ArrayList();\n" + + " }\n" + + " public static Collection emptyCollection() {\n" + + " return new ArrayList();\n" + + " }\n" + + " public static Iterable emptyIterable() {\n" + + " return new ArrayList();\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " // generic inference using expected lhs type: T --> String\n" + + " final List lL = emptyList(); // 1\n" + + " \n" + + " // generic inference using expected cast type: T --> String\n" + + " final Collection cL = (Collection)emptyList(); // 2\n" + + " \n" + + " // generic inference using expected cast type: T --> String\n" + + " final Iterable iL = (Iterable)emptyList(); // 3\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Collection cC = emptyCollection(); // 4\n" + + " \n" + + " // generic inference using expected cast type: T --> String\n" + + " final Iterable iC = (Iterable)emptyCollection(); // 5\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Iterable iI = emptyIterable(); // 6\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Collection cL2 = emptyList(); // 7\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Iterable iC2 = emptyCollection(); // 8\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " final Collection cL = (Collection)emptyList(); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to Collection\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " final Iterable iL = (Iterable)emptyList(); // 3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to Iterable\n" + + "----------\n" + + "3. ERROR in X.java (at line 31)\n" + + " final Iterable iC = (Iterable)emptyCollection(); // 5\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Collection to Iterable\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76132 + public void test0397() { + this.runNegativeTest( + new String[] { + "X.java", + "interface K1 { \n" + + " public void kk(K1 x); \n" + + "} \n" + + " \n" + + "class K2 implements K1 { \n" + + " public void kk(K1 y) { \n" + + " System.out.println(\"K2::kk(\" + y.toString() + \")\"); \n" + + " } \n" + + "} \n" + + " \n" + + "// --------------------------------------------------- \n" + + " \n" + + "interface L1 { \n" + + " public void ll(L1 a); \n" + + "} \n" + + " \n" + + "class L2 implements L1 { \n" + + " public void ll(L1 b) { \n" + + " ll2(b); \n" + + " } \n" + + " \n" + + " private void ll2(L1 c) { \n" + + " System.out.println(\"L2::ll2(\" + c.toString() + \")\"); \n" + + " } \n" + + "} \n" + + " \n" + + "// --------------------------------------------------- \n" + + " \n" + + "interface M1 { \n" + + " public void mm(M1 p); \n" + + "} \n" + + " \n" + + "class M2 implements M1 { \n" + + " public void mm(M1 q) { \n" + + " System.out.println(\"M2::mm(\" + q.toString() + \")\"); \n" + + " } \n" + + "} \n" + + " \n" + + "// =================================================== \n" + + " \n" + + "class XX { public String toString() { return \"XX\"; } } \n" + + "class YY extends XX { public String toString() { return \"YY\"; } } \n" + + "class ZZ extends YY { public String toString() { return \"ZZ\"; } } \n" + + " \n" + + "// --------------------------------------------------- \n" + + " \n" + + "public class X { \n" + + " public static void main(String arg[]) { \n" + + " goK(new K2()); \n" + + " goL(new L2()); \n" + + " goM(new M2()); \n" + + " } \n" + + " \n" + + " \n" + + " public static void goK(K1 k) { \n" + + " // k.kk(new K2()); // Would fail \n" + + " k.kk(new K2()); \n" + + " k.kk(new K2()); \n" + + " } \n" + + " \n" + + " \n" + + " public static void goL(L1 l) { \n" + + " // l.ll(new L2()); // Would fail \n" + + " l.ll(new L2()); \n" + + " l.ll(new L2()); \n" + + " } \n" + + " \n" + + " \n" + + " public static void goM(M1 m) { \n" + + " // m.mm(new M2()); // Would fail \n" + + " m.mm(new M2()); \n" + + " m.mm(new M2()); \n" + + " } \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 33)\n" + + " class M2 implements M1 { \n" + + " ^^\n" + + "The type M2 must implement the inherited abstract method M1.mm(M1)\n" + + "----------\n" + + "2. ERROR in X.java (at line 34)\n" + + " public void mm(M1 q) { \n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method mm(M1) of type M2 has the same erasure as mm(M1) of type M1 but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 41)\n" + + " class XX { public String toString() { return \"XX\"; } } \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type XX should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "4. WARNING in X.java (at line 42)\n" + + " class YY extends XX { public String toString() { return \"YY\"; } } \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type YY should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "5. WARNING in X.java (at line 43)\n" + + " class ZZ extends YY { public String toString() { return \"ZZ\"; } } \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type ZZ should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + } + // cannot allocate parameterized type with wildcards + public void test0398() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(){\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " new X();\n" + + " new X(){};\n" + + " new X(){};\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X();\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " new X();\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " new X(){};\n" + + " ^\n" + + "The type new X(){} cannot extend or implement X. A supertype may not specify any wildcard\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " new X(){};\n" + + " ^\n" + + "The type new X(){} cannot extend or implement X. A supertype may not specify any wildcard\n" + + "----------\n"); + } + + public void test0399() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 AX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P foo() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X>(AX) is undefined\n" + + "----------\n"); + } + + public void test0400() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(X xt){\n" + + " this.t = xt.t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new X>(null));\n" + + " }\n" + + "}\n" + + "class AX

{\n" + + " P foo() { return null; }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X>(new X>(null));\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X>(new X>(null));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X>(X>) is undefined\n" + + "----------\n"); + } + + // legal to allocate/inherit from a type with wildcards, as long as non direct arguments + public void test0401() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " new X>();\n" + + " new X>();\n" + + " new X>(){};\n" + + " new X>(){};\n" + + " }\n" + + "}", + }, + ""); + } + + // legal to inherit from a type with wildcards, as long as non direct arguments + public void test0402() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y> {\n" + + "}\n" + + "class Y {}", + }, + ""); + } + // check cast between generic types + public void test0403() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(X> xs) {\n" + + " X> x = (X>) xs;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X> x = (X>) xs;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X> to X>\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // check cast between generic types + public void test0404() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(X xs) {\n" + + " X x = (X) xs;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X x = (X) xs;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // check cast between generic types + public void test0405() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(X> xs) {\n" + + " X> x = (X>) xs;\n" + + " }\n" + + " void bar(X xs) {\n" + + " X x = (X) xs;\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X> x = (X>) xs;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X> to X>\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X x = (X) xs;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n"); + } + + public void test0406() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements M {\n" + + " abstract M other();\n" + + " public S> entrySet() {\n" + + " return other().entrySet();\n" + + " }\n" + + "}\n" + + "interface M {\n" + + " interface E { }\n" + + " S> entrySet();\n" + + "}\n" + + "interface S {}", + }, + ""); + } + + public void test0407() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements M {\n" + + " abstract M other();\n" + + " public S> entrySet() {\n" + // qualified M.E... + " return other().entrySet();\n" + + " }\n" + + "}\n" + + "interface M {\n" + + " interface E { }\n" + + " S> entrySet();\n" + + "}\n" + + "interface S {}", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78008 + public void test0408() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public Integer[] getTypes() {\n" + + " List list = new ArrayList();\n" + + " return list == null \n" + + " ? new Integer[0] \n" + + " : list.toArray(new Integer[list.size()]);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class clazz = null;\n" + + " try {\n" + + " clazz = Class.forName(\"X\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78008 + public void test0409() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public Number getTypes() {\n" + + " List list = new ArrayList();\n" + + " return list == null \n" + + " ? Float.valueOf(0)\n" + + " : list.get(0);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class clazz = null;\n" + + " try {\n" + + " clazz = Class.forName(\"X\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74178 + public void test0410() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + "public void write(List list) {\n" + + " \n" + + " list.add(new RuntimeException()); // works\n" + + " list.add(new IllegalMonitorStateException()); // works\n" + + " Exception exc = new Exception();\n" + + " list.add(exc); // works\n" + + " list.add(new Object()); // should fail\n" + + " list.add(new Throwable()); // should fail\n" + + " list.add(new Exception()); // works\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " list.add(new Object()); // should fail\n" + + " ^^^\n" + + "The method add(capture#4-of ? super Exception) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " list.add(new Throwable()); // should fail\n" + + " ^^^\n" + + "The method add(capture#5-of ? super Exception) in the type List is not applicable for the arguments (Throwable)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78015 + public void test0411() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void m1(T t);\n" + + " void m2(T t);\n" + + "}\n" + + "\n" + + "class A {};\n" + + "\n" + + "class B implements I {\n" + + " public void m1(A a) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void m2(A a) {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " m(new B());\n" + + " }\n" + + "\n" + + " public static void m(I x) {\n" + + " x.m1(null);\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78467 + public void test0412() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static T first(T... args) {\n" + + " return args[0];\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " if (false) { \n" + + " String s = first(); \n" + + " int i; \n" + + " i++; \n" + + " }\n" + + " System.out.println(first(\"SUCCESS\", \"List\"));\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78467 - variation + public void test0412a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "\n" + + " public static T first(T... args) {\n" + + " return args[0];\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " if (false) { \n" + + " List ls = first(); \n" + + " int i; \n" + + " i++; \n" + + " }\n" + + " System.out.println(first(\"SUCCESS\", \"List\"));\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List ls = first(); \n" + + " ^^^^^^^\n" + + "Type safety : A generic array of List is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0413() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class TLM {\n" + + " }\n" + + " TLM getMap(TL t) {\n" + + " return t.tls;\n" + + " }\n" + + " static TLM createInheritedMap(TLM parentMap) {\n" + + " return new TLM();\n" + + " } \n" + + "}\n" + + "\n" + + "class TL {\n" + + " X.TLM tls = null;\n" + + "}", + }, + ""); + } + + public void test0414() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l, C c) {\n" + + " bar(l, c);\n" + + " }\n" + + " void bar(L l, C c) { \n" + + " } \n" + + "}\n" + + "class C {}\n" + + "class L {}", + }, + ""); + } + + public void test0415() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public S> foo(HM hm) {\n" + + " return C.bar(hm).foo();\n" + + " }\n" + + "}\n" + + "class C {\n" + + " public static M bar(M m) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class S {\n" + + "}\n" + + "abstract class HM implements M{\n" + + "}\n" + + "interface M {\n" + + " static class E {}\n" + + " S> foo(); \n" + + "}", + }, + ""); + } + + public void test0416() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public S> foo(HM hm) {\n" + + " M m = C.bar(hm);\n" + + " if (false) return m.foo();\n" + + " return C.bar(hm).foo();\n" + + " }\n" + + "}\n" + + "class C {\n" + + " public static M bar(M m) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class S {\n" + + "}\n" + + "abstract class HM implements M{\n" + + "}\n" + + "interface M {\n" + + " static class E {}\n" + + " S> foo(); \n" + + "}", + }, + ""); + } + + public void test0417() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x) {\n" + + " X xs = foo(x).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0418() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0419() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0420() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78863 + public void test0421() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class Test\n" + + "{\n" + + " protected Map, List> m_test\n" + + " = new HashMap, List>();\n" + + "}\n", + "Test2.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class Test2 extends Test\n" + + "{\n" + + " public Map, List> test()\n" + + " {\n" + + " return m_test;\n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78704 + public void test0422() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo() {\n" + + " return new X();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return new X();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " return new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + + public void test0423() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static T bar() {\n" + + " return null;\n" + + " }\n" + + " static U foo() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " bar();\n" + + " foo();\n" + + " }\n" + + "\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " foo();\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo() of type X is not applicable for the arguments (). The inferred type X is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } + + public void test0424() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " B b = foo(new B());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n", + }, + ""); + } + + // check tiebreak eliminates related generic methods which are less specific + public void test0425() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " static void m(E e) { System.out.println(\"A:\"+e.getClass()); }\n" + + " static void m(F f) throws Exception { System.out.println(\"B:\"+f.getClass()); }\n" + + " static void m(G g) throws IOException { System.out.println(\"C:\"+g.getClass()); }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " m(new A());\n" + + " m(new B());\n" + + " m(new C());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " m(new B());\n" + + " ^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " m(new C());\n" + + " ^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); + } + + // check inferred return types are truly based on arguments, and not on parameter erasures + public void test0426() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static E m(E e) { System.out.print(\"[A:\"+e.getClass()+\"]\"); return e; }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A a = m(new A());\n" + + " B b = m(new B());\n" + + " C c = m(new C());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n", + }, + "[A:class A][A:class B][A:class C]"); + } + + // check inferred return types are truly based on arguments, and not on parameter erasures + public void test0427() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static E m(E e, E... e2) { System.out.print(\"[A:\"+e.getClass()+\"]\"); return e; }\n" + + " static F m(F f, F... f2) { System.out.print(\"[B:\"+f.getClass()+\"]\"); return f; }\n" + + " static G m(G g, G... g2) { System.out.print(\"[C:\"+g.getClass()+\"]\"); return g; }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A a = m(new A(), new A());\n" + + " B b = m(new B(), new B());\n" + + " C c = m(new C(), new C());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n", + }, + "[A:class A][B:class B][C:class C]"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79390 + public void test0428() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " public static void foo() {\n" + + " class A {\n" + + " T t = null;\n" + + " T get() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + " A a = new A() {\n" + + " @Override\n" + + " Long get() {\n" + + " return new Long(5);\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429() { + this.runConformTest( + new String[] { + "X1.java", + "class X1 > {}\n" + + "abstract class Y implements Comparable {}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429a() { + this.runConformTest( + new String[] { + "X2.java", + "class X2 > {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429b() { + this.runConformTest( + new String[] { + "X3.java", + "class X3 > {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429c() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X4.java", + "class X4 & Comparable> {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X4.java (at line 1)\n" + + " class X4 & Comparable> {}\n" + + " ^^^^^^^^^^\n" + + "Duplicate bound Comparable\n" + + "----------\n", + // no complaints about duplicates if they are both parameterized with same args + // but you cannot extend Comparable & Comparable so we'll report an error + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429d() { + this.runNegativeTest( + new String[] { + "X5.java", + "class X5 > {}\n" + + "abstract class Y implements Comparable {}", + }, + "----------\n" + + "1. ERROR in X5.java (at line 1)\n" + + " class X5 > {}\n" + + " ^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X5.java (at line 1)\n" + + " class X5 > {}\n" + + " ^^\n" + + "X5 is a raw type. References to generic type X5 should be parameterized\n" + + "----------\n" + // Comparable cannot be inherited with different arguments: and + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429e() { + this.runNegativeTest( + new String[] { + "X6.java", + "class X6 > {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "----------\n" + + "1. ERROR in X6.java (at line 1)\n" + + " class X6 > {}\n" + + " ^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X6.java (at line 1)\n" + + " class X6 > {}\n" + + " ^^\n" + + "X6 is a raw type. References to generic type X6 should be parameterized\n" + + "----------\n" + // Comparable cannot be inherited with different arguments: and + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429f() { + this.runNegativeTest( + new String[] { + "X7.java", + "class X7 & Comparable> {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "----------\n" + + "1. ERROR in X7.java (at line 1)\n" + + " class X7 & Comparable> {}\n" + + " ^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X7.java (at line 1)\n" + + " class X7 & Comparable> {}\n" + + " ^^\n" + + "X7 is a raw type. References to generic type X7 should be parameterized\n" + + "----------\n" + // Comparable cannot be inherited with different arguments: and + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429g() { + this.runNegativeTest(new String[] { + "X.java", + "interface I {}\n" + + "\n" + + "class A implements I, I {}\n" + + "public class X & I> {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class A implements I, I {}\n" + + " ^\n" + + "Duplicate interface I for the type A\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public class X & I> {\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public class X & I> {\n" + + " ^\n" + + "Duplicate bound I\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79797 + public void test0430() { + this.runConformTest( + new String[] { + "p/MMM.java", + "package p;\n" + + "public interface MMM< F extends MMM, G extends NNN> { } \n", + "p/NNN.java", + "package p;\n" + + "public interface NNN { } \n", + }, + ""); + + this.runConformTest( + new String[] { + "X.java", + "import p.MMM;\n" + + "import p.NNN;\n" + + "\n" + + "interface RRR< A extends MMM, B extends NNN> {}\n" + + "\n" + + "class J1 implements MMM { }\n" + + "class J2 implements NNN { }\n" + + "\n" + + "class J3 implements RRR {} \n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " J3 thing = null;\n" + + " }\n" + + "}\n", + }, + "", + null, + false, // do not flush output + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79891 + public void test0431() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Element {\n" + + " }\n" + + " public X() {\n" + + " Element[] eArray = new Element[10];\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Element[] eArray = new Element[10];\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X.Element\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79891 + public void test0432() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class Element {\n" + + " }\n" + + " public X() {\n" + + " Element[] eArray = new Element[10];\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80144 + public void test0433() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Alpha<\n" + + " A1 extends Alpha, \n" + + " B1 extends Beta> {\n" + + "}\n" + + "interface Beta<\n" + + " A2 extends Alpha, \n" + + " B2 extends Beta> {\n" + + "}\n" + + "interface Phi<\n" + + " A3 extends Alpha, \n" + + " B3 extends Beta> {\n" + + " \n" + + " public void latinize(A3 s);\n" + + "}\n" + + "\n" + + "public class X<\n" + + " A extends Alpha, \n" + + " B extends Beta, \n" + + " P extends Phi> extends ArrayList

implements Phi {\n" + + " \n" + + " public final void latinize(A a) {\n" + + " frenchify(this, a); // (X, A)\n" + + " }\n" + + " // -----------------------------------------------------------------\n" + + " public static final , BB extends Beta> \n" + + " void frenchify(Collection< ? extends Phi> phis, AA aa) {\n" + + " for (final Phi phi : phis)\n" + + " phi.latinize(aa);\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80083 + public void test0434() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X\n" + + "{\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " ArrayList l = new ArrayList();\n" + + " l.add(\"x\");\n" + + " String s = \"\";\n" + + " s += l.get(0); // X\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80765 + public void test0435() { + this.runNegativeTest( + new String[] { + "Test.java",//=============================== + "import java.lang.reflect.InvocationTargetException;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "import orders.DiscreteOrder;\n" + + "import orders.impl.IntegerOrder;\n" + + "import orders.impl.IntegerOrder2;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public static void main(String[] args) throws SecurityException,\n" + + " NoSuchMethodException, IllegalArgumentException,\n" + + " IllegalAccessException {\n" + + " Test test = new Test();\n" + + "\n" + + " for (String method : new String[] { \"test01\", \"test02\", \"test03\", \"test04\" }) {\n" + + " Method m = test.getClass().getMethod(method);\n" + + " try {\n" + + " m.invoke(test);\n" + + " System.out.print(\"*** \" + m + \": success\");\n" + + " } catch (InvocationTargetException e) {\n" + + " System.out.print(\"*** \" + m + \": failed, stacktrace follows\");\n" + + " e.getCause().printStackTrace(System.out);\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public void test01() { // works\n" + + " new IntegerOrder().next(new Integer(0)); // works\n" + + " }\n" + + "\n" + + " public void test02() { // doesn\'t work\n" + + " final DiscreteOrder order = new IntegerOrder();\n" + + " order.next(new Integer(0));\n" + + " }\n" + + "\n" + + " public void test03() { // works\n" + + " new IntegerOrder2().next(new Integer(0)); // works\n" + + " }\n" + + "\n" + + " public void test04() { // doesn\'t work\n" + + " final DiscreteOrder order = new IntegerOrder2();\n" + + " order.next(new Integer(0));\n" + + " }\n" + + "}\n", + "orders/DiscreteOrder.java",//=============================== + "package orders;\n" + + "public interface DiscreteOrder> {\n" + + " /**\n" + + " * @return The element immediately before element in the\n" + + " * discrete ordered space.\n" + + " */\n" + + " public E previous(E element);\n" + + " /**\n" + + " * @return The element immediately after element in the\n" + + " * discrete ordered space.\n" + + " */\n" + + " public E next(E element);\n" + + "}\n", + "orders/impl/IntegerOrder.java",//=============================== + "package orders.impl;\n" + + "import orders.DiscreteOrder;\n" + + "\n" + + "public class IntegerOrder implements DiscreteOrder {\n" + + "\n" + + " public IntegerOrder() {\n" + + " super();\n" + + " }\n" + + "\n" + + " public Integer previous(Integer arg0) {\n" + + " return new Integer(arg0.intValue() - 1);\n" + + " }\n" + + "\n" + + " public Integer next(Integer arg0) {\n" + + " return new Integer(arg0.intValue() + 1);\n" + + " }\n" + + "}\n", + "orders/impl/IntegerOrder2.java",//=============================== + "package orders.impl;\n" + + "\n" + + "\n" + + "public class IntegerOrder2 extends IntegerOrder {\n" + + "\n" + + " public IntegerOrder2() {\n" + + " super();\n" + + " }\n" + + "\n" + + " public Comparable previous(Comparable arg0) {\n" + + " return previous((Integer) arg0);\n" + + " }\n" + + "\n" + + " public Comparable next(Comparable arg0) {\n" + + " return next((Integer) arg0);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in orders\\impl\\IntegerOrder2.java (at line 10)\n" + + " public Comparable previous(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in orders\\impl\\IntegerOrder2.java (at line 10)\n" + + " public Comparable previous(Comparable arg0) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method previous(Comparable) of type IntegerOrder2 has the same erasure as previous(E) of type DiscreteOrder but does not override it\n" + + "----------\n" + + "3. WARNING in orders\\impl\\IntegerOrder2.java (at line 10)\n" + + " public Comparable previous(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in orders\\impl\\IntegerOrder2.java (at line 14)\n" + + " public Comparable next(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "5. ERROR in orders\\impl\\IntegerOrder2.java (at line 14)\n" + + " public Comparable next(Comparable arg0) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method next(Comparable) of type IntegerOrder2 has the same erasure as next(E) of type DiscreteOrder but does not override it\n" + + "----------\n" + + "6. WARNING in orders\\impl\\IntegerOrder2.java (at line 14)\n" + + " public Comparable next(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + // "*** public void Test.test01(): success*** public void Test.test02(): success*** public void Test.test03(): success*** public void Test.test04(): success" + // name clash: next(java.lang.Comparable) in orders.impl.IntegerOrder2 and next(E) in orders.DiscreteOrder have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80028 + public void test0436() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " Number n= new Integer(1);\n" + + " X x = new X();\n" + + " x.m(n);\n" + + " x.m(new Integer(2));\n" + + " Y y= new Y();\n" + + " y.m(n);\n" + + " y.m(new Integer(2));\n" + + " }\n" + + "}\n", + "X.java", + "class X {\n" + + " public void m(Number num) { System.out.print(\"X.m(Number) = \" + num + ','); }\n" + + " public void m(T t) { System.out.print(\"X.m(T) = \" + t + ','); }\n" + + "}\n", + "Y.java", + "class Y extends X {\n" + + " public void m(Number num) { System.out.print(\"Y.m(Number) = \" + num + ','); }\n" + + "}\n", + }, + "X.m(Number) = 1,X.m(Number) = 2,Y.m(Number) = 1,Y.m(Number) = 2,"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80028 + public void test0437() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " Number n= new Integer(1);\n" + + " X x = new X();\n" + + " x.m(n);\n" + + " x.m(new Integer(2));\n" + + " Y y= new Y();\n" + + " y.m(n);\n" + + " y.m(new Integer(2));\n" + + " }\n" + + "}\n", + "X.java", + "class X {\n" + + " public void m(Number num) { System.out.print(\"X.m(Number) = \" + num + ','); }\n" + + " public void m(T t) { System.out.print(\"X.m(T) = \" + t + ','); }\n" + + "}\n", + "Y.java", + "class Y extends X {\n" + + " public void m(Number num) { System.out.print(\"Y.m(Number) = \" + num + ','); }\n" + + "}\n", + }, + "X.m(Number) = 1,X.m(Number) = 2,Y.m(Number) = 1,Y.m(Number) = 2,"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78591 + public void test0438() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " Zork z;\n" + + " List list;\n" + + " void add(Object abs) {\n" + + " list.add((T) list.get(0)); // checked cast\n" + + " list.add((T) abs); // unchecked cast\n" + + " }\n" + + " void bar(List other) {\n" + + " list.add((T) other.get(0)); // checked cast\n" + + " }\n" + + " void baz(List other) {\n" + + " list.add((T) other.get(0)); // unchecked cast\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " list.add((T) list.get(0)); // checked cast\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from T to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " list.add((T) abs); // unchecked cast\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " list.add((T) other.get(0)); // checked cast\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from capture#1-of ? extends T to T\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " list.add((T) other.get(0)); // unchecked cast\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from capture#2-of ? super T to T\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78592 + public void test0439() { + this.runNegativeTest( + new String[] { + "X.java", + "class Node {\n" + + "}\n" + + "class Composite {\n" + + "}\n" + + "class Concrete extends Composite {\n" + + "}\n" + + "public class X {\n" + + " Composite comp = new Concrete(); // unchecked cast\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " class Concrete extends Composite {\n" + + " ^^^^^^^^^\n" + + "Composite is a raw type. References to generic type Composite should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " Composite comp = new Concrete(); // unchecked cast\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Concrete needs unchecked conversion to conform to Composite\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0440() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " public void foo(X xt) {\n" + + " U u = (U) xt;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " U u = (U) xt;\n" + + " ^^^^^^\n" + + "Type safety: Unchecked cast from X to U\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0441() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T[] array;\n" + + " X(int s) {\n" + + " array = (T[]) new Number[s]; // Unnecessary cast from Number[] to T[]\n" + + " array = new Number[s]; // Type mismatch: cannot convert from Number[] to T[]\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " array = (T[]) new Number[s]; // Unnecessary cast from Number[] to T[]\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Number[] to T[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " array = new Number[s]; // Type mismatch: cannot convert from Number[] to T[]\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Number[] to T[]\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82053 + public void test0442() { + this.runConformTest( + new String[] { + "X.java", + "class Foo {\n" + + " public interface Model {\n" + + " }\n" + + " public interface View {\n" + + " M getTarget() ;\n" + + " }\n" + + "}\n" + + "class Bar {\n" + + " public interface Model extends Foo.Model {\n" + + " }\n" + + " public interface View extends Foo.View {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void baz() {\n" + + " Bar.View bv = null ;\n" + + " Bar.Model m = bv.getTarget() ;\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81757 + public void test0443() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "public class X implements Iterator {\n" + + " public boolean hasNext() { return false; }\n" + + " public String next() { return null; }\n" + + " public void remove() {}\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81824 + public void test0444() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I, I {}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements I, I {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78810 + public void test0445() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public abstract Object getProperty(final Object src, final String name);\n" + + " Zork z;\n" + + " public T getTheProperty(final Object src, final String name)\n" + + " {\n" + + " final T val = (T) getProperty(src, name); // this gives erroneous cast warning\n" + + " return val;\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " final T val = (T) getProperty(src, name); // this gives erroneous cast warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 + public void test0446() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { }\n" + + "\n" + + " void method() {\n" + + " X.Inner a= new X().new Inner();\n" + + " Inner b= new X().new Inner();\n" + + " Inner c= new Inner();\n" + + " // OK\n" + + "\n" + + " X.Inner d= new X.Inner();\n" + + " //eclipse: OK\n" + + " //other: error: \'(\' or \'[\' expected\n" + + "\n" + + " X.Inner e= new X().new Inner();\n" + + " X.Inner f= new Inner();\n" + + " e= b;\n" + + " f= c;\n" + + " //other: OK\n" + + " //eclipse: Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "\n" + + " }\n" + + "}\n" + + "\n" + + "class External {\n" + + " void m() {\n" + + " X.Inner x= new X().new Inner();\n" + + " // OK\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X.Inner d= new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236243); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0447() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { }\n" + + "\n" + + " void method() {\n" + + " X.Inner d1 = new X.Inner();\n" + + " X.Inner d2 = new X.Inner();\n" + + " X.Inner d3 = new X.Inner();\n" + + " d1 = d2;\n" + + " d2 = d1;\n" + + " d1 = d3;\n" + + " d3 = d1;\n" + + " d2 = d3;\n" + + " d3 = d2;\n" + + "\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X.Inner d1 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " X.Inner d2 = new X.Inner();\n" + + " ^^^^^^^\n" + + "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X.Inner d2 = new X.Inner();\n" + + " ^^^^^^^\n" + + "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " X.Inner d3 = new X.Inner();\n" + + " ^^^^^^^\n" + + "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " X.Inner d3 = new X.Inner();\n" + + " ^^^^^^^\n" + + "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " d1 = d2;\n" + + " ^^\n" + + "Type safety: The expression of type X.Inner needs unchecked conversion to conform to X.Inner\n" + + "----------\n" + + "7. ERROR in X.java (at line 10)\n" + + " d1 = d3;\n" + + " ^^\n" + + "Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "----------\n" + + "8. ERROR in X.java (at line 11)\n" + + " d3 = d1;\n" + + " ^^\n" + + "Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "----------\n" + + "9. WARNING in X.java (at line 13)\n" + + " d3 = d2;\n" + + " ^^\n" + + "Type safety: The expression of type X.Inner needs unchecked conversion to conform to X.Inner\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0448() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Inner { }\n" + + "\n" + + " void method() {\n" + + " X.Inner d = new X.Inner(); \n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0448a() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " class Y {}\n" + + " X.Y[] tab = new X.Y[] {};\n" + + "}" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); + } + + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0449() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { \n" + + " }\n" + + "\n" + + " void method() {\n" + + " X.Inner d4 = new X.Inner();\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^\n" + + "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0450() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Inner { \n" + + " }\n" + + "\n" + + " void method() {\n" + + " X.Inner d4 = new X.Inner();\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "The member type X.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "The member type X.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0451() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { \n" + + " }\n" + + "\n" + + " void method() {\n" + + " X.Inner d4 = new X.Inner() {};\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner() {};\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236243); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82187 + public void test0452() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public > S test01(S param){\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " \n" + + " public void test02() {\n" + + " test01(new Vector());\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().test02();\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82250 + public void test0453() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {}\n" + + "interface I {}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Duplicate bound I\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82504 + public void test0454() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object[] objectArr;\n" + + " void foo(T t) {\n" + + " T x1= (T) objectArr;\n" + + " U x2= (U) objectArr;\n" + + " int[] x= (int[]) t;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " T x1= (T) objectArr;\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to T\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " U x2= (U) objectArr;\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from Object[] to U\n" + + "----------\n"); + } + + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81719 + public void test0455() { + this.runConformTest( + new String[] { + "AbstractTest.java", + "public abstract class AbstractTest {\n" + + " abstract void array(T[] a);\n" + + " abstract void type(T a);\n" + + " abstract T[] foo();\n" + + "}\n", + }, + ""); + + this.runConformTest( + new String[] { + "Test.java", + "public class Test extends AbstractTest {\n" + + " void array(T[] a) {}\n" + + " void type(T a) {}\n" + + " T[] foo() { return null; }\n" + + "}\n", + }, + "", + null, + false, // do not flush output + null); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81721 + public void test0456() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doTest(S[] a);\n" + + "}\n" + + "\n" + + "abstract class AbstractTest implements I {\n" + + " public void doTest(V[] a) {}\n" + + "}\n" + + "\n" + + "public class X extends AbstractTest {}\n", + }, + ""); + } + + public void test0457() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " void add(List l) { \n" + + " l.add(new X()); \n" + + " }\n" + + " void add2(List l) { \n" + + " l.add(new X()); \n" + + " }\n" + + " \n" + + " static void add3(List l, List l2) { \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List lx = null;\n" + + " List ls = null;\n" + + " add3(lx, ls);\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " l.add(new X()); \n" + + " ^^^\n" + + "The method add(capture#2-of ? extends X) in the type List is not applicable for the arguments (X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " add3(lx, ls);\n" + + " ^^^^\n" + + "The method add3(List, List) in the type X is not applicable for the arguments (List, List)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82243 + public void test0458() { + this.runNegativeTest( + new String[] { + "X.java", + "interface A{\n" + + " E getOne();\n" + + "}\n" + + "\n" + + "\n" + + "abstract class B implements A {\n" + + " Number getTwo() {\n" + + " return getOne(); // succeeds\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class C extends B {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(A a, B b, C c){\n" + + " Object o= a.getOne();\n" + + " Number n1= b.getOne(); // fails\n" + + " Number n2= b.getTwo(); // succeeds, but inlining fails\n" + + " Integer i = c.getOne(); // succeeds\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " void foo(A a, B b, C c){\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " void foo(A a, B b, C c){\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " Number n1= b.getOne(); // fails\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Number\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78027 - variation (check unchecked warnings) + public void test0459() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X \n" + + "{\n" + + "Zork z;\n" + + "}\n" + + "\n" + + "interface ITest\n" + + "{ \n" + + "}\n" + + "\n" + + "abstract class Test implements ITest\n" + + "{\n" + + " protected Manager m_manager;\n" + + " \n" + + " public ITest get()\n" + + " {\n" + + " return m_manager.getById(getClass(), new Integer(1));\n" + + " }\n" + + " \n" + + " public static class Manager\n" + + " {\n" + + " public > T getById(Class cls, Integer id)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " return m_manager.getById(getClass(), new Integer(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation getById(Class, Integer) of the generic method getById(Class, Integer) of type Test.Manager\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " return m_manager.getById(getClass(), new Integer(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type capture#1-of ? extends Test needs unchecked conversion to conform to ITest\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82439 + public void test0460() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public > S test(S param) {\n" + + " \n" + + " Class c = param.getClass(); // ok\n" + + " Class d = getClazz(); // ko\n" + + " return null;\n" + + " }\n" + + " Class getClazz() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "abstract class Z implements Collection {\n" + + " void foo() {\n" + + " Class c = getClass(); // ok\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " Class c = param.getClass(); // ok\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " Class d = getClazz(); // ko\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Class d = getClazz(); // ko\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " Class c = getClass(); // ok\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82844 + public void test0461() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^\n" + + "The array type int[] cannot be used as a type parameter bound\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79628 + public void test0462() { + this.runConformTest( + new String[] { + "PropertiedObject.java", + "interface PropertiedObject> {}\n" + + "interface Model extends PropertiedObject {}\n" + + "interface View extends PropertiedObject> {}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79144 + public void test0463() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Set;\n" + + "public class X {\n" + + " Zork z;\n" + + " public Set[] test() {\n" + + " Set[] sets = new Set[10];\n" + + " return sets;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Set[] sets = new Set[10];\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " return sets;\n" + + " ^^^^\n" + + "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79144 + public void test0464() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " public static void main(String[] args) {\n" + + " List[] nums = new List[] {Collections.singletonList(\"Uh oh\")};\n" + + " System.out.println(nums[0].get(0).intValue());\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " List[] nums = new List[] {Collections.singletonList(\"Uh oh\")};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List[] needs unchecked conversion to conform to List[]\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82547 + public void test0465() { + this.runNegativeTest( + new String[] { + "Cla.java", + "class Cla {\n" + + " T getT() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " void m() {\n" + + " String s= new Cla.getT();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Cla.java (at line 7)\n" + + " String s= new Cla.getT();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cla.getT cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83096 + public void test0466() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { }\n" + + " ^\n" + + "Duplicate type parameter A\n" + + "----------\n" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 + public void test0467() { + this.runConformTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " protected String s; \n" + + " protected String dosomething(){ return \"done\"; } \n" + + " protected class Bar {} \n" + + "} \n", + "test02/FooBar.java", + "package test02; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation + public void test0468() { + this.runConformTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " String s; \n" + + " String dosomething(){ return \"done\"; } \n" + + " class Bar {} \n" + + "} \n", + "test/FooBar.java", + "package test; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83083 + public void test0469() { + this.runConformTest( + new String[] { + "a/C.java", + "package a; \n" + + "import p.B; \n" + + "public class C extends B { \n" + + " public void foo(Object obj) {} \n" + + "} \n", + "p/B.java", + "package p; \n" + + "public class B extends A {} \n", + "p/A.java", + "package p; \n" + + "public class A { \n" + + " public void foo(E e) {} \n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "a/C.java", + "package a; \n" + + "import p.B; \n" + + "public class C extends B { \n" + + " public void foo(Object obj) {} \n" + + "} \n", + "p/A.java", + "package p; \n" + + "public class A { \n" + + " public void foo(E e) {} \n" + + "}\n", + }, + "", + null, + false, // do not flush output + null); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83225 + public void test0470() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static T choose(boolean b, T t1, T t2) {\n" + + " if (b)\n" + + " return t1;\n" + + " return t2;\n" + + " }\n" + + "\n" + + " public static void foo() {\n" + + " Comparable s1 = choose(true, \"string\", new Integer(1));\n" + + " Number s2 = choose(true, new Integer(1), new Float(2));\n" + + " Comparable s3 = choose(true, new Integer(1), new Float(2));\n" + + " Cloneable s4 = choose(true, new Integer(1), new Float(2));\n" + + " Cloneable s5 = choose(true, \"string\", new Integer(1));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Comparable s1 = choose(true, \"string\", new Integer(1));\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " Comparable s3 = choose(true, new Integer(1), new Float(2));\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " Cloneable s4 = choose(true, new Integer(1), new Float(2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Number&Comparable to Cloneable\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Cloneable s5 = choose(true, \"string\", new Integer(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object&Serializable&Comparable to Cloneable\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation + public void test0471() { + this.runNegativeTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " protected R s; \n" + + " protected R dosomething(){ return s; } \n" + + " protected class Bar {} \n" + + "} \n", + "test02/FooBar.java", + "package test02; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test02\\FooBar.java (at line 7)\n" + + " this.s = \"foo\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to R\n" + + "----------\n" ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation + public void test0472() { + this.runNegativeTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " private R s; \n" + + " private R dosomething(){ return s; } \n" + + " private class Bar {} \n" + + "} \n", + "test02/FooBar.java", + "package test02; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. WARNING in test\\Foo.java (at line 4)\n" + + " private R dosomething(){ return s; } \n" + + " ^^^^^^^^^^^^^\n" + + "The method dosomething() from the type Foo is never used locally\n" + + "----------\n" + + "2. WARNING in test\\Foo.java (at line 5)\n" + + " private class Bar {} \n" + + " ^^^\n" + + "The type Foo.Bar is never used locally\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test02\\FooBar.java (at line 6)\n" + + " f.s = \"foo\"; \n" + + " ^\n" + + "The field Foo.s is not visible\n" + + "----------\n" + + "2. ERROR in test02\\FooBar.java (at line 7)\n" + + " this.s = \"foo\";\n" + + " ^\n" + + "The field Foo.s is not visible\n" + + "----------\n" + + "3. ERROR in test02\\FooBar.java (at line 8)\n" + + " f.dosomething(); \n" + + " ^^^^^^^^^^^\n" + + "The method dosomething() from the type Foo is not visible\n" + + "----------\n" + + "4. ERROR in test02\\FooBar.java (at line 9)\n" + + " this.dosomething(); \n" + + " ^^^^^^^^^^^\n" + + "The method dosomething() from the type Foo is not visible\n" + + "----------\n" + + "5. ERROR in test02\\FooBar.java (at line 10)\n" + + " Bar b1; \n" + + " ^^^\n" + + "The type Bar is not visible\n" + + "----------\n" + + "6. ERROR in test02\\FooBar.java (at line 11)\n" + + " FooBar.Bar b2; \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The type FooBar.Bar is not visible\n" + + "----------\n" + + "7. ERROR in test02\\FooBar.java (at line 12)\n" + + " Foo.Bar b3; \n" + + " ^^^^^^^^^^^^^^^\n" + + "The type Foo.Bar is not visible\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 + public void test0473() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X\n" + + "{\n" + + " List itsList;\n" + + " B itsB;\n" + + " MyTyped itsTyped;\n" + + " \n" + + " \n" + + " public void test()\n" + + " {\n" + + " method (itsList, itsB, itsTyped);\n" + + " }\n" + + " \n" + + " public void method (List arg1, T arg2, Typed arg3)\n" + + " {\n" + + " }\n" + + " \n" + + " interface A{}\n" + + " class B implements A{}\n" + + " class Typed{}\n" + + " class MyTyped extends Typed{}\n" + + "\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 - variation + public void test0474() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Typed itsList;\n" + + " Typed itsTyped;\n" + + " public void test() {\n" + + " method(itsList, itsTyped);\n" + + " }\n" + + " public void method(Typed arg1, Typed arg3) {\n" + + " }\n" + + " interface A {\n" + + " }\n" + + " class B implements A {\n" + + " }\n" + + " class Typed {\n" + + " }\n" + + "}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 + public void test0475() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void method(List list) {\n" + + " list.add(new Object()); // should fail\n" + + " list.add(new Integer(3)); // correct\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " list.add(new Object()); // should fail\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (Object)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0476() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void method(List list, List lo) {\n" + + " list = lo;\n" + + " lo = list;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lo = list;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0477() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super T) in the type List is not applicable for the arguments (capture#2-of ? extends Number)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0478() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (capture#2-of ? super U)\n" + + "----------\n"); + } + + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0479() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0480() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Integer) in the type List is not applicable for the arguments (capture#2-of ? extends Number)\n" + + "----------\n"); + } + + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0481() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (capture#2-of ? super Integer)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83799 + public void test0482() { + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + " public void testEquals(final String x, T one, T two) {\n" + + " }\n" + + "\n" + + " public void testEqualsAlt(final String x, T1 one, T2 two) {\n" + + " }\n" + + "\n" + + " public interface Fooey {\n" + + " }\n" + + "\n" + + " public interface Bar extends Fooey {\n" + + " }\n" + + "\n" + + " public interface GenericFooey {\n" + + " }\n" + + "\n" + + " public interface GenericBar extends GenericFooey {\n" + + " }\n" + + "\n" + + " public void testGeneric() {\n" + + " testEquals(\"Should work\", new GenericBar() {\n" + + " }, new GenericBar() {\n" + + " });\n" + + " final GenericBar child = new GenericBar() {\n" + + " };\n" + + " final GenericFooey parent = child;\n" + + " testEquals(\"Doesn\'t work but should\", child, parent); // this\n" + + " // fails\n" + + " // but should work it\'s identical to next line.\n" + + " testEquals(\"Doesn\'t work but should\", (GenericFooey) child, parent);\n" + + " testEqualsAlt(\"Should work\", child, parent);\n" + + " }\n" + + " public void test() {\n" + + " testEquals(\"Should work\", new Bar() {\n" + + " }, new Bar() {\n" + + " });\n" + + " final Bar child = new Bar() {\n" + + " };\n" + + " final Fooey parent = child;\n" + + " testEquals(\"Doesn\'t work but should\", child, parent);\n" + + " testEquals(\"Doesn\'t work but should\", (Fooey) child, parent);\n" + + " testEqualsAlt(\"Should work\", child, parent);\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83904 + public void test0483() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " m(new Y(), new Y());\n" + + " }\n" + + "\n" + + " public static void m(Y x, Y y) {\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " m(new Y(), new Y());\n" + + " ^\n" + + "The method m(Y, Y) in the type X is not applicable for the arguments (Y, Y)\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 + public void test0484() { + this.runConformTest( + new String[] { + "X.java", + "class Base {\n" + + " public class Inner {\n" + + " }\n" + + " Inner a;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class DerivedInner extends Inner {\n" + + " }\n" + + " X() {\n" + + " a = new DerivedInner();\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - variation + public void test0485() { + this.runConformTest( + new String[] { + "X.java", + "class Base {\n" + + " public class Inner {\n" + + " }\n" + + " Inner a;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class DerivedInner extends Inner {\n" + + " }\n" + + " X() {\n" + + " a = new DerivedInner();\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - variation + public void test0486() { + this.runConformTest( + new String[] { + "X.java", + "class Base {\n" + + " public class Inner {\n" + + " }\n" + + " Inner a;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class DerivedInner extends Inner {\n" + + " }\n" + + " X() {\n" + + " a = new DerivedInner();\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0487() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo(List ls) {\n" + + " List l = ls;\n" + + " bar(l, \"\"); \n" + + " }\n" + + " void bar(List l, T t) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " bar(l, \"\"); \n" + + " ^^^\n" + + "The method bar(List, T) in the type X is not applicable for the arguments (List, String)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 + public void test0488() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " Foo f2 = new Foo();\n" + + " f1.bar = f2.bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " f1.bar = f2.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 + public void test0489() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " f1.bar = f1.bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " f1.bar = f1.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + public void test0490() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void bar(X> lhs, X> rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#4-of ? to capture#3-of ?\n" + + "----------\n"); + } + + public void test0491() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void bar(X> lhs, X> rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz2(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz3(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz4(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#4-of ? to capture#3-of ?\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " lhs = rhs;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#14-of ? extends Number to capture#13-of ? extends Number\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " lhs = rhs;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "5. ERROR in X.java (at line 21)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#18-of ? super Number to capture#17-of ? extends Number\n" + + "----------\n" + + "6. ERROR in X.java (at line 25)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#22-of ? super Number to capture#21-of ? super Number\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81576 + public void test0492() { + this.runConformTest( + new String[] { + "SuperType.java",//==================================== + "public class SuperType {\n" + + " protected InnerType valueWrapper;\n" + + " protected class InnerType {\n" + + " private T value;\n" + + " protected InnerType(T value) {\n" + + " this.value = value;\n" + + " }\n" + + " }\n" + + " public SuperType(T value) {\n" + + " /*\n" + + " * This constructor exists only to show that the usage of the inner\n" + + " * class within its enclosing class makes no problems\n" + + " */\n" + + " this.valueWrapper = new InnerType(value);\n" + + " }\n" + + " protected SuperType() {\n" + + " // Provided for the convenience of subclasses\n" + + " }\n" + + "}\n", + "SubType.java",//==================================== + "public class SubType extends SuperType {\n" + + "\n" + + " public SubType(T value) {\n" + + "\n" + + " /* The constructor SuperType .InnerType(T) is undefined */\n" + + " InnerType localValueWrapper = new InnerType(value);\n" + + "\n" + + " /*\n" + + " * Type mismatch: cannot convert from SuperType .InnerType to\n" + + " * SuperType .InnerType\n" + + " * \n" + + " * Type safety: The expression of raw type SuperType.InnerType is\n" + + " * converted to SuperType .InnerType. References to generic type\n" + + " * SuperType .InnerType should be parametrized.\n" + + " */\n" + + " localValueWrapper = super.valueWrapper;\n" + + " }\n" + + "\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83611 + public void test0493() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class M { M(Class templateClass) {} }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " void test() { M m = new M(X.class); }\n" + + "}\n" + }, + "" + ); + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " void test() { M m = new M(X.class); }\n" + + "}\n" + }, + "", + null, + false, + null + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83615 + public void test0494() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Number n= null;\n" + + " Integer i= null;\n" + + " new X().nextTry(i, n);\n" + + " new X().nextTry2(n, i);\n" + + " } \n" + + " \n" + + " void nextTry(I i, N n) {}\n" + + " \n" + + " void nextTry2(N n, I i) {} \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X().nextTry(i, n);\n" + + " ^^^^^^^\n" + + "Bound mismatch: The generic method nextTry(I, N) of type X is not applicable for the arguments (Integer, Number). The inferred type Number is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84422 + public void test0495() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " List l= null; \n" + + "\n" + + " void add(String s) {\n" + + " l.add(s);\n" + + " }\n" + + " \n" + + " void addAll(String[] ss) {\n" + + " l.addAll(Arrays.asList(ss));\n" + + " }\n" + + " \n" + + " String[] get() {\n" + + " return (String[])l.toArray(new String[l.size()]);\n" + + " }\n" + + "}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84593 + public void test0496() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "class Super {\n" + + " class A { }\n" + + " void take(A o) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class Sub extends Super {\n" + + " void test() {\n" + + " take(new A());\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Sub().test();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84593 - variation - uncheck warnings + public void test0497() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "class Super {\n" + + " class A { }\n" + + " void take(A o) {\n" + + " }\n" + + "}\n" + + "class Sub extends Super {\n" + + " void test() {\n" + + " take(new A());\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Sub().test();\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " take(new A());\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type Super.A needs unchecked conversion to conform to Super.A\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " take(new A());\n" + + " ^\n" + + "Super.A is a raw type. References to generic type Super.A should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84743 - variation in -source 1.4 mode but 1.5 compliance (ignore covariance) +public void test0498(){ + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " Object foo();\n" + + "}\n" + + " \n" + + "public class X implements I {\n" + + " public String foo() {\n" + + " return \"\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = new X();\n" + + " try {\n" + + " J j = (J) i;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 15)\n" + + " J j = (J) i;\n" + + " ^^^^^\n" + + "Cannot cast from I to J\n" + + "----------\n", + // javac options + RUN_JAVAC ? /* javac test options */ + new JavacTestOptions("-source 1.4") : + JavacTestOptions.DEFAULT ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=85157 +public void test0499(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " String[] tab1 = new String[0];\n" + + " Integer[] tab2 = new Integer[0];\n" + + " boolean cond = true;\n" + + " Integer[] var = cond ? tab1 : tab2;\n" + + " System.out.println(var);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Integer[] var = cond ? tab1 : tab2;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object&Serializable&Comparable>[] to Integer[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84251 +public void test0500(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "\n" + + "interface Sink { \n" + + " void flush(T t);\n" + + "}\n" + + "class SimpleSinkImpl implements Sink {\n" + + " public void flush(T t) {}\n" + + "}\n" + + "public class X {\n" + + "\n" + + " private T writeAll(Collection coll, Sink snk) { \n" + + " T last = null;\n" + + " for (T t : coll) { \n" + + " last = t;\n" + + " snk.flush(last);\n" + + " }\n" + + " return last;\n" + + " }\n" + + "\n" + + " public void test01() {\n" + + " Sink s = new SimpleSinkImpl();\n" + + " Collection cs = new ArrayList();\n" + + " cs.add(\"hello!\");\n" + + " cs.add(\"goodbye\");\n" + + " cs.add(\"see you\");\n" + + " \n" + + " String str = this.writeAll(cs, s); \n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " \n" + + " test.test01();\n" + + " }\n" + + "}\n" + }, + ""); +} + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0501() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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" + + " System.out.print(x.t.ax);\n" + + " System.out.print(x.t.bx);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P ax;\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " Q bx;\n" + + "}\n", + }, + "nullnull"); + 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 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 18 aload_1 [x]\n" + + " 19 getfield X.t : AX [16]\n" + + " 22 checkcast BX [26]\n" + + " 25 getfield BX.ax : java.lang.Object [37]\n" + + " 28 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [41]\n" + + " 31 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 34 aload_1 [x]\n" + + " 35 getfield X.t : AX [16]\n" + + " 38 checkcast BX [26]\n" + + " 41 getfield BX.bx : java.lang.Object [47]\n" + + " 44 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [41]\n" + + " 47 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 31, line: 9]\n" + + " [pc: 47, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 48] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 15, pc: 48] local: x index: 1 type: X\n" + + " Local variable type table:\n" + + " [pc: 15, pc: 48] local: x index: 1 type: X\n"; + + 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); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0502() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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" + + " System.out.print(x.self().t.ax);\n" + + " System.out.print(x.self().t.bx);\n" + + " }\n" + + " X self() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P ax;\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " Q bx;\n" + + "}\n", + }, + "nullnull"); + 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 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 18 aload_1 [x]\n" + + " 19 invokevirtual X.self() : X [37]\n" + + " 22 getfield X.t : AX [16]\n" + + " 25 checkcast BX [26]\n" + + " 28 getfield BX.ax : java.lang.Object [41]\n" + + " 31 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 34 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 37 aload_1 [x]\n" + + " 38 invokevirtual X.self() : X [37]\n" + + " 41 getfield X.t : AX [16]\n" + + " 44 checkcast BX [26]\n" + + " 47 getfield BX.bx : java.lang.Object [51]\n" + + " 50 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 53 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 34, line: 9]\n" + + " [pc: 53, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 54] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 15, pc: 54] local: x index: 1 type: X\n" + + " Local variable type table:\n" + + " [pc: 15, pc: 54] local: x index: 1 type: X\n"; + + 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); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0503() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XA {}\n" + + "interface XB {\n" + + " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + + "}\n" + + "class XAB extends XA implements XB {}\n" + + "\n" + + "public class X {\n" + + " E e;\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e.CONST);\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " System.out.print(this.e.CONST);\n" + + " }\n" + + "}\n", + }, + "SUCCESSSUCCESS"); + String expectedOutput = + "// Signature: Ljava/lang/Object;\n" + + "public class X {\n" + + " \n" + + " // Field descriptor #6 LXA;\n" + + " // Signature: TE;\n" + + " XA e;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 new X [1]\n" + + " 6 dup\n" + + " 7 invokespecial X() [28]\n" + + " 10 getfield X.e : XA [29]\n" + + " 13 checkcast XAB [31]\n" + + " 16 pop\n" + + " 17 getstatic XAB.CONST : XB [33]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 23 new X [1]\n" + + " 26 dup\n" + + " 27 invokespecial X() [28]\n" + + " 30 invokevirtual X.foo() : void [43]\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 33, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X.e : XA [29]\n" + + " 7 checkcast XB [48]\n" + + " 10 pop\n" + + " 11 getstatic XB.CONST : XB [50]\n" + + " 14 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 17, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n"; + + 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); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0504() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XA {}\n" + + "interface XB {\n" + + " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + + "}\n" + + "class XAB extends XA implements XB {}\n" + + "\n" + + "public class X {\n" + + " E e() { return null; }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e().CONST);\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " System.out.print(this.e().CONST);\n" + + " }\n" + + "}\n", + }, + "SUCCESSSUCCESS"); + String expectedOutput = + "// Signature: Ljava/lang/Object;\n" + + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #17 ()LXA;\n" + + " // Signature: ()TE;\n" + + " // Stack: 1, Locals: 1\n" + + " XA e();\n" + + " 0 aconst_null\n" + + " 1 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 new X [1]\n" + + " 6 dup\n" + + " 7 invokespecial X() [28]\n" + + " 10 invokevirtual X.e() : XA [29]\n" + + " 13 checkcast XAB [31]\n" + + " 16 pop\n" + + " 17 getstatic XAB.CONST : XB [33]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 23 new X [1]\n" + + " 26 dup\n" + + " 27 invokespecial X() [28]\n" + + " 30 invokevirtual X.foo() : void [43]\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 33, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 aload_0 [this]\n" + + " 4 invokevirtual X.e() : XA [29]\n" + + " 7 checkcast XB [48]\n" + + " 10 pop\n" + + " 11 getstatic XB.CONST : XB [50]\n" + + " 14 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 17, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n"; + + 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); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0505() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XA {}\n" + + "interface XB {\n" + + " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + + "}\n" + + "class XAB extends XA implements XB {}\n" + + "\n" + + "public class X {\n" + + " E e;\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " new Object() {\n" + + " void run() {\n" + + " System.out.print(e.CONST);\n" + + " }\n" + + " }.run();\n" + + " System.out.print(e.CONST);\n" + + " }\n" + + "}\n", + }, + "SUCCESSSUCCESS"); + String expectedOutput = + "// Signature: Ljava/lang/Object;\n" + + "public class X {\n" + + " \n" + + " // Field descriptor #6 LXA;\n" + + " // Signature: TE;\n" + + " XA e;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [22]\n" + + " 7 invokevirtual X.foo() : void [23]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 10, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: args index: 0 type: java.lang.String[]\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " public void foo();\n" + + " 0 new X$1 [28]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$1(X) [30]\n" + + " 8 invokevirtual X$1.run() : void [33]\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [36]\n" + + " 14 aload_0 [this]\n" + + " 15 getfield X.e : XA [42]\n" + + " 18 checkcast XB [44]\n" + + " 21 pop\n" + + " 22 getstatic XB.CONST : XB [46]\n" + + " 25 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [50]\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 8, line: 17]\n" + + " [pc: 11, line: 18]\n" + + " [pc: 28, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 29] local: this index: 0 type: X\n"; + + 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); + } + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85477 + public void test0506() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "\n" + + "public final class X {\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " foo(list, comparator);\n" + + " bar(list, comparator);\n" + + " \n" + + " x.foo(list, comparator);\n" + + " x.bar(list, comparator);\n" + + " }\n" + + "\n" + + " void foo(List lt, Comparator ct) {\n" + + " }\n" + + " static void bar(List lt, Comparator ct) {\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " ^^^^^^^^^^\n" + + "Comparator is a raw type. References to generic type Comparator should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " foo(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List, Comparator) of the generic method foo(List, Comparator) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " foo(list, comparator);\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " foo(list, comparator);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " bar(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, Comparator) of the generic method bar(List, Comparator) of type X\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " bar(list, comparator);\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "9. WARNING in X.java (at line 8)\n" + + " bar(list, comparator);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + + "----------\n" + + "10. WARNING in X.java (at line 10)\n" + + " x.foo(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(List, Comparator) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The static method bar(List, Comparator) from the type X should be accessed in a static way\n" + + "----------\n" + + "12. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, Comparator) of the generic method bar(List, Comparator) of type X\n" + + "----------\n" + + "13. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "14. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + + "----------\n" + + "15. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // array bound for wildcard + public void test0507() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo1(List l) {\n" + + " int i = l.get(0).length;\n" + + " }\n" + + " void foo2(List l) {\n" + + " Object o = l.get(0).toString();\n" + + " }\n" + + " void foo3(List l, Serializable s) {\n" + + " boolean b = true;\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " }\n" + + "}\n" + }, + ""); + } + // array bound for wildcard + public void test0508() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo1(List l) {\n" + + " int i = l.get(0).length;\n" + + " }\n" + + " void foo2(List l) {\n" + + " Object o = l.get(0).toString();\n" + + " }\n" + + " void foo3(List l, Serializable s) {\n" + + " boolean b = true;\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int i = l.get(0).length;\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Serializable\n" + + "----------\n"); + } + // type parameter hiding + public void test0509() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " list.add(new MyTigerSimpleObject(\"a\"));\n" + + " list.add(new MyTigerSimpleObject(\"b\"));\n" + + " \n" + + " for (MyTigerSimpleObject so : list)\n" + + " System.out.println(so.getSomeAttribute()); \n" + + " }\n" + + "}\n" + + "class MyTigerSimpleObject {\n" + + " MyTigerSimpleObject(String s) {}\n" + + " E getSomeAttribute() { return null; }\n" + + "}\n" + + "\n" + + "class TigerList extends ArrayList {\n" + + " public void listAll() {\n" + + " for (MyTigerSimpleObject so : this)\n" + + " System.out.println(so.getSomeAttribute());\n" + + " }\n" + + " \n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List list = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " List list = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " list.add(new MyTigerSimpleObject(\"a\"));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " list.add(new MyTigerSimpleObject(\"b\"));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " for (MyTigerSimpleObject so : list)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " class TigerList extends ArrayList {\n" + + " ^^^^^^^^^\n" + + "The serializable class TigerList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " class TigerList extends ArrayList {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type parameter MyTigerSimpleObject is hiding the type MyTigerSimpleObject\n" + + "----------\n" + + "8. ERROR in X.java (at line 20)\n" + + " System.out.println(so.getSomeAttribute());\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method getSomeAttribute() is undefined for the type MyTigerSimpleObject\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84355 + public void test0510() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " public X() {\n" + + " String[] strings = new String[]{\"test\"};\n" + + "\n" + + " // this fails\n" + + " Object obj = ClassB.doSomething((String) strings[0]);\n" + + "\n" + + " // this works fine\n" + + " String intermediate = ClassB.doSomething((String) strings[0]);\n" + + " Object obj1 = intermediate;\n" + + " }\n" + + "}\n" + + "\n" + + "class ClassB {\n" + + " public static T doSomething(String value) {\n" + + " return (T) value;\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82407 + public void test0511() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + "\n" + + " static HashMap substitutionList(String s1, String s2) {\n" + + "\n" + + " HashMap subst = new HashMap();\n" + + "\n" + + " for (int i = 0; i < s1.length(); i++) {\n" + + " char key = s1.charAt(i);\n" + + " char value = s2.charAt(i);\n" + + " if (subst.containsKey(key)) {\n" + + " if (value != subst.get(key)) {\n" + + " return null;\n" + + " }\n" + + " } else if (subst.containsValue(value)) {\n" + + " return null;\n" + + " } else {\n" + + " subst.put(key, value);\n" + + " }\n" + + " }\n" + + "\n" + + " return subst;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0512() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "public class X { \n" + + " public static void main(String argv[]) {\n" + + " \n" + + " new X().new M(null) {\n" + + " void run() {\n" + + " Exception e = ex;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " class M {\n" + + " E ex;\n" + + " M(E ex) {\n" + + " this.ex = ex;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0513() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "public class X { \n" + + " public static void main(String argv[]) {\n" + + " \n" + + " new X().new M(null) {\n" + + " void run() {\n" + + " Exception e = ex;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " class M {\n" + + " E ex;\n" + + " M(E ex) {\n" + + " this.ex = ex;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new X().new M(null) {\n" + + " void run() {\n" + + " Exception e = ex;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor X.M(Throwable) belongs to the raw type X.M. References to generic type X.M should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " new X().new M(null) {\n" + + " ^\n" + + "X.M is a raw type. References to generic type X.M should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " new X().new M(null) {\n" + + " ^^^^^^^\n" + + "Type safety: The constructor X.M(Throwable) belongs to the raw type X.M. References to generic type X.M should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Exception e = ex;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Throwable to Exception\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82955 + public void test0514(){ + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static T infer( T t1, T t2 ) { return null; }\n" + + " public static void main( String [] args ) {\n" + + " Base base = infer( new Sub1(), new Sub2() );\n" + + " // Note: Eclipse 3.1 says this is an error, but it\'s not\n" + + " Runnable runnable = infer( new Sub1(), new Sub2() );\n" + + " }\n" + + "}\n" + + "class Base { }\n" + + "class Sub1 extends Base implements Runnable { public void run() { } }\n" + + "class Sub2 extends Base implements Runnable { public void run() { } }\n" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84348 + public void test0515(){ + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static void myMethod(final List fileList) {\n" + + " Collections.sort(fileList, new Comparator(){\n" + + " public int compare(File f1, File f2) { return 0; }\n" + + " });\n" + + " }\n" + + "}\n" + + "\n" + + "class List {}\n" + + "class File {}\n" + + "interface Comparator {}\n" + + "class Collections {\n" + + " static void sort(List list, Comparator c) {}\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 + public void test0516(){ + runConformTest( + new String[] { + "parser/AbstractParser.java", + "package parser;\n" + + "public abstract class AbstractParser implements ValueParser {\n" + + " public T parse( final String string ) {\n" + + " return valueOf(string); \n" + + " }\n" + + " protected abstract T valueOf(final String string); \n" + + "}\n" + + "interface ValueParser {\n" + + " T parse(final String string);\n" + + "}\n", + "parser/BooleanParser.java", + "package parser;\n" + + "public class BooleanParser extends AbstractParser {\n" + + " protected Boolean valueOf(final String string ) {\n" + + " return Boolean.valueOf(string); \n" + + " }\n" + + "}\n" + } + ); + runConformTest( + new String[] { + "test/BooleanParserTest.java", + "package test;\n" + + "import parser.BooleanParser;\n" + + "public class BooleanParserTest {\n" + + " static final boolean getBoolean(final String value) {\n" + + " return new BooleanParser().parse(value).booleanValue(); // The type Boolean is not visible\n" + + " }\n" + + "}\n" + }, + null, + null, + false, // do not flush output directory + null + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 - check no warning for using raw member + public void test0517(){ + runNegativeTest( + new String[] { + "X.java", + "class Base {\n" + + " class InnerBase {\n" + + " java.util.List list;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class InnerDerived extends InnerBase {\n" + + " void method() {\n" + + " list.add(\"Hi\"); // Warning on this method call\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85930 - check no warning for using raw member + public void test0518(){ + runNegativeTest( + new String[] { + "X.java", + "interface Callable {\n" + + " public enum Result {\n" + + " GOOD, BAD\n" + + " };\n" + + " public Result call(T arg);\n" + + "}\n" + + "\n" + + "public class X implements Callable {\n" + + " public Result call(String arg) {\n" + + " return Result.GOOD;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85262 + public void test0519(){ + runConformTest( + new String[] { + "FooImpl.java", + "interface Bar> {} \n" + + " \n" + + "class BarImpl> implements Bar {} \n" + + " \n" + + "interface Foo> extends Bar {} \n" + + " \n" + + "public class FooImpl> extends BarImpl implements Foo {}\n" + + "\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85262 - variation + public void test0520(){ + runConformTest( + new String[] { + "Bar.java", + "public interface Bar> {} \n", + "BarImpl.java", + "public class BarImpl> implements Bar {} \n", + "Foo.java", + "public interface Foo> extends Bar {} \n", + }, + ""); + runConformTest( + new String[] { + "FooImpl.java", + "public class FooImpl> extends BarImpl implements Foo {}\n", + }, + "", + null, + false, // do not flush output directory + null); + } + public void test0521(){ + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " static public void addAll(T a, T b) {\n" + + " a.addAll(b);\n" + + " }\n" + + " static public void main(String[] args) {\n" + + " Collection a = new ArrayList();\n" + + " Collection b = new ArrayList();\n" + + " b.add(\"string\");\n" + + " addAll(a, b);\n" + + " try {\n" + + " System.out.println(a.iterator().next().intValue()); // ClassCastException\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // variation on test0521, check issuing of unchecked warning ** + public void test0522(){ + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " static public void addAll(T a, T b) {\n" + + " a.addAll(b);\n" + + " }\n" + + " static public void main(String[] args) {\n" + + " Collection a = new ArrayList();\n" + + " Collection b = new ArrayList();\n" + + " b.add(\"string\");\n" + + " addAll(a, b);\n" + + " try {\n" + + " System.out.println(a.iterator().next().intValue()); // ClassCastException\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " static public void addAll(T a, T b) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " a.addAll(b);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The method addAll(Collection) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0523(){ + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public X() {\n" + + " M m = new M();\n" + + " List ls = m.list(); // rawified even though wasn\'t using T parameter\n" + + " }\n" + + " Zork z;\n" + + " static class M {\n" + + " List list() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " M m = new M();\n" + + " ^\n" + + "X.M is a raw type. References to generic type X.M should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " M m = new M();\n" + + " ^\n" + + "X.M is a raw type. References to generic type X.M should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " List ls = m.list(); // rawified even though wasn\'t using T parameter\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ensure there is no unchecked warning ** + public void test0524(){ + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class MyList extends ArrayList {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List a = new MyList();\n" + + " List b = (MyList) a; \n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class MyList extends ArrayList {\n" + + " ^^^^^^\n" + + "The serializable class MyList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0525(){ + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " List list = new ArrayList();\n" + + " String s = \"this shouldn\'t work\";\n" + + " list.add(s);\n" + + " List listInt = list;\n" + + " int i = listInt.get(0);\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0526(){ + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " T f(Object o) {\n" + + " return (T) o; // OK\n" + + " }\n" + + "\n" + + " T g(Object o) {\n" + + " return (T) o; // bug???\n" + + " }\n" + + "\n" + + " T h(Object o) {\n" + + " return X.castTo(o); // workaround\n" + + " }\n" + + "\n" + + " private static T castTo(Object o) {\n" + + " return (T) o;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " return (T) o; // OK\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " return (T) o; // bug???\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " return (T) o;\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n"); + } + // should not produce unchecked errors ** + public void test0527(){ + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(U u, V v) {\n" + + " return this == null ? (T) u : (T)v;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86217 + public void test0528() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {}\n" + + "class Y { static class M {} }\n", + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86463 + public void test0529() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " T t = new ArrayList(); // BUG!!!\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public class X {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " T t = new ArrayList(); // BUG!!!\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " T t = new ArrayList(); // BUG!!!\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86463 + public void test0530() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "abstract class Foo\n" + + " {\n" + + " abstract void foo(T t);\n" + + " void foo2()\n" + + " {\n" + + " List l = new LinkedList();\n" + + " foo(l); // BUG!!!\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Foo\n" + + "{\n" + + " void foo(ArrayList l)\n" + + " {\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " abstract class Foo\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " List l = new LinkedList();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " List l = new LinkedList();\n" + + " ^^^^^^^^^^\n" + + "LinkedList is a raw type. References to generic type LinkedList should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " foo(l); // BUG!!!\n" + + " ^^^\n" + + "The method foo(T) in the type Foo is not applicable for the arguments (List)\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " public class X extends Foo\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " void foo(ArrayList l)\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method foo(ArrayList) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " void foo(ArrayList l)\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86646 + public void test0531() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " public T f1(T l) {\n" + + " Vector v = new Vector();\n" + + " v.add(l);\n" + + " return (T) v.get(0); // Expect warning here\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " return (T) v.get(0); // Expect warning here\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from T to T\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 + public void test0532() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X extends Z {\n" + + " @Override public Boolean value() { return true; }\n" + + "}\n" + + "abstract class Z {\n" + + " public T foo() { return value(); }\n" + + " public abstract T value();\n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "Y.java", + "import p.X;\n" + + "public class Y { boolean test() { return new X().foo().booleanValue(); } }\n", + }, + "", + null, + false, // do not flush output + null + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 + public void test0533() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0534() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0535() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0536() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0537() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0538() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet>\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0539() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class B {\n" + + " public T willBe(Class c) {\n" + + " return (T)null;\n" + + " }\n" + + " }\n" + + " interface I1 {\n" + + " }\n" + + " interface I2 extends I1 {\n" + + " }\n" + + " \n" + + " public static void m1(String[] args) {\n" + + " B b = new B();\n" + + " I2 v = b.willBe(I2.class);\n" + + " }\n" + + " public static void m2(String[] args) {\n" + + " B b = new B();\n" + + " I2 v = b.willBe(I2.class);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return (T)null;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from null to T\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " B b = new B();\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 13)\n" + + " B b = new B();\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " I2 v = b.willBe(I2.class);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method willBe(Class) belongs to the raw type X.B. References to generic type X.B should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " I2 v = b.willBe(I2.class);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.I1 to X.I2\n" + + "----------\n"); + } + // test paramtype argument compatibility + public void test0540() { + this.runNegativeTest( + new String[] { + "Baz.java", + "import java.util.*;\n" + + "interface Foo {}\n" + + "interface Bar extends Foo {\n" + + "}\n" + + "public class Baz {\n" + + " public R visit(Collection> trees, D d) {\n" + + " return null;\n" + + " }\n" + + " R test(Collection c, D d) {\n" + + " return visit(c, d);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Baz.java (at line 3)\n" + + " interface Bar extends Foo {\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "2. ERROR in Baz.java (at line 10)\n" + + " return visit(c, d);\n" + + " ^^^^^\n" + + "The method visit(Collection>, D) in the type Baz is not applicable for the arguments (Collection, D)\n" + + "----------\n"); + } + public void test0541() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map m = null;\n" + + " try {\n" + + " Map m2 = m.getClass().newInstance();\n" + + " } catch(Exception e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0542() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static boolean isOK(T x) {\n" + + " return isOK(x);\n" + + " }\n" + + "\n" + + " static boolean isStillOK(T x) {\n" + + " return true && isOK(x);\n" + + " }\n" + + "\n" + + " static boolean isNoMoreOK(T x) {\n" + + " return true && isNoMoreOK(x);\n" + + " }\n" + + "\n" + + " static boolean isOKAgain(T x) {\n" + + " boolean res;\n" + + " return true && (res = isOKAgain(x));\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0543() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object obj = null;\n" + + " List ls = (List) obj;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " List ls = (List) obj;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0544() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Vector a = new Vector();\n" + + " Vector b = new Vector();\n" + + " b.add(new Object());\n" + + " a = b;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Vector b = new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " Vector b = new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " b.add(new Object());\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " a = b;\n" + + " ^\n" + + "Type safety: The expression of type Vector needs unchecked conversion to conform to Vector\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86898 + public void test0545() { + this.runNegativeTest( + new String[] { + "X.java", + "class B extends A {\n" + + " void m2() {\n" + + " m3((X2) m()); // A.m() --> X - cannot cast to X2\n" + + " }\n" + + " void m3(X2 i) {}\n" + + "}\n" + + "class A {\n" + + " X m() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class X2 extends X {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(X lhs, X rhs) {\n" + + " lhs = rhs; // cannot convert\n" + + " }\n" + + " void bar(X2 lhs, X rhs) {\n" + + " lhs = rhs; // cannot convert\n" + + " }\n" + + "}\n" + + "class C {\n" + + " void foo(X xo) {}\n" + + " void bar(X xs) {}\n" + + "}\n" + + "class D extends C {\n" + + " void foo(X xs) {}\n" + + " void bar(X xo) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " lhs = rhs; // cannot convert\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " lhs = rhs; // cannot convert\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X2\n" + + "----------\n" + + "3. ERROR in X.java (at line 29)\n" + + " void foo(X xs) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(X) of type D has the same erasure as foo(X) of type C but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 30)\n" + + " void bar(X xo) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method bar(X) of type D has the same erasure as bar(X) of type C but does not override it\n" + + "----------\n"); + } + // ensure no unsafe cast warning ** + public void test0546() { + this.runNegativeTest( + new String[] { + "X.java", + "class StringList extends java.util.LinkedList {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.List a = new StringList();\n" + + " java.util.List b = (StringList) a; // warned but safe.\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class StringList extends java.util.LinkedList {\n" + + " ^^^^^^^^^^\n" + + "The serializable class StringList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0547() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public TreeMap essai(K type) {\n" + + " TreeMap treeMap = new TreeMap();\n" + + " return treeMap;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " TreeMap treeMap = x.essai(null);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + public void test0548() { + this.runNegativeTest( + new String[] { + "X.java", + "interface DA {\n" + + "}\n" + + "interface DB extends DA {\n" + + "}\n" + + "interface DC extends DA {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Object o = (DC) (DA) null;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Object o = (DC) (DA) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from DA to DC\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Object o = (DC) (DA) null;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from null to DA\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ** + public void test0549() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean DEBUG = this instanceof Special;\n" + + "\n" + + " public static class Special extends X {\n" + + " }\n" + + "}\n", + }, + ""); + } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 + public void test0550() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public class X {\n" + + " public void foo(X param) {\n" + + " X foo = (X)param;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X foo = (X)param;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ensure no unchecked warning + public void test0551() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " return (z? (T) x1: x2);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " ^\n" + + "The parameter z is hiding a field from type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0552() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " Comparable x;\n" + + "\n" + + " void put(Comparable c) {\n" + + " this.x = c;\n" + + " }\n" + + "\n" + + " Comparable get() {\n" + + " return x;\n" + + " }\n" + + "\n" + + " void test() {\n" + + " X ci = new X();\n" + + " ci.put(new Integer(3));\n" + + " Integer i = (Integer) ci.get();\n" + + " }\n" + + "\n" + + "}\n", + }, + ""); + } + public void test0553() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) throws Exception {\n" + + " doIt();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void doIt() {\n" + + " Holder association = new Holder(new Integer(0));\n" + + " Integer sizeHolder = (Integer)(association.getValue()); //Cast to Integer is redundant!!!\n" + + " System.out.print(sizeHolder.intValue());\n" + + " }\n" + + " static class Holder {\n" + + " V value;\n" + + " Holder(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " V getValue() {\n" + + " return value;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + "0SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86898 - variation + public void test0554() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + " public class X {\n" + + " public static void main(String[] args) {\n" + + " X xo = null;\n" + + " X xs = null;\n" + + " X2 x2 = null;\n" + + " \n" + + " Object o1 = (X) xo;\n" + + " Object o2 = (X) xs;\n" + + " Object o3 = (X2) xo;\n" + + " Object o4 = (X) x2;\n" + + " Object o5 = (X3) xo;\n" + + " }\n" + + "}\n" + + "class X2 extends X {\n" + + "}\n" + + "class X3 extends X {\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " Object o1 = (X) xo;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " Object o1 = (X) xo;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Object o2 = (X) xs;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " Object o3 = (X2) xo;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from X to X2\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " Object o4 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X2 to X\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " Object o5 = (X3) xo;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X3\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " Object o5 = (X3) xo;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X3\n" + + "----------\n" + + "8. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0555() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.List;\n" + + " public class X {\n" + + " U u;\n" + + " void foo(X xn, X xu) {\n" + + " xn = xu;\n" + + " xu = xn;\n" + + " xu.u = xn.u; // ko\n" + + " xn.u = xu.u; // ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " xu = xn;\n" + + " ^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " xu.u = xn.u; // ko\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from capture#6-of ? extends Number to capture#5-of ? extends U\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " xn.u = xu.u; // ko\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from capture#8-of ? extends U to capture#7-of ? extends Number\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87273 + public void test0556() { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " Object get();\n" + + "}\n" + + "\n" + + "interface MyList extends Foo {\n" + + " public F get();\n" + + "}\n" + + "\n" + + "class MyListImpl implements MyList {\n" + + " public G get() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface StringList extends MyList {\n" + + "}\n" + + "\n" + + "class StringListImpl extends MyListImpl implements StringList {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = new StringListImpl();\n" + + " f.get();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83002 + public void test0557() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(T t) throws T {\n" + // ensure exception is properly encoded (...^ex) + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "import java.io.*;\n" + + "public class Y {\n" + + " void foo() {\n" + + " try {\n" + + " X.foo(new IOException());\n" + + " } catch(IOException e){\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83002 + public void test0558() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(T t, U u) throws T, U {\n" + // ensure exception is properly encoded (...^ex) + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "import java.io.*;\n" + + "public class Y {\n" + + " void foo() {\n" + + " try {\n" + + " X.foo(new IOException(), new ClassNotFoundException());\n" + + " } catch(IOException e){\n" + + " } catch(ClassNotFoundException e){\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86902 + // ** + public void test0559() { + this.runNegativeTest( + new String[] { + "X.java", + "class Cell {\n" + + " T t;\n" + + " public void setT(T t) {\n" + + " this.t= t;\n" + + " }\n" + + " public T getT() {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " public static void main(String[] args) {\n" + + " Cell c= new Cell();\n" + + " c.setT(Boolean.FALSE); // other: warning: [unchecked] unchecked\n" + + " // call to setT(T) as a member of the raw type p.Cell\n" + + " c.t= Boolean.TRUE; // other: warning: [unchecked] unchecked call\n" + + " // to setT(T) as a member of the raw type p.Cell\n" + + " boolean b1= (Boolean) c.getT();\n" + + " boolean b2= (Boolean) c.t;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " Cell c= new Cell();\n" + + " ^^^^\n" + + "Cell is a raw type. References to generic type Cell should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " Cell c= new Cell();\n" + + " ^^^^\n" + + "Cell is a raw type. References to generic type Cell should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " c.setT(Boolean.FALSE); // other: warning: [unchecked] unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setT(Object) belongs to the raw type Cell. References to generic type Cell should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " c.t= Boolean.TRUE; // other: warning: [unchecked] unchecked call\n" + + " ^\n" + + "Type safety: The field t from the raw type Cell is assigned a value of type Boolean. References to generic type Cell should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85924 + public void test0560() { + this.runConformTest( + new String[] { + "X.java", + "interface IController> {\n" + + " public U getView() ;\n" + + "}\n" + + "interface IView {\n" + + "}\n" + + "class MatGroup {\n" + + " public abstract static class View implements IView {\n" + + " public void setTempAppearance() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " \n" + + " public abstract static class Ctrl implements IController {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String []args) {\n" + + " MatGroup.Ctrlchildren[] = { \n" + + " new MatGroup.Ctrl(){\n" + + " public MatGroup.View getView() { return new MatGroup.View(){}; } \n" + + " }} ;\n" + + " for(MatGroup.Ctrl glmat: children) {\n" + + " glmat.getView().setTempAppearance() ;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87956 + public void test0561() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(A a) {}\n" + + " Object foo(A a) { return null; }\n" + + " void test(A a) { foo(a); }\n" + + "}\n" + + "class A {}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Number foo(A a) { return null; }\n" + + " Integer foo(A a) { return null; }\n" + + " void test(A a) { foo(a); }\n" + + "}\n" + + "class A {}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 + public void test0562() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface Inter {}\n" + + "public class X> extends ArrayList implements Inter {\n" + + " public final void foo(U u) {\n" + + " X.bar(this, u);\n" + + " }\n" + + " public static final void bar(Collection> c, Q q) {}\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - variation + public void test0563() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface Inter {}\n" + + "public class X> extends ArrayList implements Inter {\n" + + " public final void foo(U u) {\n" + + " X.bar(this, u);\n" + + " }\n" + + " public static final void bar(Collection c, Q q) {}\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - variation + public void test0564() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface Inter {}\n" + + "public class X> extends ArrayList implements Inter {\n" + + " public final void foo(U u) {\n" + + " X.bar(this, u);\n" + + " }\n" + + " public static final void bar(Collection> c, Q q) {}\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87995 - check no warning + public void test0565() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "interface IFoo {\n" + + " public T get(Class clazz);\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "class Bar implements IFoo {\n" + + " public Integer get(Class arg0) {\n" + + " return new Integer(3);\n" + + " }\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0566() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void bar2() {\n" + + " List le = new ArrayList(5);\n" + + " le = fill(le, new X2());\n" + + " }\n" + + " List fill(List lt, T t) { return null; }\n" + + "}\n" + + "class X1 {}\n" + + "class X2 extends X1 {\n" + + " void foo(){}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " le = fill(le, new X2());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89454 + public void test0567() { + this.runConformTest( + new String[] { + "Thrower.java", + "public interface Thrower {\n" + + " public void throwIt() throws E;\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "GenericsTest.java", + "public class GenericsTest {\n" + + " public static void main(String[] args) throws MyException {\n" + + " Thrower thrower = new Thrower() {\n" + + " public void throwIt() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + " };\n" + + " try {\n" + + " thrower.throwIt();\n" + + " } catch(Exception e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class MyException extends Exception {\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89448 + public void test0568() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + "\n" + + " ArrayList> n = new ArrayList>();\n" + + " ArrayList arr = new ArrayList();\n" + + " arr.add(new Long(5));\n" + + " n.add(arr);\n" + + " \n" + + " List> m = n; // Whoa!\n" + + " \n" + + " for(Long l : m.get(0)) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + "\n" + + "}\n", + }, + "5"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89778 + public void test0569() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " protected static void foo() throws T, Exce {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " protected static void foo() throws T, Exce {\n" + + " ^^^^\n" + + "Exce cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90147 + public void test0570() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class InnerClass implements Comparable {\n" + + " public int compareTo(T other) {\n" + + " return -1;\n" + + " }\n" + + " }\n" + + " \n" + + " public void foo() {\n" + + " InnerClass a = new InnerClass();\n" + + " InnerClass b = new InnerClass();\n" + + " // The following line does not compile (anymore):\n" + + " a.compareTo(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " a.compareTo(b);\n" + + " ^^^^^^^^^\n" + + "The method compareTo(T) in the type X.InnerClass is not applicable for the arguments (X.InnerClass)\n" + + "----------\n"); + } + public void test0571() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "class Box {\n" + + " T value() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void test01(Box box) {\n" + + " box.value().foo();\n" + + " }\n" + + " void test02(Box box) {\n" + + " box.value().foo();\n" + + " box.value().bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90430 + public void test0572() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public > void doWithEnumClass(Class enumClass) {\n" + + " }\n" + + "\n" + + " public void f() {\n" + + " Class cl = null; // Returned by Class.forName(\"xyz\");\n" + + " doWithEnumClass((Class) cl);\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90430 - check unchecked warnings + public void test0573() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public > void doWithEnumClass(Class enumClass) {\n" + + " Zork z;\n" + + " }\n" + + "\n" + + " public void f() {\n" + + " Class cl = null; // Returned by Class.forName(\"xyz\");\n" + + " doWithEnumClass((Class) cl);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " doWithEnumClass((Class) cl);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doWithEnumClass(Class) of the generic method doWithEnumClass(Class) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " doWithEnumClass((Class) cl);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " doWithEnumClass((Class) cl);\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 - variation + public void test0574() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " class C2 {\n" + + " T foo(Object o) { return null; } // ok\n" + + " T foo(Object o) { return null; } // ok\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new C2().foo((List) null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " new X().new C2().foo((List) null);\n" + + " ^^^\n" + + "The method foo(Object) is ambiguous for the type X.C2\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with field ref + public void test0575() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " (f1).bar = (f1).bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (f1).bar = (f1).bar;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with single ref + public void test0576() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " Foo f2 = new Foo();\n" + + " f1 = f1;\n" + + " f1 = f2;\n" + + " }\n" + + " static class Foo {\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with qualified name ref + public void test0577() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " (f1).bar = f1.bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (f1).bar = f1.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + // check array bound for wildcard + public void test0578() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Box box) {\n" + + " int[] ints = box.get();\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " T get() { return null; }\n" + + "}\n" + }, + ""); + } + // check array bound for wildcard + public void test0579() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Box box) {\n" + + " int[] ints = box.get();\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " T get() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int[] ints = box.get();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? super int[] to int[]\n" + + "----------\n"); + } + // check array bound for wildcard + public void test0580() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Box box) {\n" + + " int[] ints = box.get();\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " T get() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int[] ints = box.get();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to int[]\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation + public void test0581() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " f1.bar = f1.bar;\n" + + " }\n" + + " }\n" + + "class Foo {\n" + + " Bar bar = new Bar();\n" + + "}\n" + + "class Bar {\n" + + " T t;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " f1.bar = f1.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Bar to Bar\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 + public void test0582() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " void foo(List l1) {\n" + + " C1 c1 = (C1)l1.get(0);\n" + + " }\n" + + "}\n" + + "interface I1{}\n" + + "class C1{}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91021 + public void test0583() { + this.runNegativeTest( + new String[] { + "X.java", + "class D {\n" + + " public D (D anotherD) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static class C {\n" + + " public C(C anotherC) {\n" + + " }\n" + + " }\n" + + "\n" + + " public void mD(D d) {\n" + + " //the following line is OK (no warning reported)\n" + + " new D(d);\n" + + " }\n" + + " \n" + + " public void mC(C c) {\n" + + " /* type safety warning\n" + + " * (The expression of type X.C\n" + + " * needs unchecked conversion to conform to\n" + + " * XSB.C)\n" + + " */\n" + + " new C(c);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 25)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91017 + public void test0584() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List stringList = new ArrayList();\n" + + " stringList.add(\"foo\");\n" + + " List intList = new ArrayList();\n" + + " intList.add(1);\n" + + "\n" + + " List untypedList = stringList;\n" + + " List untypedList2 = intList;\n" + + "\n" + + " //correctly flagged as error: untypedList.add(new Object());\n" + + " //ditto: untypedList.add(untypedList2.get(0));\n" + + "\n" + + " //but this is not flagged at all by eclipse:\n" + + " untypedList.addAll(untypedList2);\n" + + "\n" + + " for(String s : stringList){\n" + + " //next line generates runtime ClassCastException\n" + + " Logger.log(\"Test_Lists.main: s: \" + s);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " untypedList.addAll(untypedList2);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Logger.log(\"Test_Lists.main: s: \" + s);\n" + + " ^^^^^^\n" + + "Logger cannot be resolved\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90881 + public void test0585() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Outer.Comparator i = new Outer.Comparator() {\n" + + "\n" + + " public boolean equals(String a, String b) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int hashCode(String a) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + "\n" + + " }\n" + + "}\n" + + "\n" + + "class Outer {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Outer.Comparator i = new Outer.Comparator() {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Outer.Comparator cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Outer.Comparator i = new Outer.Comparator() {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Outer.Comparator cannot be resolved to a type\n" + + "----------\n"); + } + + // ** + // note: the test does not show the needed unchecked warning, since it is + // a conform test + public void test0586() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class BB { }\n" + + " static class BD extends BB { }\n" + + " void f() {\n" + + " BB bb = null;\n" + + " Object o = (BD) bb;\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0587() { + this.runConformTest( + new String[] { + "X.java", + "interface DA {\n" + + "}\n" + + "interface DB extends DA {\n" + + "}\n" + + "interface DC extends DA {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Object o = (DC) (DA) null;\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90433 + // ** + public void test0588() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public void f() {\n" + + " Class> cc = Long.class;\n" + + " Class currentClass = null;\n" + + " boolean b = currentClass == Long.class;\n" + + " boolean c = X.class == Long.class;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " boolean c = X.class == Long.class;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 + public void test0589() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void addAll(List target, List source) {\n" + + " target.addAll(source);\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " List ints = new ArrayList();\n" + + " ints.add(3);\n" + + "\n" + + " List floats = new ArrayList();\n" + + " floats.add(3f);\n" + + "\n" + + " new X().addAll(ints, floats);\n" + + "\n" + + " for (Integer integer : ints) {\n" + + " System.out.println(integer.intValue());\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " target.addAll(source);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation + public void test0590() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void assignAll(Class sup, Class ext) {\n" + + " Class superSup = sup.getSuperclass();\n" + + " Class superExt = ext.getSuperclass();\n" + + " Class superSup2 = ext.getSuperclass();\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Class superSup2 = ext.getSuperclass();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation + public void test0591() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public Values foo(Box box) {\n" + + " return selectedValues(box.getValues());\n" + + " }\n" + + " public static Values selectedValues(Values v) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + ""); + } + public void test0592() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List l;\n" + + " void m() {\n" + + " m2(l);\n" + + " }\n" + + " void m2(List l2) {\n" + + " l2.add(l2.remove(0));\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0593() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + + " List> classes2 = Arrays.asList(String.class, Boolean.class);\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Class> is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List>> to List>\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " List> classes2 = Arrays.asList(String.class, Boolean.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Class> is created for a varargs parameter\n" + + "----------\n"); + } + public void test0594() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + "import static java.util.Map.*;\n" + + "\n" + + "abstract class MyIterator implements Iterator {\n" + + " Set iteratedSet;\n" + + "}\n" + + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Map map;\n" + + " Iterator> it = map.entrySet().iterator();\n" + + "\n" + + " Entry unrelatedEntry;\n" + + " MyIterator> mit = (MyIterator>) it;\n" + + " mit.iteratedSet.add(unrelatedEntry);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Iterator> it = map.entrySet().iterator();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator> to Iterator>\n" + + "----------\n"); + } + public void test0595() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + "import static java.util.Map.*;\n" + + "\n" + + "abstract class MyIterator implements Iterator {\n" + + " Set iteratedSet;\n" + + "}\n" + + "public class X {\n" + + " \n" + + " void bar() {\n" + + " Map map;\n" + + " Iterator> it = map.entrySet().iterator();\n" + + "\n" + + " Entry unrelatedEntry;\n" + + " MyIterator> mit = (MyIterator>) it;\n" + + " mit.iteratedSet.add(unrelatedEntry);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Iterator> it = map.entrySet().iterator();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator> to Iterator>\n" + + "----------\n"); + } + public void test0596() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Set unmodifiableSet(Set set) {\n" + + " return set;\n" + + " }\n" + + " public void foo(Set s) {\n" + + " Set s2 = unmodifiableSet(s);\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0597() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Pair m() { \n" + + " return null; \n" + + " }\n" + + " void foo(X x) {\n" + + " x.m().first = x.m().second;\n" + + " }\n" + + "}\n" + + " \n" + + "class Pair {\n" + + " E first;\n" + + " F second;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.m().first = x.m().second;\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? to capture#1-of ?\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 + public void test0598() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class X implements Comparable {\n" + + "\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "class Y {\n" + + " public static void main(String[] args) {\n" + + " List lx = null;\n" + + " Collections.sort(lx);\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - variation + public void test0599() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X implements Comparable {\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " \n" + + " List lx = null;\n" + + " sort1(lx);\n" + + " sort2(lx);\n" + + " sort3(lx);\n" + + " sort4(lx);\n" + + " sort5(lx);\n" + + " }\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " static > void sort1(List list) {}\n" + + " static > void sort2(List list) {}\n" + + " static > void sort3(List list) {}\n" + + " static > void sort4(List list) {}\n" + + " static void sort5(List list) {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " sort1(lx);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort1(List) of the generic method sort1(List) of type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " sort2(lx);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort2(List) of the generic method sort2(List) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " sort4(lx);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort4(List) of the generic method sort4(List) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 21)\n" + + " static void sort5(List list) {}\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - variation + public void test0600() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X implements Comparable {\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " \n" + + " List le = null;\n" + + " sort6(le);\n" + + " sort7(le);\n" + + " sort8(le);\n" + + " sort9(le);\n" + + " sort10(le);\n" + + " }\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " static > void sort6(List list) {}\n" + + " static > void sort7(List list) {}\n" + + " static > void sort8(List list) {}\n" + + " static > void sort9(List list) {}\n" + + " static void sort10(List list) {}\n" + + "}\n" + + "class MyEnum> {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " List le = null;\n" + + " ^^^^^^\n" + + "MyEnum is a raw type. References to generic type MyEnum should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " sort6(le);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort6(List) of the generic method sort6(List) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " sort7(le);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort7(List) of the generic method sort7(List) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 11)\n" + + " sort9(le);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort9(List) of the generic method sort9(List) of type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 21)\n" + + " static void sort10(List list) {}\n" + + " ^^^^^^\n" + + "MyEnum is a raw type. References to generic type MyEnum should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation + public void test0601() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public Values foo(Box box) {\n" + + " return selectedValues(box.getValues());\n" + + " }\n" + + " public static Values selectedValues(Values v) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return selectedValues(box.getValues());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0602() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box box) {\n" + + " box.getValues()[0] = box.getValues()[1];\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " box.getValues()[0] = box.getValues()[1];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0603() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box[] boxes) {\n" + + " boxes[0] = boxes[1];\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + ""); + } + // capture on array ref + public void test0604() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box[] boxes) {\n" + + " bar(boxes[0], boxes[1]);\n" + + " }\n" + + " void bar(V v1, V v2) {}\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + ""); + } + // capture on array ref + public void test0605() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box box) {\n" + + " box.getValues()[1] = box.getValues()[2];\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " box.getValues()[1] = box.getValues()[2];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0606() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box box) {\n" + + " box.getValues()[1] = (Values) box.getValues()[2];\n" + + " }\n" + + " void bar(V v1, V v2) {}\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " box.getValues()[1] = (Values) box.getValues()[2];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0607() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void test01() {\n" + + " List> lObj = new ArrayList> ();\n" + + " Collections.sort (lObj); \n" + + " }\n" + + " void test02() {\n" + + " List lComp = new ArrayList ();\n" + + " Collections.sort (lComp); \n" + + " }\n" + + " void test03() {\n" + + " List> lStr = new ArrayList> ();\n" + + " Collections.sort (lStr);\n" + + " }\n" + + " }\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List lComp = new ArrayList ();\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List lComp = new ArrayList ();\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " Collections.sort (lComp); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort(List) of the generic method sort(List) of type Collections\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " Collections.sort (lStr);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method sort(List) of type Collections is not applicable for the arguments (List>). The inferred type Comparable is not a valid substitute for the bounded parameter >\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84284 - check warnings + public void test0608() { + this.runNegativeTest( + new String[] { + "Ball.java", + "import java.util.*;\n" + + "class Ball implements Comparable {\n" + + "\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " LinkedList foo = new LinkedList();\n" + + " Collections.sort(foo);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Ball.java (at line 2)\n" + + " class Ball implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in Ball.java (at line 10)\n" + + " Collections.sort(foo);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort(List) of the generic method sort(List) of type Collections\n" + + "----------\n" + + "3. ERROR in Ball.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81831 + public void test0609() { + this.runConformTest( + new String[] { + "I.java", + "interface I> {}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89940 + public void test0610() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List objects, List raw) {\n" + + "\n" + + " List numbers;\n" + + " List ext;\n" + + " \n" + + " numbers= (List) objects; // correct - cast error\n" + + " ext= (List) objects; // wrong, should fail\n" + + "\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List objects, List raw) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " numbers= (List) objects; // correct - cast error\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " ext= (List) objects; // wrong, should fail\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91696 + public void test0611() { + this.runConformTest( + new String[] { + "C.java", + "import java.io.Serializable;\n" + + "\n" + + "interface A, S extends A.BS> {\n" + + " public interface BS extends Serializable {\n" + + " }\n" + + " public interface BK extends Serializable {\n" + + " public void put(SS a);\n" + + " }\n" + + "\n" + + " public P getP();\n" + + "}\n" + + "\n" + + "class P, S extends A.BS> {\n" + + " K k;\n" + + " S s;\n" + + "\n" + + " public void put() {\n" + + " k.put(s);\n" + + " }\n" + + "}\n" + + "\n" + + "public class C implements A {\n" + + " public static class K implements A.BK {\n" + + " public void put(S a) {\n" + + " }\n" + + " }\n" + + " protected static class S implements A.BS {\n" + + " }\n" + + "\n" + + " public P getP() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0612() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class MPair {}\n" + + "\n" + + "public class X {\n" + + " private static class Bucket extends LinkedList> {}\n" + + " private Bucket[] buckets = new X.Bucket[100];\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " private static class Bucket extends LinkedList> {}\n" + + " ^\n" + + "Cannot make a static reference to the non-static type K\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " private static class Bucket extends LinkedList> {}\n" + + " ^\n" + + "Cannot make a static reference to the non-static type V\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " private Bucket[] buckets = new X.Bucket[100];\n" + + " ^^^^^^^\n" + + "The field X.buckets is never read locally\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 + public void test0613() { + this.runNegativeTest( + new String[] { + "Map.java", + "package xy;\n" + + "import xy.Map.Entry;\n" + + "\n" + + "class Map {\n" + + " class Entry { }\n" + + "}\n" + + "class User {\n" + + " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " void b(Entry e) { } // OK\n" + + " void d(Map.Entry e) { } // OK\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Map.java (at line 8)\n" + + " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + + " ^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "2. ERROR in Map.java (at line 9)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "3. WARNING in Map.java (at line 10)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0614() { + this.runNegativeTest( + new String[] { + "X1.java", + "class X1 {\n" + + " static class X2 {\n" + + " class X3 {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y1 {\n" + + " class Y2 extends X1.X2 {\n" + + " void foo() {\n" + + " X3 x;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X1.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0615() { + this.runNegativeTest( + new String[] { + "X1.java", + "class X1 {\n" + + " static class X2 {\n" + + " class X3 {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y1 {\n" + + " class Y2 extends X1.X2 {\n" + + " void foo() {\n" + + " X3 x;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X1.java (at line 8)\n" + + " class Y2 extends X1.X2 {\n" + + " ^^^^^\n" + + "X1.X2 is a raw type. References to generic type X1.X2 should be parameterized\n" + + "----------\n" + + "2. ERROR in X1.java (at line 10)\n" + + " X3 x;\n" + + " ^^\n" + + "The member type X1.X2.X3 must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0616() { + this.runNegativeTest( + new String[] { + "Map.java", + "package xy;\n" + + "import xy.Map.Entry;\n" + + "\n" + + "class Map {\n" + + " class Entry { }\n" + + "}\n" + + "class User extends Map {\n" + + " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " void b(Entry e) { } // OK\n" + + " void d(Map.Entry e) { } // OK\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Map.java (at line 9)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "2. WARNING in Map.java (at line 10)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } +public void test0617() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo() {\n" + + " String s = null;\n" + + " ZZZ1.ZZZ2.ZZZ3 var = null;\n" + + " s = var;\n" + + " }\n" + + "}\n" + + "\n" + + "class ZZZ1 {\n" + + " class ZZZ2 {\n" + + " class ZZZ3 {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " s = var;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from ZZZ1.ZZZ2.ZZZ3 to String\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0618() { + this.runNegativeTest( + new String[] { + "Map.java", + "class Map {\n" + + " class Entry { }\n" + + " class Foo {\n" + + " Entry entry;\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " }\n" + + " static class Bar {\n" + + " Entry entry; // invalid static ref\n" + + " }\n" + + " void a(Entry e) { } // OK\n" + + " void c(Map.Entry e) { } // illegal \n" + + " void b(Entry e) { } // OK\n" + + " void d(Map.Entry e) { } // OK\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Map.java (at line 5)\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The method foo cannot be declared static; static methods can only be declared in a static or top level type\n" + + "----------\n" + + "2. ERROR in Map.java (at line 5)\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Entry\n" + + "----------\n" + + "3. ERROR in Map.java (at line 8)\n" + + " Entry entry; // invalid static ref\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Entry\n" + + "----------\n" + + "4. ERROR in Map.java (at line 11)\n" + + " void c(Map.Entry e) { } // illegal \n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "5. WARNING in Map.java (at line 12)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89440 + public void test0619() { + this.runConformTest( + new String[] { + "X.java", + "interface ISample {\n" + + " public static enum Stuff {\n" + + " FIRST, SECOND, THIRD\n" + + " };\n" + + "}\n" + + "\n" + + "class SampleClass {\n" + + " public void doSomething(ISample.Stuff thing) {\n" + + "\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public void doSomething() {\n" + + " SampleClass sample = new SampleClass();\n" + + " sample.doSomething(ISample.Stuff.FIRST);\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 + public void test0620() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner { }\n" + + " \n" + + " static void test(Inner i) { }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Outer.java (at line 4)\n" + + " static void test(Inner i) { }\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Inner\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551- variation + public void test0621() { + this.runConformTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner { }\n" + + " \n" + + " static void test(Inner i) { }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - variation + public void test0622() { + this.runConformTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " static class Inner { }\n" + + " \n" + + " static void test(Inner i) { }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - variation + public void test0623() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Outer {\n" + + " class Inner { }\n" + + " static void test(Inner i) { }\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83034 + public void test0624() { + this.runConformTest( + new String[] { + "X.java", + " interface IFoo> {\n" + + " V bar(int i);\n" + + "}\n" + + "\n" + + "public class X> {\n" + + " \n" + + " public boolean foo(X x) {\n" + + " return false;\n" + + " }\n" + + " public boolean baz(IFoo f) {\n" + + " return foo(f.bar(0));\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83034 - variation + public void test0625() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " public enum Mode {\n" + + " A\n" + + " };\n" + + " public void test(Mode mode) {\n" + + " }\n" + + "} \n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Keys {\n" + + " B\n" + + " };\n" + + " public void test() {\n" + + " Foo foo = new Foo();\n" + + " foo.test(Foo.Mode.A); // error\n" + + " }\n" + + "} \n", + }, + "", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92037 + public void test0626() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static class A {\n" + + "\n" + + " }\n" + + "\n" + + " private static class B {\n" + + "\n" + + " }\n" + + "\n" + + " private static class AA extends A {\n" + + "\n" + + " }\n" + + "\n" + + " private static class C extends B {\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " B b = new B();\n" + + " System.out.println(b instanceof C);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " private static class B {\n" + + " ^\n" + + "The type parameter A is hiding the type X.A\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " private static class AA extends A {\n" + + " ^^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " private static class C extends B {\n" + + " ^\n" + + "Access to enclosing constructor X.B() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "4. ERROR in X.java (at line 21)\n" + + " System.out.println(b instanceof C);\n" + + " ^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types X.B and X.C\n" + + "----------\n"); + } + public void test0627() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " List foo(List l1, List l2) {\n" + + " return l1;\n" + + " }\n" + + " void bar(List l1, List l2) {\n" + + " String s = foo(l1, l2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = foo(l1, l2);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to String\n" + + "----------\n"); + } + // check capture for conditional operator + public void test0628() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " List foo(List l1, List l2) {\n" + + " return l1;\n" + + " }\n" + + " void bar(List l1, List l2) {\n" + + " List l3 = null;\n" + + " String s = l1 != null ? foo(l1, l2) : l3;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = l1 != null ? foo(l1, l2) : l3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to String\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=92556 + public void test0629() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public abstract class Context {\n" + + " private Strategy> strategy;\n" + + " public void setStrategy(Strategy> strategy) {\n" + + " this.strategy = strategy;\n" + + " }\n" + + " // m?thode qui utilise la strat?gie\n" + + " public N call() throws Exception {\n" + + " return this.strategy.call(this);\n" + + " }\n" + + " }\n" + + " public interface Strategy> {\n" + + " public abstract N call(C context);\n" + + " }\n" + + "\n" + + "} \n", + }, + ""); + } + public void test0630() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + "\n" + + " void test0() {\n" + + " List arrays= new ArrayList();\n" + + " Number[] a= null;\n" + + " arrays.add(null);\n" + + " arrays.add(a); // Error: The method add(capture-of ? super Number[]) in the type List is not applicable for the arguments (Number[])\n" + + " }\n" + + "\n" + + " void test01() {\n" + + " List arrays= new ArrayList();\n" + + " Number[] a= null;\n" + + " arrays.add(null);\n" + + " arrays.add(a); // Error: The method add(capture-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + + " }\n" + + " \n" + + " void test02() {\n" + + " List nums= null;\n" + + " Number n= null;\n" + + " nums.add(null);\n" + + " nums.add(n);\n" + + " }\n" + + "\n" + + " void test3() {\n" + + " List> nums= null;\n" + + " List n= null;\n" + + " nums.add(null);\n" + + " nums.add(n);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " arrays.add(a); // Error: The method add(capture-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + + " ^^^\n" + + "The method add(capture#4-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93044 + public void test0631() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "public class X\n" + + "{\n" + + " public static void main(String[] args)\n" + + " {\n" + + " Class> c = RetentionPolicy.class;\n" + + " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + + " ^^^^^^^\n" + + "Bound mismatch: The generic method valueOf(Class, String) of type Enum is not applicable for the arguments (Class>, String). The inferred type capture#1-of ? extends Enum is not a valid substitute for the bounded parameter >\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982 + public void test0632() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " void test01() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + " void test02() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + " void test3() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + " void test4() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#3-of ? extends Object[]) in the type Vector is not applicable for the arguments (capture#4-of ? extends Object[])\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#5-of ? super Object[]) in the type Vector is not applicable for the arguments (capture#6-of ? super Object[])\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#7-of ? extends Object[]) in the type Vector is not applicable for the arguments (capture#8-of ? super Object[])\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982 - variation + public void test0633() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " void test1() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0)); \n" + + " foo(rhs.get(0)); // ok #foo(Object[])\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90775 + public void test0634() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.reflect.Array;\n" + + "\n" + + "public class X {\n" + + "\n" + + " T[] theArray;\n" + + "\n" + + " public X(Class clazz) {\n" + + " theArray = (T[]) Array.newInstance(clazz, 10); // Compiler warning\n" + + " }\n" + + "\n" + + " public T get(int i) {\n" + + " return theArray[i];\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X t = new X(Integer.class);\n" + + " // GenericsArray1 t = new GenericsArray1( int.class );\n" + + " Object[] o = t.theArray;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " theArray = (T[]) Array.newInstance(clazz, 10); // Compiler warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93298 + public void test0635() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "public class X {\n" + + " public static class Indexed {\n" + + " public Iterator foo() {\n" + + " return new IndexedIter();\n" + + " }\n" + + " class IndexedIter implements Iterator {\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + " public U next() {\n" + + " return null;\n" + + " }\n" + + " public void remove() {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=78084 + public void test0636() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public final T element() {\n" + + " T result = (T) customElement(); // reports unnecessary cast\n" + + " return result;\n" + + " }\n" + + " protected abstract Object customElement();\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T result = (T) customElement(); // reports unnecessary cast\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84968 + public void test0637() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final class Ex1 extends Exception {\n" + + " private static final long serialVersionUID = 1;\n" + + " }\n" + + "\n" + + " private void a1() {\n" + + " try {\n" + + " a1_1();\n" + + " } catch (Ex1 si) {\n" + + " assert si != null;\n" + + " }\n" + + " }\n" + + "\n" + + " protected Object a1_1() throws Ex1 {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void a2() {\n" + + " try {\n" + + " a2_1();\n" + + " } catch (Ex2 si) {\n" + + " assert si != null;\n" + + " }\n" + + " }\n" + + "\n" + + " protected Object a2_1() throws Ex2 {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public final static class Ex3 extends Exception {\n" + + " private static final long serialVersionUID = 1;\n" + + " }\n" + + "\n" + + " private void a3() {\n" + + " try {\n" + + " a3_1();\n" + + " } catch (Ex3 si) {\n" + + " assert si != null;\n" + + " }\n" + + " }\n" + + "\n" + + " protected Object a3_1() throws Ex3 {\n" + + " return null;\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "final class Ex2 extends Exception {\n" + + " private static final long serialVersionUID = 1;\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93478 + public void test0638() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.concurrent.BlockingQueue;\n" + + "\n" + + "public class X {\n" + + " static interface IMX {\n" + + " void call(L a, S b);\n" + + " }\n" + + " static interface Y {\n" + + " void addX(final IMX a);\n" + + " void removeX(final IMX a);\n" + + " }\n" + + " static final class Pair {\n" + + " T first;\n" + + "\n" + + " V second;\n" + + " }\n" + + " static class Bar

{\n" + + " Bar(final BlockingQueue

a) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "final class Foo extends X.Bar> implements X.IMX {\n" + + " Foo(final BlockingQueue> in) {\n" + + " super(in);\n" + + " }\n" + + " public void call(L a, S b) {\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0639() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + " \n" + + " U getAnnotation(Class annotatedType) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0640() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + " \n" + + " U getAnnotation(Class annotatedType) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0641() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = method.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = field.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = packge.getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n"); + } + public void test0642() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = method.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = field.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = packge.getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + "}\n", + }, + ""); + } + public void test0643() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " static U foo(U u) {\n" + + " return u;\n" + + " }\n" + + " \n" + + " void bar(X x) {\n" + + " String str = x.foo(\"hello\");\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0644() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " U foo(U u) {\n" + + " return u;\n" + + " }\n" + + " \n" + + " void bar(X x) {\n" + + " String str = x.foo(\"hello\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " String str = x.foo(\"hello\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " String str = x.foo(\"hello\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to String\n" + + "----------\n"); + } + public void test0645() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "\n" + + "class X {\n" + + " void bar(XClass arg) {\n" + + " XClass xc = new XClass();\n" + + " String str = xc.getConstructor().getAnnotation(arg);\n" + + " }\n" + + "}\n" + + "\n" + + "class XClass {\n" + + " XConstructor getConstructor() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class XConstructor {\n" + + " W getAnnotation(XClass cl) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " XClass xc = new XClass();\n" + + " ^^^^^^\n" + + "XClass is a raw type. References to generic type XClass should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " XClass xc = new XClass();\n" + + " ^^^^^^\n" + + "XClass is a raw type. References to generic type XClass should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " String str = xc.getConstructor().getAnnotation(arg);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(XClass) belongs to the raw type XConstructor. References to generic type XConstructor should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " String str = xc.getConstructor().getAnnotation(arg);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to String\n" + + "----------\n"); + } + public void test0646() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " X x = inner.setOuterT(new X());\n" + + " \n" + + " Outer.Inner innerS = inner;\n" + + " }\n" + + "}\n" + + "\n" + + "class Outer {\n" + + " T t;\n" + + " class Inner {\n" + + " T setOuterT(T t1) {\n" + + " t = t1;\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " X x = inner.setOuterT(new X());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setOuterT(Object) belongs to the raw type Outer.Inner. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " X x = inner.setOuterT(new X());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " Outer.Inner innerS = inner;\n" + + " ^^^^^\n" + + "Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer.Inner\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 + public void test0647() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " X x = inner.set(new X());\n" + + " \n" + + " Outer.Inner innerS = inner;\n" + + " }\n" + + "}\n" + + "\n" + + "class Outer {\n" + + " T t;\n" + + " static class Inner {\n" + + " U set(U u) {\n" + + " return u;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " X x = inner.set(new X());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method set(Object) belongs to the raw type Outer.Inner. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " X x = inner.set(new X());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " Outer.Inner innerS = inner;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The member type Outer.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Outer\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - variation + public void test0648() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Outer.Inner inner = new Sub().get();\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class Outer {\n" + + " class Inner {\n" + + " }\n" + + "}\n" + + "class Sub extends Outer {\n" + + " Inner get() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Sub().get();\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class Sub extends Outer {\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " Inner get() { return null; }\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - variation + public void test0649() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Outer.Inner inner = new Sub().get();\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class Outer {\n" + + " class Inner {\n" + + " }\n" + + "}\n" + + "class Sub extends Outer {\n" + + " Inner get() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Sub().get();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer.Inner\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class Sub extends Outer {\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " Inner get() { return null; }\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89440 + public void test0650() { + this.runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "\n" + + "public interface A {\n" + + " public static enum Stuff {\n" + + " FIRST, SECOND, THIRD\n" + + " };\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "q/SampleClass2.java", + "package q;\n" + + "\n" + + "import p.A.Stuff;\n" + + "\n" + + "public class SampleClass2 {\n" + + " public void doSomething(Stuff thing) {\n" + + " \n" + + " }\n" + + "}" + }, + "", + null, + false, + null); + this.runConformTest( + new String[] { + "q/SampleClass3.java", + "package q;\n" + + "\n" + + "import p.A;\n" + + "\n" + + "public class SampleClass3 {\n" + + " public void doSomething() {\n" + + " SampleClass2 sample = new SampleClass2();\n" + + " sample.doSomething(A.Stuff.FIRST);\n" + + " }\n" + + "}", + }, + "", + null, + false, + null); + } + public void test0651() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " int field;\n" + + " static int FIELD;\n" + + "\n" + + " {\n" + + " field = 1;\n" + + " }\n" + + " static {\n" + + " FIELD = 1;\n" + + " }\n" + + "\n" + + " public Values foo(Box box) {\n" + + " return selectedValues(box.getValues()); // 1\n" + + " }\n" + + " public static Values selectedValues(Values v) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "abstract class Box { // Added bound for V\n" + + " abstract Values getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + JavacTestOptions.EclipseHasABug.EclipseBug236217); + } + public void test0652() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Collection c = new HashSet();\n" + + " Set s = (Set)c;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0653() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " static public void workaround(T a, T b) {\n" + + " a.addAll(b);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " static public void workaround(T a, T b) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " a.addAll(b);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The method addAll(Collection) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0654() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map myMap = new HashMap();\n" + + " myMap.put(\"key1\", \"1\");\n" + + "\n" + + " for (Map.Entry e : myMap.entrySet())\n" + + " System.out.println(\"Key = \" + e.getKey() + \" Value = \" + e.getValue());\n" + + " Set set = myMap.entrySet();\n" + + " for (Map.Entry e : set)\n" + + " System.out.println(\"Key = \" + e.getKey() + \" Value = \" + e.getValue());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Map myMap = new HashMap();\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Map myMap = new HashMap();\n" + + " ^^^^^^^\n" + + "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " myMap.put(\"key1\", \"1\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " for (Map.Entry e : myMap.entrySet())\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " for (Map.Entry e : myMap.entrySet())\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to Map.Entry\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " Set set = myMap.entrySet();\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " Set set = myMap.entrySet();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set needs unchecked conversion to conform to Set\n" + + "----------\n" + + "8. WARNING in X.java (at line 11)\n" + + " for (Map.Entry e : set)\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } +// ** +public void test0655() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class BB { }\n" + + " static class BD extends BB { }\n" + + " void f() {\n" + + " BB bb = null;\n" + + " Object o = (BD) bb;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Object o = (BD) bb;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.BB to X.BD\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " Object o = (BD) bb;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X.BB to X.BD\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0656() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " protected Vector v = null;\n" + + "\n" + + " public void f() {\n" + + " ((String) (v.elementAt(0))).charAt(0);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +public void test0657() { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " \n" + + " private static class GenericWrapper {\n" + + " private Elem theObject;\n" + + " public GenericWrapper(Elem arg) {\n" + + " theObject = arg;\n" + + " }\n" + + " public GenericWrapper (GenericWrapper other) {\n" + + " this.theObject = other.theObject;\n" + + " }\n" + + " public String toString() {\n" + + " return theObject.toString();\n" + + " }\n" + + " }\n" + + " private static GenericWrapper method (Object wrappedString) {\n" + + " return (GenericWrapper) wrappedString;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(method(new GenericWrapper(\"abc\")));\n" + + " System.out.println(method(new GenericWrapper(new Exception())));\n" + + " }\n" + + "}\n", + }, + "abcjava.lang.Exception"); +} +public void test0658() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " \n" + + " private static class GenericWrapper {\n" + + " Zork z;\n" + + " private Elem theObject;\n" + + " public GenericWrapper(Elem arg) {\n" + + " theObject = arg;\n" + + " }\n" + + " public GenericWrapper (GenericWrapper other) {\n" + + " this.theObject = other.theObject;\n" + + " }\n" + + " public String toString() {\n" + + " return theObject.toString();\n" + + " }\n" + + " }\n" + + " private static GenericWrapper method (Object wrappedString) {\n" + + " return (GenericWrapper) wrappedString;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(method(new GenericWrapper(\"abc\")));\n" + + " System.out.println(method(new GenericWrapper(new Exception())));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " public String toString() {\n" + + " ^^^^^^^^^^\n" + + "The method toString() of type X.GenericWrapper should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " return (GenericWrapper) wrappedString;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to X.GenericWrapper\n" + + "----------\n"); +} +public void test0659() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.ref.*;\n" + + "\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X extends WeakReference {\n" + + " Zork z;\n" + + " static ReferenceQueue queue = new ReferenceQueue();\n" + + "\n" + + " private K key;\n" + + "\n" + + " public X(K key, V value, ReferenceQueue queue) {\n" + + " super(value, queue);\n" + + " }\n" + + "\n" + + " public K getKey() {\n" + + " return key;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"key:\" + key;\n" + + " }\n" + + "\n" + + " public static void main(String[] arg) throws Exception {\n" + + " X ref = new X(\"Dummy Key\", new Integer(5), queue);\n" + + " new Thread() {\n" + + " @Override\n" + + " public void run() {\n" + + " for (;;) {\n" + + " // force ref to be cleared\n" + + " System.gc();\n" + + " }\n" + + " }\n" + + " }.start();\n" + + "\n" + + " X fromQueue = (X) queue.remove();\n" + + " System.out.println(fromQueue);\n" + + " System.exit(0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 34)\n" + + " X fromQueue = (X) queue.remove();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Reference to X\n" + + "----------\n"); +} +public void test0660() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " boolean run(X x) {\n" + + " return false;\n" + + " }\n" + + " void run(Class ct) {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " boolean b = new X().run(new X(){});\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 +public void test0661() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public X() {\n" + + " S a = (S)(Integer)3;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " S a = (S)(Integer)3;\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Integer to S\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation +public void test0662() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public X() {\n" + + " S a = (S)(Integer)3; // this should fail\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " S a = (S)(Integer)3; // this should fail\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from Integer to S\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation +public void test0663() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " Object foo(Comparable c) {\n" + + " return (Comparable) c;\n" + + " }\n" + + " void foo(List lv) {\n" + + " List l = (List) lv;\n" + + " }\n" + + " void foo2(List> lv) {\n" + + " List l = (List>) lv;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return (Comparable) c;\n" + + " ^\n" + + "S cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " List l = (List) lv;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " List l = (List) lv;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " List l = (List) lv;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " List l = (List>) lv;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " List l = (List>) lv;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List> to List>\n" + + "----------\n" + + "7. WARNING in X.java (at line 11)\n" + + " List l = (List>) lv;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List> to List>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation +public void test0664() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public X(X2 x2) {\n" + + " S a = (S)x2;\n" + + " }\n" + + "}\n" + + "abstract class X2 implements Comparable {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " S a = (S)x2;\n" + + " ^^^^^\n" + + "Cannot cast from X2 to S\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation +public void test0665() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void foo() {\n" + + " A a = new A();\n" + + " Comparable c = (Comparable) a; // Fails as expected\n" + + " Comparable c2 = (Comparable) a; // Should fail?\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "final class A implements Comparable {\n" + + " public int compareTo(A o) {\n" + + " return 0;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " Comparable c = (Comparable) a; // Fails as expected\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from A to Comparable\n" + + "----------\n" + + "2. WARNING in Test.java (at line 5)\n" + + " Comparable c2 = (Comparable) a; // Should fail?\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from A to Comparable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89940 +public void test0666() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List objects, List raw) {\n" + + "\n" + + " List numbers;\n" + + " List ext;\n" + + " \n" + + " numbers= (List) objects; // correct - cast error\n" + + " ext= (List) objects; // wrong, should fail\n" + + "\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List objects, List raw) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " numbers= (List) objects; // correct - cast error\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " ext= (List) objects; // wrong, should fail\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +public void _test0667() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void foo(List l) { }\n" + + " \n" + + " public static void foo2(List l) { }\n" + + " \n" + + " public static void foo3(List l) { }\n" + + " \n" + + " public static void bar(List l) { }\n" + + " \n" + + " public static void bar2(List l) { }\n" + + " \n" + + " public static void bar3(List l) { }\n" + + " \n" + + " public static void bar4(List l) { }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " { // can be { Object, Object[] }\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [01]\n" + + " l.add((Object) null); // illegal [02]\n" + + " l.add((Integer) null); // illegal [03]\n" + + " l.add((Object []) null); // illegal [04]\n" + + " l.add((Integer []) null); // illegal [05]\n" + + " l.add((Integer [][]) null); // illegal [06]\n" + + " \n" + + " foo(l); // List - legal [07]\n" + + " foo2(l); // List - illegal [08]\n" + + " foo3(l); // List - illegal [09]\n" + + " bar(l); // List - illegal [10]\n" + + " bar2(l); // List - illegal [11]\n" + + " bar3(l); // List - legal [12]\n" + + " bar4(l); // List - legal [13]\n" + + " }\n" + + " { // can be Object[] or (? extends Object)[]\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // legal [14]\n" + + " l.add((Object) null); // illegal [15]\n" + + " l.add((Integer) null); // illegal [16]\n" + + " l.add((Object []) null); // legal [17]\n" + + " l.add((Integer []) null); // legal [18]\n" + + " l.add((Integer [][]) null); // legal [19]\n" + + " \n" + + " foo(l); // List - legal [20]\n" + + " foo2(l); // List - legal [21]\n" + + " foo3(l); // List - legal [22]\n" + + " bar(l); // List - illegal [23]\n" + + " bar2(l); // List - illegal [24]\n" + + " bar3(l); // List - legal [25]\n" + + " bar4(l); // List - legal [26]\n" + + " }\n" + + " { // Only allows wildcards, Object is illegal.\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [27]\n" + + " l.add((Object) null); // illegal [28]\n" + + " l.add((Integer) null); // illegal [29]\n" + + " l.add((Object []) null); // illegal [30]\n" + + " l.add((Integer []) null); // illegal [31]\n" + + " l.add((Integer [][]) null); // illegal [32]\n" + + " \n" + + " foo(l); // List - illegal [33]\n" + + " foo2(l); // List - illegal [34]\n" + + " foo3(l); // List - legal [35]\n" + + " bar(l); // List - illegal [36]\n" + + " bar2(l); // List - illegal [37]\n" + + " bar3(l); // List - legal [38]\n" + + " bar4(l); // List - legal [39]\n" + + " }\n" + + " { // can add non-arrays but can only match ? super Object, ? super Object[], or ? extends Object, but not Object \n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // legal [40]\n" + + " l.add((Object) null); // legal [41]\n" + + " l.add((Integer) null); // legal [42]\n" + + " l.add((Object []) null); // illegal [43]\n" + + " l.add((Integer []) null); // illegal [44]\n" + + " l.add((Integer [][]) null); // illegal [45]\n" + + " \n" + + " foo(l); // legal [46]\n" + + " foo2(l); // illegal [47]\n" + + " foo3(l); // illegal [48]\n" + + " bar(l); // legal [49]\n" + + " bar2(l); // illegal [50]\n" + + " bar3(l); // legal [51]\n" + + " bar4(l); // legal [52]\n" + + " }\n" + + " { // can add array but cannot call a method which expects an array. 100% !\n" + + " List l = new ArrayList();\n" + + " l.get(0).toString();\n" + + " l.add(l.get(0)); // legal [53]\n" + + " l.add((Object) null); // legal [54]\n" + + " l.add((Integer) null); // legal [55]\n" + + " l.add((Object []) null); // legal [56]\n" + + " l.add((Integer []) null); // legal [57]\n" + + " l.add((Integer [][]) null); // legal [58]\n" + + " \n" + + " foo(l); // legal [59]\n" + + " foo2(l); // illegal [60]\n" + + " foo3(l); // illegal [61]\n" + + " bar(l); // legal [62]\n" + + " bar2(l); // legal [63]\n" + + " bar3(l); // legal [64]\n" + + " bar4(l); // legal [65]\n" + + " }\n" + + " { // cannot add any type but can match ? or ? extends Object.\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [66]\n" + + " l.add((Object) null); // illegal [67]\n" + + " l.add((Integer) null); // illegal [68]\n" + + " l.add((Object []) null); // illegal [69]\n" + + " l.add((Integer []) null); // illegal [70]\n" + + " l.add((Integer [][]) null); // illegal [71]\n" + + " \n" + + " foo(l); // List - illegal [72]\n" + + " foo2(l); // List - illegal [73]\n" + + " foo3(l); // List - illegal [74]\n" + + " bar(l); // List - illegal [75]\n" + + " bar2(l); // List - illegal [76]\n" + + " bar3(l); // List - legal [77]\n" + + " bar4(l); // List - legal [78]\n" + + " }\n" + + " { // same as ? extends Object.\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [79]\n" + + " l.add((Object) null); // illegal [80]\n" + + " l.add((Integer) null); // illegal [81]\n" + + " l.add((Object []) null); // illegal [82]\n" + + " l.add((Integer []) null); // illegal [83]\n" + + " l.add((Integer [][]) null); // illegal [84]\n" + + " \n" + + " foo(l); // List - illegal [85]\n" + + " foo2(l); // List - illegal [86]\n" + + " foo3(l); // List - illegal [87]\n" + + " bar(l); // List - illegal [88]\n" + + " bar2(l); // List - illegal [89]\n" + + " bar3(l); // List - legal [90]\n" + + " bar4(l); // List - legal [91]\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " l.add(l.get(0)); // illegal [01]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (capture-of ? super Object[])\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " l.add((Object) null); // illegal [02]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " l.add((Integer) null); // illegal [03]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "4. ERROR in X.java (at line 24)\n" + + " l.add((Object []) null); // illegal [04]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "5. ERROR in X.java (at line 25)\n" + + " l.add((Integer []) null); // illegal [05]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "6. ERROR in X.java (at line 26)\n" + + " l.add((Integer [][]) null); // illegal [06]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "7. ERROR in X.java (at line 28)\n" + + " foo(l); // List - legal [07]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "8. ERROR in X.java (at line 29)\n" + + " foo2(l); // List - illegal [08]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "9. ERROR in X.java (at line 30)\n" + + " foo3(l); // List - illegal [09]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "10. ERROR in X.java (at line 31)\n" + + " bar(l); // List - illegal [10]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "11. ERROR in X.java (at line 32)\n" + + " bar2(l); // List - illegal [11]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "12. ERROR in X.java (at line 39)\n" + + " l.add((Object) null); // illegal [15]\n" + + " ^^^\n" + + "The method add(Object[]) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "13. ERROR in X.java (at line 40)\n" + + " l.add((Integer) null); // illegal [16]\n" + + " ^^^\n" + + "The method add(Object[]) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "14. ERROR in X.java (at line 48)\n" + + " bar(l); // List - illegal [23]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "15. ERROR in X.java (at line 49)\n" + + " bar2(l); // List - illegal [24]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "16. ERROR in X.java (at line 55)\n" + + " l.add(l.get(0)); // illegal [27]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (capture-of ? extends Object[])\n" + + "----------\n" + + "17. ERROR in X.java (at line 56)\n" + + " l.add((Object) null); // illegal [28]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "18. ERROR in X.java (at line 57)\n" + + " l.add((Integer) null); // illegal [29]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "19. ERROR in X.java (at line 58)\n" + + " l.add((Object []) null); // illegal [30]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "20. ERROR in X.java (at line 59)\n" + + " l.add((Integer []) null); // illegal [31]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "21. ERROR in X.java (at line 60)\n" + + " l.add((Integer [][]) null); // illegal [32]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "22. ERROR in X.java (at line 62)\n" + + " foo(l); // List - illegal [33]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "23. ERROR in X.java (at line 63)\n" + + " foo2(l); // List - illegal [34]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "24. ERROR in X.java (at line 65)\n" + + " bar(l); // List - illegal [36]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "25. ERROR in X.java (at line 66)\n" + + " bar2(l); // List - illegal [37]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "26. ERROR in X.java (at line 75)\n" + + " l.add((Object []) null); // illegal [43]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "27. ERROR in X.java (at line 76)\n" + + " l.add((Integer []) null); // illegal [44]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "28. ERROR in X.java (at line 77)\n" + + " l.add((Integer [][]) null); // illegal [45]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "29. ERROR in X.java (at line 79)\n" + + " foo(l); // legal [46]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "30. ERROR in X.java (at line 80)\n" + + " foo2(l); // illegal [47]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "31. ERROR in X.java (at line 81)\n" + + " foo3(l); // illegal [48]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "32. ERROR in X.java (at line 83)\n" + + " bar2(l); // illegal [50]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "33. ERROR in X.java (at line 98)\n" + + " foo2(l); // illegal [60]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "34. ERROR in X.java (at line 99)\n" + + " foo3(l); // illegal [61]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "35. ERROR in X.java (at line 107)\n" + + " l.add(l.get(0)); // illegal [66]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (capture-of ? extends Object)\n" + + "----------\n" + + "36. ERROR in X.java (at line 108)\n" + + " l.add((Object) null); // illegal [67]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "37. ERROR in X.java (at line 109)\n" + + " l.add((Integer) null); // illegal [68]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "38. ERROR in X.java (at line 110)\n" + + " l.add((Object []) null); // illegal [69]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "39. ERROR in X.java (at line 111)\n" + + " l.add((Integer []) null); // illegal [70]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "40. ERROR in X.java (at line 112)\n" + + " l.add((Integer [][]) null); // illegal [71]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "41. ERROR in X.java (at line 114)\n" + + " foo(l); // List - illegal [72]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "42. ERROR in X.java (at line 115)\n" + + " foo2(l); // List - illegal [73]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "43. ERROR in X.java (at line 116)\n" + + " foo3(l); // List - illegal [74]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "44. ERROR in X.java (at line 117)\n" + + " bar(l); // List - illegal [75]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "45. ERROR in X.java (at line 118)\n" + + " bar2(l); // List - illegal [76]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "46. ERROR in X.java (at line 124)\n" + + " l.add(l.get(0)); // illegal [79]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (capture-of ?)\n" + + "----------\n" + + "47. ERROR in X.java (at line 125)\n" + + " l.add((Object) null); // illegal [80]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "48. ERROR in X.java (at line 126)\n" + + " l.add((Integer) null); // illegal [81]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "49. ERROR in X.java (at line 127)\n" + + " l.add((Object []) null); // illegal [82]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "50. ERROR in X.java (at line 128)\n" + + " l.add((Integer []) null); // illegal [83]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "51. ERROR in X.java (at line 129)\n" + + " l.add((Integer [][]) null); // illegal [84]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "52. ERROR in X.java (at line 131)\n" + + " foo(l); // List - illegal [85]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "53. ERROR in X.java (at line 132)\n" + + " foo2(l); // List - illegal [86]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "54. ERROR in X.java (at line 133)\n" + + " foo3(l); // List - illegal [87]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "55. ERROR in X.java (at line 134)\n" + + " bar(l); // List - illegal [88]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "56. ERROR in X.java (at line 135)\n" + + " bar2(l); // List - illegal [89]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n"); +} +public void test0668() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.List;\n" + + " \n" + + "public class X {\n" + + " void foo(List l) {\n" + + " l.add(new Object[0]);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95289 +public void test0669() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "private static int indexOf(final T[] array,final T elem) {\n" + + " return 0;\n" + + "}\n" + + "public static void meth(AContainer ac, AInfo[] aiArray) {\n" + + " for(AInfo ai: aiArray) {\n" + + " int index1 = indexOf(ac.getAs(),ai.a);\n" + + " int index2 = indexOf(ac.getAs(),ai); // ai.class!=ai.a.class!!!\n" + + " }\n" + + "}\n" + + "}\n" + + "\n" + + "class AContainer {\n" + + " public A[] getAs(){ return null; }\n" + + "}\n" + + "\n" + + "class AInfo {\n" + + " public A a;\n" + + "}\n" + + "\n" + + "class A {\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 (ensure not even a warning) +public void test0670() { + runConformTest( + true, + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "interface MethodProperty> {\n" + + " public void copyFrom(ActualType other);\n" + + "}\n" + + "\n" + + "class MethodPropertyDatabase> {\n" + + " Map propertyMap;\n" + + " \n" + + " void read(String fileName) {\n" + + " }\n" + + "}\n" + + "\n" + + "class FooProperty implements MethodProperty {\n" + + " String value;\n" + + "\n" + + " public void copyFrom(FooProperty other) {\n" + + " this.value = other.value;\n" + + " }\n" + + "}\n" + + "\n" + + "class FooPropertyDatabase extends MethodPropertyDatabase {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " FooPropertyDatabase fooDatabase;\n" + + " \n" + + " public void readDatabase() {\n" + + " FooPropertyDatabase database = new FooPropertyDatabase();\n" + + " \n" + + " fooDatabase = readDatabase(database, \"foodatabase.db\"); // Bug reported on this line\n" + + " }\n" + + " \n" + + " private<\n" + + " Property extends MethodProperty,\n" + + " DatabaseType extends MethodPropertyDatabase\n" + + " > DatabaseType readDatabase(DatabaseType database, String fileName) {\n" + + " database.read(fileName);\n" + + " return database;\n" + + " }\n" + + " \n" + + "}\n", + }, + "", + null, + null, + JavacTestOptions.EclipseJustification.EclipseBug95021); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 - variation: ensure not even a warning +public void test0671() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "interface MethodProperty> {\n" + + " public void copyFrom(ActualType other);\n" + + "}\n" + + "\n" + + "class MethodPropertyDatabase> {\n" + + " Map propertyMap;\n" + + " \n" + + " void read(String fileName) {\n" + + " }\n" + + "}\n" + + "\n" + + "class FooProperty implements MethodProperty {\n" + + " String value;\n" + + "\n" + + " public void copyFrom(FooProperty other) {\n" + + " this.value = other.value;\n" + + " }\n" + + "}\n" + + "\n" + + "class FooPropertyDatabase extends MethodPropertyDatabase {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " FooPropertyDatabase fooDatabase;\n" + + " \n" + + " public void readDatabase() {\n" + + " FooPropertyDatabase database = new FooPropertyDatabase();\n" + + " \n" + + " fooDatabase = readDatabase(database, \"foodatabase.db\"); // Bug reported on this line\n" + + " }\n" + + " \n" + + " private<\n" + + " Property extends MethodProperty,\n" + + " DatabaseType extends MethodPropertyDatabase\n" + + " > DatabaseType readDatabase(DatabaseType database, String fileName) {\n" + + " database.read(fileName);\n" + + " return database;\n" + + " }\n" + + " \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 - variation: ensure not even a warning +public void test0672() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo> {\n" + + "}\n" + + "\n" + + "class Bar {\n" + + "}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " void readDatabase() {\n" + + " Bar bar = new Bar();\n" + + " read(bar, \"sadasd\");\n" + + " }\n" + + " \n" + + "

, D extends Bar

> \n" + + " D read(D d, String s) {\n" + + " return d;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " Bar bar = new Bar();\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " Bar bar = new Bar();\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " read(bar, \"sadasd\");\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation read(Bar, String) of the generic method read(D, String) of type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 +public void test0673() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "class Key> {\n" + + "}\n" + + "\n" + + "class State {\n" + + "}\n" + + "\n" + + "class Type> {\n" + + "}\n" + + "\n" + + "class Store, C extends Key, D extends State> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " List, ? extends State>> stores;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0674() { + this.runConformTest( + new String[] { + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X> {\n" + + " Store> store;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0675() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X {\n" + + " Store> store1;\n" + + " Store> store2;\n" + + "}\n", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " Store> store1;\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//check fault tolerance, in spite of bound mismatch, still pass param type for further resolving message send +public void test0676() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo(X xs) {\n" + + " xs.get().printStackTrace();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void foo(X xs) {\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " xs.get().printStackTrace();\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method printStackTrace() is undefined for the type String\n" + + "----------\n"); +} +public void test0677() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " {\n" + + " ArrayList arrayList = new ArrayList(); // compile error\n" + + " Number number = arrayList.get(0);\n" + + " }\n" + + " {\n" + + " ArrayList arrayList = new ArrayList(); //correct\n" + + " Number number = arrayList.get(0);\n" + + " }\n" + + " {\n" + + " ArrayList arrayList = new ArrayList();\n" + + " Object number = arrayList.get(0); //returns java.lang.Object\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " ArrayList arrayList = new ArrayList(); // compile error\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to ArrayList\n" + + "----------\n"); +} +public void test0678() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " \n" + + " X right1;\n" + + " X wrong1;\n" + + " X right2;\n" + + " \n" + + " static class Y implements Serializable {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot specify any additional bound Serializable when first bound is a type parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X wrong1;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type Serializable is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " static class Y implements Serializable {\n" + + " ^\n" + + "The serializable class Y does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0679() { + this.runConformTest( + new String[] { + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X> {\n" + + " Store> store;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0680() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "class Key, G extends Key, H extends State> {}\n" + + "class State {}\n" + + "class Type, V extends Key, W extends State> {}\n" + + "class Store, C extends Key, D extends State> {}\n" + + "\n" + + "public class X> {\n" + + " List, ? extends State>> stores;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0681() { + this.runConformTest( + new String[] { + "X.java", + "class Key> {\n" + + "}\n" + + "class Store> {\n" + + "}\n" + + "class X {\n" + + " Store store1;\n" + + " Store> store2;\n" + + "\n" + + " class StoreHolder > {\n" + + " Store store;\n" + + " }\n" + + "}\n" + + "class Y> {\n" + + " Y y;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95963 +public void test0682() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends A {}\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends A {}\n" + + " ^^^\n" + + "X.M cannot be resolved to a type\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96085 +public void test0683() { + this.runConformTest( + new String[] { + "P.java", + "public interface P {\n" + + " interface A {}\n" + + "}\n", + "P2.java", + "public class P2 implements P.A {\n" + + " P2(P.A problem) {}\n" + + "}\n", + "P3.java", + "public class P3 {\n" + + " void test() {P.A o = new P2((P.A) null);}\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "P3.java", + "class P3 {\n" + + " void test() {P.A o = new P2((P.A) null);}\n" + + "}\n", + }, + "", + null, + false, + null); +} +public void test0684() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " U foo(U u1, U u2) {\n" + + " return u1;\n" + + " }\n" + + " void bar(X x1, X x2) {\n" + + " X x = foo(x1, x2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x = foo(x1, x2);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +public void test0685() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " U foo(U u1, U u2) {\n" + + " return u1;\n" + + " }\n" + + " void bar(X x1, X x2) {\n" + + " X x = foo(x1, x2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x = foo(x1, x2);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0686() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other1;\n" + + " Other> other2; \n" + + " Other> other3; \n" + + " Other> other7 = other1;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Other> other2; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Other> other3; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0687() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other2;\n" + + " Other> other3;\n" + + " Other> other4;\n" + + " Other> other5;\n" + + " Other> other6;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Other> other3;\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Other> other4;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Other> other5;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " Other> other6;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0688() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other5;\n" + + "}\n", + }, + ""); +} +// check wildcard bounds wrt variable boundCheck +public void test0689() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other5;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Other> other5;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n"); +} +// check assignment rules across param types with wildcards +public void test0690() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List lr, List la) {\n" + + " lr = la;\n" + + " la = lr;\n" + + " }\n" + + "} \n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " lr = la;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); +} +// check that final class bound is more restrictive +public void test0691() { + this.runNegativeTest( + new String[] { + "XX.java", + "public class XX {\n" + + " void foo(XX lhs, XX rhs) {\n" + + " lhs = rhs;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in XX.java (at line 2)\n" + + " void foo(XX lhs, XX rhs) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends String is not a valid substitute for the bounded parameter of the type XX\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0692() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X> {\n" + + " \n" + + " void foo(X> x) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void foo(X> x) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +// bound checks +public void test0693() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X> x1;\n" + + " X x2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X> x1;\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " X> x1;\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " X x2;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends String is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); +} +// bound checks +public void test0694() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " X>> x1;\n" + + " X>> x2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X>> x1;\n" + + " ^\n" + + "Bound mismatch: The type X> is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " X>> x1;\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " X>> x1;\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " X>> x2;\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X> is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 3)\n" + + " X>> x2;\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 3)\n" + + " X>> x2;\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +// bound checks +public void test0695() { + this.runConformTest( + new String[] { + "I.java", + "interface I> {\n" + + "}\n", + }, + ""); +} +public void test0696() { + this.runNegativeTest( + new String[] { + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X {\n" + + " Store> store = new Store>();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Store> store = new Store>();\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Store> store = new Store>();\n" + + " ^^^\n" + + "Bound mismatch: The type Key is not a valid substitute for the bounded parameter > of the type Store\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Store> store = new Store>();\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n"); +} +public void test0697() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X> {\n" + + " V v;\n" + + " \n" + + " void foo(X x1, X x2) {\n" + + " String s =x1.v.get(0);\n" + + " Object o = x2.v.get(0);\n" + + " \n" + + " }\n" + + "}\n", + }, + ""); +} +public void test0698() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X, V extends List> {\n" + + " \n" + + " X x;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super Exception is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X x;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super Exception is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +public void test0699() { + this.runNegativeTest( + new String[] { + "X2.java", + "import java.util.List;\n" + + "class Other2> {\n" + + "}\n" + + "\n" + + "class X2 {\n" + + " Other2> other1;\n" + + " Other2> other2; \n" + + " Other2> other3; \n" + + " Other2> other7 = other1;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X2.java (at line 6)\n" + + " Other2> other1;\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + + "----------\n" + + "2. ERROR in X2.java (at line 7)\n" + + " Other2> other2; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + + "----------\n" + + "3. ERROR in X2.java (at line 8)\n" + + " Other2> other3; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96646 +public void test0700() { + this.runConformTest( + new String[] { + "X.java", + "abstract class BaseFactory {\n" + + " public T create() throws Exception {\n" + + " return getType().newInstance();\n" + + " }\n" + + " public abstract Class getType();\n" + + "}\n" + + "interface StringFactory {\n" + + " public String create() throws Exception;\n" + + "}\n" + + "public class X extends BaseFactory implements StringFactory {\n" + + " @Override\n" + + " public Class getType() {\n" + + " return String.class;\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " String emptyString = new X().create();\n" + + " System.out.printf(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 +public void test0701() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "class Deejay {\n" + + " class Counter {}\n" + + "\n" + + " Counter songCounter = new Counter();\n" + + " Counter genreCounter = new Counter();\n" + + "\n" + + " List> list1 = Arrays.asList(songCounter, genreCounter);\n" + + " List> list2 = Arrays.asList(songCounter, genreCounter);\n" + + " List> list3 = Arrays.>asList(songCounter, genreCounter);\n" + + " List> list4 = Arrays.asList(new Counter[] {songCounter, genreCounter});\n" + + " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + + "}\n" + + "class Genre {}\n" + + "class Song {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List> list1 = Arrays.asList(songCounter, genreCounter);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " List> list2 = Arrays.asList(songCounter, genreCounter);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation +public void test0702() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements Runnable {\n" + + " \n" + + " void foo0(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 0\n" + + " }\n" + + " void foo1(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 1\n" + // TODO (philippe) should be ok using capture rules for equivalence + " }\n" + + " void foo2(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 2\n" + + " }\n" + + " void foo3(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 3\n" + + " }\n" + + " void foo4(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 4\n" + + " }\n" + + " void foo5(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 5\n" + + " }\n" + + " void foo6(X>>>> lhs, X>>>> rhs) {\n" + + " lhs = rhs; // 6\n" + + " } \n" + + " public void run() {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " lhs = rhs; // 1\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " lhs = rhs; // 2\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " lhs = rhs; // 3\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " lhs = rhs; // 5\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n"); +} +public void test0703() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {}\n" + + "class Y extends X {\n" + + " X p = (Y)null;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97800 +public void test0704() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List l = (List)Collections.emptyList();\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " List l = (List)Collections.emptyList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97480 +public void test0705() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void f(Object o){\n" + + " ((Map.Entry)o).setValue(\"bug\");\n" + + " \n" + + " Map.Entry me= (Map.Entry)o; \n" + + " me.setValue(\"ok\");\n" + + " \n" + + " ((Vector)o).add(\"ok\");\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " ((Map.Entry)o).setValue(\"bug\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setValue(Object) belongs to the raw type Map.Entry. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " ((Map.Entry)o).setValue(\"bug\");\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " Map.Entry me= (Map.Entry)o; \n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Map.Entry me= (Map.Entry)o; \n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " me.setValue(\"ok\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setValue(Object) belongs to the raw type Map.Entry. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " ((Vector)o).add(\"ok\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " ((Vector)o).add(\"ok\");\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 +public void test0706() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " bb.test();\n" + + " ((AA) bb).test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + ""); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " bb.test();\n" + + " ((AA) bb).test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " bb.test();\r\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 +public void test0706a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " AA res1 = bb.test();\n" + + " AA res3 = bb.test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res1 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " AA res3 = bb.test();\n" + + " ^^\n" + + "AA is a raw type. References to generic type AA should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " AA res3 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + // 4: reference to test is ambiguous, both method test() in AA and method test() in BB match + // 5: reference to test is ambiguous, both method test() in AA and method test() in BB match + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 +public void test0706b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " AA res = bb.test();\n" + + " BB res2 = bb.test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " BB res2 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + // 4: reference to test is ambiguous, both method test() in AA and method test() in BB match + // 4: incompatible types on the assignment + // 5: reference to test is ambiguous, both method test() in AA and method test() in BB match + // 5: incompatible types on the assignment + ); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " AA res = bb.test();\n" + + " BB res2 = bb.test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { }\n" + + "class CC {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res = bb.test();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from AA to AA\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " BB res2 = bb.test();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from AA to BB\n" + + "----------\n" + // incompatible types on both assignments + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98079 +public void test0707() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " B b() {\n" + + " return a();\n" + + " }\n" + + " \n" + + " B a() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " static class B { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95684 +public void test0708() { + this.runConformTest( + new String[] { + "UserClass.java", + "public class UserClass {\n" + + " protected class DataHolder {}\n" + + " protected void loadHook(DataHolder data) {}\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "ChildClass.java", + "public class ChildClass extends UserClass {\n" + + " @Override protected void loadHook(DataHolder data) {}\n" + + "}\n", + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95684 - variation +public void test0709() { + this.runConformTest( + new String[] { + "UserClass.java", + "public class UserClass {\n" + + " protected class DataHolder {}\n" + + " protected void loadHook(DataHolder[] data) {}\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "ChildClass.java", + "public class ChildClass extends UserClass {\n" + + " @Override protected void loadHook(DataHolder[] data) {}\n" + + "}\n", + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96713 +public void test0710() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static > P createDataObject(V value) {\n" + + " return null;\n" + + " }\n" + + " public static void testCreateDataObject(Object v) {\n" + + " Persistent d = createDataObject(v);\n" + + " }\n" + + "\n" + + " private interface Persistent {\n" + + " public V getValueObject();\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97108 +public void test0711(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " static private Map m1 = new HashMap();\n" + + " private List m2 = new ArrayList();\n" + + " static protected XX foo()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " static public abstract class XX\n" + + " {\n" + + " }\n" + + "}\n", + }, + ""); + + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X \n" + + "{ \n" + + "}\n" + }, + "", + null, + false, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97108 +// The case that works +public void test0712(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " static private Map m1 = new HashMap();\n" + + " private List> m2 = new ArrayList>();\n" + + " static protected XX foo()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " static public abstract class XX\n" + + " {\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X \n" + + "{ \n" + + "}\n" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96713 +public void test0713() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i = 0;\n" + + " interface Y {\n" + + " java.util.List lt = null;\n" + + " int j = i;\n" + + " void m1(T t); \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " java.util.List lt = null;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = i;\n" + + " ^\n" + + "Cannot make a static reference to the non-static field i\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " void m1(T t); \n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98232 +public void test0714() { + this.runConformTest( + new String[] { + "B.java", + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "import java.util.SortedSet;\n" + + "\n" + + "public class B {\n" + + " static Set foo(SortedSet set) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n", + }, + ""); + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " A() {\n" + + " B.foo(null);\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98393 +public void test0715() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Comparable c = (java.util.List)bar(5, 5.0);\n" + + " }\n" + + " \n" + + " T bar(T t1, T t2) { return t1; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Comparable c = (java.util.List)bar(5, 5.0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to Comparable\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Comparable c = (java.util.List)bar(5, 5.0);\n" + + " ^^^^^^^^^^^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98396 +// ** +public void test0716() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " void foo(T t) {\n" + + " Comparable ci = (Comparable) t; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Comparable ci = (Comparable) t; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from T to Comparable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=98396 - variation +public void test0717() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X & List> {\n" + + " void foo(T t) {\n" + + " Comparable ci = (Comparable) t; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Comparable ci = (Comparable) t; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from T to Comparable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98478 +public void test0718() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "import java.util.Set;\n" + + "import java.util.TreeSet;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public interface Base {\n" + + " }\n" + + " \n" + + " abstract class Action {\n" + + " }\n" + + "\n" + + " public class ActionImpl extends Action implements Comparable {\n" + + " public int compareTo(ActionImpl o) {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " public void test() {\n" + + " Set set = new TreeSet();\n" + + " Collections.max(set);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " public class ActionImpl extends Action implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " public int compareTo(ActionImpl o) {\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 20)\n" + + " Set set = new TreeSet();\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " Set set = new TreeSet();\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 21)\n" + + " Collections.max(set);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation max(Collection) of the generic method max(Collection) of type Collections\n" + + "----------\n" + + "6. ERROR in X.java (at line 23)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 +public void test0719() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.ListIterator;\n" + + "\n" + + "interface IntegerIterator extends Iterator {}\n" + + "interface IntegerListIterator extends ListIterator, IntegerIterator {}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " interface IntegerIterator extends Iterator {}\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " interface IntegerListIterator extends ListIterator, IntegerIterator {}\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The interface Iterator cannot be implemented more than once with different arguments: Iterator and Iterator\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 - variation +public void test0720() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo {}\n" + + "interface Bar extends Foo {}\n" + + "interface Baz extends Bar, Foo {}\n" + + "\n" + + "class XSuper implements Foo {}\n" + + "class XSub extends XSuper implements Foo {}\n" + + "\n" + + "public class X implements Bar, Foo {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " interface Baz extends Bar, Foo {}\n" + + " ^^^\n" + + "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " interface Baz extends Bar, Foo {}\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " class XSuper implements Foo {}\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " class XSub extends XSuper implements Foo {}\n" + + " ^^^^\n" + + "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " public class X implements Bar, Foo {}\n" + + " ^\n" + + "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " public class X implements Bar, Foo {}\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98561 +public void test0721() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo\n" + + "{\n" + + " protected abstract class InnerFoo\n" + + " {\n" + + " protected abstract void doSomething();\n" + + " }\n" + + " \n" + + " protected void run( InnerFoo innerFoo )\n" + + " {\n" + + " innerFoo.doSomething();\n" + + " }\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "Bar.java", + "public class Bar extends Foo\n" + + "{\n" + + " public void go()\n" + + " {\n" + + " InnerFoo inner = new InnerFoo()\n" + + " {\n" + + " protected void doSomething()\n" + + " {\n" + + " System.out.println( \"hello\" );\n" + + " }\n" + + " };\n" + + " run( inner );\n" + + " }\n" + + "}" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 - variation +public void test0722() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I1 {\n" + + "}\n" + + "\n" + + "interface I2 extends I1 {\n" + + "}\n" + + "\n" + + "public class X implements I1, I2 {\n" + + "}\n", + }, + ""); +} +public void test0723() { + this.runConformTest( + new String[] { + "X.java", + "interface IA {}\n" + + "interface IB extends IA {}\n" + + "class A implements IA {}\n" + + "class B implements IB {}\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A x = new A();\n" + + " B y = new B();\n" + + " print(x);\n" + + " print(y);\n" + + " }\n" + + " public static > void print(T a) {\n" + + " System.out.print(\"A\");\n" + + " }\n" + + " public static > void print(T a) {\n" + + " System.out.println(\"B\");\n" + + " }\n" + + "}\n", + }, + "AB"); +} +public void test0724() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " HashMap subst = new HashMap();\n" + + " subst.put((byte)1, (byte)1);\n" + + " if (1 + subst.get((byte)1) > 0.f) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 +public void test0725() { + this.runNegativeTest( + new String[] { + "X.java", + "class AbsC {\n" + + " public T[] resize(T[] src, T[] dest) {\n" + + " return dest;\n" + + " }\n" + + "}\n" + + "\n" + + "class ConrC extends AbsC {\n" + + " T[][] data;\n" + + " protected void allocateChunkSlots(int maxChunkNo) {\n" + + " data = resize(data, new Object[maxChunkNo][]);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " data = resize(data, new Object[maxChunkNo][]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object[][] to T[][]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 +public void test0726() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " \n" + + " Controller ctrl = null;\n" + + " foobar(ctrl.getView().getContent()); \n" + + " } \n" + + " \n" + + " static void foobar(X x) {\n" + + " }\n" + + "}\n" + + "interface Controller> {\n" + + " public T getView() ;\n" + + "}\n" + + "interface View {\n" + + " public U getContent();\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 - variation +public void test0727() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " \n" + + " Controller ctrl = null;\n" + + " foobar(ctrl.getView().getContent()); \n" + + " } \n" + + " \n" + + " static void foobar(X x) {\n" + + " }\n" + + "}\n" + + "interface Controller> {\n" + + " public T getView() ;\n" + + "}\n" + + "interface View> {\n" + + " public U getContent();\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 - variation +public void test0728() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " \n" + + " Controller ctrl = null;\n" + + " foobar(ctrl.getView().getContent()); \n" + + " } \n" + + " \n" + + " static void foobar(X x) {\n" + + " }\n" + + "}\n" + + "interface Controller> {\n" + + " public T getView() ;\n" + + "}\n" + + "interface View> {\n" + + " public U getContent();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " foobar(ctrl.getView().getContent()); \n" + + " ^^^^^^\n" + + "The method foobar(X) in the type X is not applicable for the arguments (capture#2-of ?)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96586 +public void test0729() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "interface I {}\n" + + "class Y extends X implements I {}\n" + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "interface I> {}\n" + + "class Y extends X implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Y extends X implements I {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class Y extends X implements I {}\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type I\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=90437 +public void test0730() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " Zork z;\n" + + " public interface SuperInterface {\n" + + " }\n" + + "\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public String getString();\n" + + " }\n" + + "\n" + + " private SuperInterface< ? extends SuperInterface> x = null;\n" + + "\n" + + " public void f() {\n" + + " ((SubInterface) this.x).getString();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " private SuperInterface< ? extends SuperInterface> x = null;\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " ((SubInterface) this.x).getString();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.SuperInterface to X.SubInterface\n" + + "----------\n" ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97440 +public void test0731() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X parent;\n" + + " X current;\n" + + "\n" + + " X parent2;\n" + + " X current2;\n" + + "\n" + + " void foo() {\n" + + " current = current.parent;\n" + + " }\n" + + "\n" + + " void bar() {\n" + + " current2 = current2.parent2;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 +public void test0732() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from D to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0733() { + this.runConformTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Object foo(C c) {\n" + + " return (D) c;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0734() { + this.runConformTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Object foo(C c, D d) {\n" + + " return c != null ? c : d; \n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0735() { + this.runConformTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Object foo(C c, D d) {\n" + + " return c != null ? c : d; \n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0736() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " void bar(C c) {\n" + + " D d = (D) c;\n" + + " foo(d, c);\n" + + " }\n" + + " void foo(U u1, U u2) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " D d = (D) c;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from C to D\n" + + "----------\n"); +} +public void test0737() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "class Sup {\n" + + "}\n" + + "\n" + + "class Sub1 extends Sup {\n" + + "}\n" + + "\n" + + "class Sub2 extends Sup {\n" + + "\n" + + "}\n" + + "abstract class X {\n" + + " abstract S method(A la, B lb);\n" + + "\n" + + " void m2() {\n" + + " Sup Sup = method(new Sub1(), new Sub2());// <-- compiles?? ( A=Sub1, B=Sub2, S=Sup)\n" + + " Object obj = method(1, \"32\");// <--doesn\'t compile?? ( A=Integer, B=String, S=Object)\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0738() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "class C implements B{}\n" + + "interface D extends B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from D to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0739() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "class D implements B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from D to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0740() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "final class C implements B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " B d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from B to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0741() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "final class D implements B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " B c = (B)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " B c = (B)d; // illegal\n" + + " ^^^^^^^^^^^^\n" + + "Cannot cast from D to B\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=98538 +// ** +public void test0742() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + " public class X {\n" + + " \n" + + " static abstract class SelfType>{\n" + + " }\n" + + " \n" + + " static class SuperType extends SelfType{\n" + + " }\n" + + " \n" + + " static class SubType extends SuperType{}\n" + + " \n" + + " static > List makeSingletonList(T t){\n" + + " return Collections.singletonList(t);\n" + + " }\n" + + " \n" + + " static ,S extends T> List makeSingletonList2(S s){\n" + + " return Collections.singletonList((T)s); // #0\n" + + " }\n" + + " \n" + + " public static void main(String[] args){\n" + + " makeSingletonList(new SuperType()); // #1 - OK\n" + + " List lsup = makeSingletonList(new SuperType()); // #2 - OK\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + + " makeSingletonList(new SubType()); // #4 - ERROR\n" + + " makeSingletonList2(new SubType()); // #5 - ERROR\n" + + " lsup = makeSingletonList2(new SubType()); // #6 - OK\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + + " makeSingletonList2(new SuperType()); // #8 - OK\n" + + " lsup = makeSingletonList2(new SuperType()); // #9 - OK\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " makeSingletonList(new SubType()); // #4 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. ERROR in X.java (at line 26)\n" + + " makeSingletonList2(new SubType()); // #5 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "4. ERROR in X.java (at line 28)\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99553 +public void test0743() { + this.runNegativeTest( + new String[] { + "X.java", + "interface TestGeneric2 {\n" + + " Nested getNested2(); // super\n" + + "\n" + + " class Nested implements TestGeneric2 {\n" + + " public Nested getNested2() { // sub\n" + + " return this;//2\n" + + " }\n" + + " }\n" + + "}\n" + + " \n" + + "class TestGeneric3 {\n" + + " Nested getNested3() { return null; } // super\n" + + "\n" + + " class Nested extends TestGeneric3 {\n" + + " @Override public Nested getNested3() { // sub\n" + + " return this;//3\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " return this;//3\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from TestGeneric3.Nested to TestGeneric3.Nested\n" + + "----------\n"); +} +public void test0744() { + this.runNegativeTest( + new String[] { + "java/util/X.java", + "package java.util;\n" + + "\n" + + "import java.io.*;\n" + + "\n" + + "class Super {\n" + + " static class Entry {\n" + + " Entry(int i, U u, V v, Entry entry) {}\n" + + " void recordAccess(Super s) {\n" + + " }\n" + + " }\n" + + "}\n"+ + "public abstract class X extends Super {\n" + + "\n" + + " Entry h;\n" + + "\n" + + " private static class Entry extends Super.Entry {\n" + + "\n" + + " Entry() {\n" + + " super(0, null, null, null);\n" + + " }\n" + + "\n" + + " void ab(Entry e) {\n" + + " }\n" + + "\n" + + " @Override void recordAccess(Super m) {\n" + + " X x = (X) m;\n" + + " ab(x.h);\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in java\\util\\X.java (at line 30)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99922 +public void test0745() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " java.util.Arrays.asList(3, 3.1);\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99922 - variation +public void test0746() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " String s = java.util.Arrays.asList(3, 3.1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " String s = java.util.Arrays.asList(3, 3.1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Number&Comparable is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String s = java.util.Arrays.asList(3, 3.1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99983 +public void test0747() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface I {}\n" + + " class Y {\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Y {\n" + + " ^\n" + + "Cannot specify any additional bound X.I when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100007 +public void test0748() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface Factory {\n" + + " public U create(Class cl);\n" + + " }\n" + + " \n" + + " static class BytesFactory implements Factory {\n" + + " public byte[] create(Class cl) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " static class BytesFactory implements Factory {\r\n" + + " ^^^^^^^^^^^^\n" + + "The type X.BytesFactory must implement the inherited abstract method X.Factory.create(Class)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100149 +public void test0749() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X> {\n" + + " T get() { return null; }\n" + + " void foo(X x) {\n" + + " String s = x.get();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = x.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100149 - variation +public void test0750() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X> {\n" + + " T get() { return null; }\n" + + " void foo(X x) {\n" + + " List l = x.get();\n" + + " }\n" + + " Zork z ;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " List l = x.get();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z ;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100153 +public void test0751() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " \n" + + " void foo(X x) {\n" + + " X x2 = x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X x2 = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +public void test0752() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " X> parent;\n" + + " X> current;\n" + + " void foo() {\n" + + " current = current.parent;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " current = current.parent;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X>> to X>\n" + + "----------\n"); +} +public void test0753() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " X> parent;\n" + + " X> current;\n" + + " void foo() {\n" + + " current = current.parent;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X> parent;\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The type ? super I is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X> current;\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The type ? super I is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " current = current.parent;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X>> to X>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99578 +public void test0754() { + this.runNegativeTest( + new String[] { + "X.java", + "class bugSuper {\n" + + " public T getData(){\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class bugElement {\n" + + "}\n" + + "\n" + + "class bugClass extends bugSuper{\n" + + "}\n" + + "\n" + + "public class X{\n" + + " public void method(bugClass bc){\n" + + " bugElement be = bc.getData(); //<< here\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " public void method(bugClass bc){\n" + + " ^^^^^^^^\n" + + "bugClass is a raw type. References to generic type bugClass should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " bugElement be = bc.getData(); //<< here\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to bugElement\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99999 +public void test0755() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class B {}\n" + + " public static void main (String... args) {\n" + + " X.B[] b = new X.B[1];\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.B[] b = new X.B[1];\n" + + " ^^^^^^^^\n" + + "The member type X.B cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X.B[] b = new X.B[1];\n" + + " ^^^^^^\n" + + "The member type X.B cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99999 - variation +public void test0756() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public class B {}\n" + + " public static void main (String... args) {\n" + + " X.B[] b = new X.B[1];\n" + + " }\n" + + "}", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100147 +public void test0757() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class EntryMap {\n" + + " class Entry {\n" + + " }\n" + + " }\n" + + "\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " void foo(Object key) {\n" + + " EntryMap.Entry entry = internalGet(key);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = internalGet(key);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.EntryMap.Entry needs unchecked conversion to conform to X.EntryMap.Entry\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100147 - variation +public void test0758() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class EntryMap {\n" + + " class Entry {\n" + + " }\n" + + " }\n" + + "\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " void foo(Object key) {\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X.EntryMap.Entry to X.EntryMap.Entry\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.EntryMap.Entry needs unchecked conversion to conform to X.EntryMap.Entry\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100128 +public void test0759() { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " E[] m;\n" + + " public X()\n" + + " {\n" + + " X x = null;\n" + + " System.out.println(x.m.length);\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test0760() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static X make() {\n" + + " return null;\n" + + " }\n" + + " public static T itself(T t) {\n" + + " return t;\n" + + " }\n" + + "\n" + + " void foo() {\n" + + " X x1 = make();\n" + + " X x2 = itself(x1);\n" + + " }\n" + + " void bar() {\n" + + " X x2 = itself(make());\n" + + " }\n" + + " void baz() {\n" + + " X x2 = itself((X)make());\n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " X x2 = itself(make());\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " X x2 = itself((X)make());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100421 +public void test0761() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public abstract class ClassA {\n" + + " public abstract B method(A param);\n" + + " }\n" + + "\n" + + " public class ClassB {\n" + + " // the following field declaration causes an error\n" + + " ClassA classA;\n" + + "\n" + + " public D method(D d) {\n" + + " return classA.method(d);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100421 - variation +public void test0762() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public abstract class ClassA {\n" + + " public abstract B method(A param);\n" + + " }\n" + + "\n" + + " public class ClassB {\n" + + " // the following field declaration causes an error\n" + + " ClassA classA;\n" + + "\n" + + " public D method(D d) {\n" + + " return classA.method(d);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100519 +public void test0763() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class InnerClass {\n" + + " public InnerClass() {\n" + + " System.out.println(\"class : \" + InnerClass.this);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100527 +public void test0764() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + " \n" + + "interface IIfClosure {}\n" + + " \n" + + "public class X {\n" + + " public X(String label, HashMap bindings) {\n" + + " this(label, bindings, (List)Collections.emptyList());\n" + + " }\n" + + " \n" + + " public X(String label, HashMap bindings, Collection coll) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " this(label, bindings, (List)Collections.emptyList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 +public void test0765() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static T f1() throws Exception{\n" + + " return null;\n" + + " }\n" + + " static U f2() throws Exception {\n" + + " return f1();\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6302954 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 +public void test0766() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Cloneable> {\n" + + " public T clone();\n" + + "}\n" + + "\n" + + "interface CloneableMap> extends Map, Cloneable> {\n" + + "}\n" + + "\n" + + "interface C> extends Cloneable {\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " CloneableMap> map = null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " CloneableMap> map = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter > of the type CloneableMap\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 - variation +public void test0767() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Cloneable> {\n" + + " public T clone();\n" + + "}\n" + + "\n" + + "interface CloneableMap> extends Map, Cloneable> {\n" + + "}\n" + + "\n" + + "interface C extends Cloneable {\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " CloneableMap map = null;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100619 +public void test0768() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo1() { return null; }\n" + + " , U extends Z & T> T foo2() { return null; }\n" + + " , U extends T & Z> T foo3() { return null; }\n" + + " , U extends W & Z> T foo4() { return null; }\n" + + "}\n" + + "\n" + + "interface Y {\n" + + "}\n" + + "\n" + + "interface Z extends Y {}\n" + + "interface W extends Y {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo1() { return null; }\n" + + " ^\n" + + "The type T is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " , U extends Z & T> T foo2() { return null; }\n" + + " ^\n" + + "The type T is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " , U extends T & Z> T foo3() { return null; }\n" + + " ^\n" + + "Cannot specify any additional bound Z when first bound is a type parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " , U extends T & Z> T foo3() { return null; }\n" + + " ^\n" + + "The interface Y cannot be implemented more than once with different arguments: Y and Y\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " , U extends W & Z> T foo4() { return null; }\n" + + " ^\n" + + "The interface Y cannot be implemented more than once with different arguments: Y and Y\n" + + "----------\n"); +} +public void test0769() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " value += 1;\n" + + " value = value + 1;\n" + + " System.out.println(value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + "[11"); +} +public void test0770() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " this.value += 1;\n" + + " this.value = this.value + 1;\n" + + " System.out.println(this.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + "[11"); +} +public void test0771() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public static void a(X x) {\n" + + " x.value += 1;\n" + + " x.value = x.value + 1;\n" + + " System.out.println(x.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " a(x);\n" + + " }\n" + + "}\n", + }, + "[11"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794 +public void test0772() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " public T getIt();\n" + + "}\n" + + "\n" + + "class FooImpl implements Foo {\n" + + " public String getIt() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + String expectedOutput = + " // Method descriptor #18 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Object getIt();\n" + + " 0 aload_0\n" + + " 1 invokevirtual FooImpl.getIt() : java.lang.String [19]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "FooImpl.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794 - variation +public void test0773() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " public T getIt() throws T;\n" + + "}\n" + + "\n" + + "class FooImpl implements Foo {\n" + + " public NullPointerException getIt() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + String expectedOutput = + " // Method descriptor #18 ()Ljava/lang/Exception;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Exception getIt() throws java.lang.Exception;\n" + + " 0 aload_0\n" + + " 1 invokevirtual FooImpl.getIt() : java.lang.NullPointerException [22]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "FooImpl.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98532 +public void test0774() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class StaticInnerNoParam {\n" + + " T x;\n" + + " }\n" + + " class NonStaticInnerParam {} \n" + + " static class StaticInnerParam { }\n" + + " void foo(T t) {}\n" + + " static void bar(T t) {}\n" + + " X(T t) {}\n" + + " \n" + + " class U {}\n" + + " void foo2(U t) {}\n" + + " static void bar2(U t) {}\n" + + " class NonStaticInnerParam2 {} \n" + + " static class StaticInnerParam2 {} \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " T x;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " class NonStaticInnerParam {} \n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " void foo(T t) {}\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " X(T t) {}\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " void foo2(U t) {}\n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " static void bar2(U t) {}\n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " class NonStaticInnerParam2 {} \n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " static class StaticInnerParam2 {} \n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100153 +public void test0775() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " void foo1(X x) {}\n" + + " void foo2(X x) {}\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103023 +public void test0776() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X> {\n" + + "\n" + + " abstract class Foo implements I> {}\n" + + "\n" + + " abstract class Bar implements I> {}\n" + + "\n" + + " public void bar(List> f, List> b) {\n" + + " foo(f, b);\n" + + " }\n" + + "\n" + + " void foo(List f, List b) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().bar(null, null);\n" + + " }\n" + + "}\n" + + "interface I {}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103472 +public void test0777() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public interface B {\n" + + " public T a();\n" + + " }\n" + + "\n" + + " public interface C extends B {\n" + + " }\n" + + "\n" + + " public class D implements B {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " // Illegal\n" + + " public class E implements B, C {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " // why is this allowed?\n" + + " public class F extends D implements C {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " public interface G {\n" + + " public void a(T pArg);\n" + + " }\n" + + "\n" + + " public interface H extends G {\n" + + " public Object b();\n" + + " }\n" + + "\n" + + " public class I implements G {\n" + + " public void a(Integer pInt) {\n" + + " }\n" + + " }\n" + + "\n" + + " // Illegal. Huh?\n" + + " public class J extends I implements G {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public interface C extends B {\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " public class E implements B, C {\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " public class F extends D implements C {\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n" + + "4. WARNING in X.java (at line 24)\n" + + " public Integer a() {\n" + + " ^^^\n" + + "The method a() of type X.F should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "5. WARNING in X.java (at line 33)\n" + + " public interface H extends G {\n" + + " ^\n" + + "X.G is a raw type. References to generic type X.G should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 43)\n" + + " public class J extends I implements G {\n" + + " ^\n" + + "The interface G cannot be implemented more than once with different arguments: X.G and X.G\n" + + "----------\n" + + "7. WARNING in X.java (at line 43)\n" + + " public class J extends I implements G {\n" + + " ^\n" + + "X.G is a raw type. References to generic type X.G should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103472 - variation +public void test0778() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface B {}\n" + + "\n" + + " interface C extends B {}\n" + + "\n" + + " class D implements B {}\n" + + "\n" + + " class F extends D implements C {}\n" + + " \n" + + " class V {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " interface C extends B {}\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " class F extends D implements C {}\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " class V {}\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103227 +public void test0779() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.AbstractList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private static class Entry {\n" + + " public void doIt(final List args) {\n" + + " List list = new AbstractList() {\n" + + " @Override public int size() { return 0; }\n" + + " @Override public String get(int i) { return args.get(i); }\n" + + " };\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Entry().doIt(null);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #31 (I)Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 2\n" + + " public bridge synthetic java.lang.Object get(int arg0);\n" + + " 0 aload_0\n" + + " 1 iload_1\n" + + " 2 invokevirtual X$Entry$1.get(int) : java.lang.String [36]\n" + + " 5 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + // check no unnecessary checkcast on bridge method for X$1 + File f = new File(OUTPUT_DIR + File.separator + "X$Entry$1.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103227 - variation +public void test0780() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " long foo(List list) {\n" + + " return list.get(0);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " list.add(123L);\n" + + " System.out.println(new X().foo(list));\n" + + " }\n" + + "}\n", + }, + "123"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104109 +public void test0781() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static > Foo doIt(T t) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " interface Foo {\n" + + " boolean ok(E e);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static > Foo doIt(T t) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104082 +public void test0782() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "import java.util.*;\n" + + "\n" + + "interface StoredObject {\n" + + " String getUid();\n" + + " String getName();\n" + + " String getDescription();\n" + + "}\n" + + "\n" + + "interface GraphDiagramNode // extends Comparable\n" + + "{\n" + + "}\n" + + "\n" + + "public class X implements GraphDiagramNode {\n" + + " private final JccsGraphDiagramModel model;\n" + + " private final X parent;\n" + + " private final ObjectType object;\n" + + "\n" + + " public class JccsGraphDiagramModel {\n" + + " }\n" + + "\n" + + " public interface GraphDiagramModel {\n" + + " }\n" + + "\n" + + " public class Dependency {\n" + + "\n" + + " }\n" + + "\n" + + " public X(JccsGraphDiagramModel argModel, X argParent, ObjectType argObject) {\n" + + " model = argModel;\n" + + " parent = argParent;\n" + + " object = argObject;\n" + + " }\n" + + "\n" + + " protected Collection> createChildren(\n" + + " Iterator argData, Class> argChildNodeClass,\n" + + " Class argInterface) {\n" + + " Collection> output = new LinkedList>();\n" + + "\n" + + " try {\n" + + " while (argData.hasNext()) {\n" + + " ChildType next = argData.next();\n" + + " Constructor> constructor = argChildNodeClass.getConstructor(\n" + + " JccsGraphDiagramModel.class, getClass(), argInterface);\n" + + "\n" + + " output.add(constructor.newInstance(model, this, next));\n" + + " }\n" + + " } catch (Exception x) {\n" + + " x.printStackTrace();\n" + + " }\n" + + "\n" + + " return output;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104167 +public void test0783() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class B{\n" + + " private int foo; //incorrectly identified as unused\n" + + " }\n" + + " void bar(B b){\n" + + " if (b.foo == 0)\n" + + " return;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104082 - variation +public void test0784() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X parent;\n" + + "\n" + + " public X(X parent) {\n" + + " this.parent = parent;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 +public void test0785() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " > T getLonger(T t1, T t2) {\n" + + " return t1.size() > t2.size() ? t1 : t2;\n" + + " }\n" + + " \n" + + " void m(HashSet list, ArrayList set) {\n" + + " getLonger(list, set);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " getLonger(list, set);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method getLonger(T, T) of type X is not applicable for the arguments (HashSet, ArrayList). The inferred type AbstractCollection&Cloneable&Serializable is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 - variation +public void test0786() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " > T getLonger(T t1, T t2) {\n" + + " return t1.size() > t2.size() ? t1 : t2;\n" + + " }\n" + + " \n" + + " void m(HashSet list, ArrayList set) {\n" + + " getLonger(list, set);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 - variation +public void test0787() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " > T getLonger(T t1, T t2) {\n" + + " return t1.size() > t2.size() ? t1 : t2;\n" + + " }\n" + + " \n" + + " void m(HashSet list, ArrayList set) {\n" + + " getLonger(list, set);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " getLonger(list, set);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method getLonger(T, T) of type X is not applicable for the arguments (HashSet, ArrayList). The inferred type AbstractCollection&Cloneable&Serializable is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103994 +public void test0788() { + this.runConformTest( + new String[] { + "test/A.java", + "package test;\n" + + "\n" + + "public class A\n" + + "{\n" + + " class B\n" + + " extends A\n" + + " {\n" + + " }\n" + + "}\n", + "java/nio/channels/spi/AbstractSelectableChannel.java", + "package java.nio.channels.spi;\n" + + "\n" + + "public abstract class AbstractSelectableChannel\n" + + " extends java.nio.channels.SelectableChannel\n" + + "{\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103994 - variation (change ordering of files should have no effect) +public void test0789() { + this.runConformTest( + new String[] { + "java/nio/channels/spi/AbstractSelectableChannel.java", + "package java.nio.channels.spi;\n" + + "\n" + + "public abstract class AbstractSelectableChannel\n" + + " extends java.nio.channels.SelectableChannel\n" + + "{\n" + + "}\n", + "test/A.java", + "package test;\n" + + "\n" + + "public class A\n" + + "{\n" + + " class B\n" + + " extends A\n" + + " {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103485 +public void test0790() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > boolean isGreater(T t1, T t2) {\n" + + " return t1.compareTo(t2) > 0 ? true : false; \n" + + " }\n" + + "\n" + + " void method1(Integer i, Double d) {\n" + + " if (isGreater(i, d)) \n" + + " System.out.println(\"GREATER\");\n" + + " else\n" + + " System.out.println(\"LOWER\");\n" + + " }\n" + + " void method2(Integer i, Double d) {\n" + + " Comparable c1= i;\n" + + " Comparable c2= d;\n" + + " isGreater(c1, c2);\n" + + " } \n" + + " void method3(Integer i, Double d) {\n" + + " Comparable c1= i;\n" + + " Comparable c2= d;\n" + + " isGreater(c1, c2);\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " Integer i = 1;\n" + + " Double d = 2.0;\n" + + " new X().method1(i, d);\n" + + " new X().method2(i, d);\n" + + " new X().method3(i, d);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (isGreater(i, d)) \n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Integer, Double). The inferred type Number&Comparable is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " isGreater(c1, c2);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Comparable, Comparable). The inferred type Comparable is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " Comparable c1= i;\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 19)\n" + + " Comparable c2= d;\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 20)\n" + + " isGreater(c1, c2);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation isGreater(Comparable, Comparable) of the generic method isGreater(T, T) of type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104655 +public void test0791() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " Sup method1(boolean b, E1 e1, E2 e2) {\n" + + " if (b)\n" + + " return e1;\n" + + " else\n" + + " return e2;\n" + + " }\n" + + "\n" + + " Sup method2(boolean b, E1 e1, E2 e2) {\n" + + " return b ? e1 : e2;\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104649 +public void test0792() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void shouldcompile() {\n" + + " java.util.Collections.max(null);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105635 +public void test0793() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public java.util.List i,j[],k;\n" + + " void m() {\n" + + " i[0] = null;\n" + + " j[0] = null;\n" + + " k[0] = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " i[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " k[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105635 +public void test0794() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X { \n" + + " public List i,j[],k;\n" + + " void m() {\n" + + " i[0] = null;\n" + + " j[0] = null;\n" + + " k[0] = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " i[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " k[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 +public void test0795() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " class B {\n" + + " B() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static { \n" + + " new X().new B() {};\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 - variation +public void test0796() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " class B {\n" + + " B(T t) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static { \n" + + " new X().new B(12) {};\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new B(12) {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X.B(int) is undefined\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 - variation +public void test0797() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " class B {\n" + + " B() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static { \n" + + " new X().new B();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106284 +public void test0798() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.math.BigDecimal;\n" + + "\n" + + "public class X\n" + + "{\n" + + " private static > T max(T... elems)\n" + + " {\n" + + " T max=null;\n" + + " for (T elem : elems)\n" + + " if (max == null || max.compareTo(elem) < 0)\n" + + " max=elem;\n" + + " return max;\n" + + " }\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + + " ^^^\n" + + "Bound mismatch: The generic method max(T...) of type X is not applicable for the arguments (Integer, Double, BigDecimal). The inferred type Number&Comparable is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105531 +public void test0799() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Y first;\n" + + " Y first2;\n" + + "\n" + + " U foo(U u1, U u2) {\n" + + " return u1;\n" + + " }\n" + + " void bar2(Y ref) {\n" + + " String s = foo(ref, first);\n" + + " }\n" + + " \n" + + " void foo(Y ref) {\n" + + " ref.next = first == null ? ref : first;\n" + + " String s = first == null ? ref : first;\n" + + " ref.next = first2 == null ? ref : first2;\n" + + " }\n" + + " Y bar(Y ref) {\n" + + " return first == null ? ref : first;\n" + + " }\n" + + "}\n" + + "\n" + + "class Y {\n" + + " Y next;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Y first;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Y first2;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s = foo(ref, first);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " ref.next = first == null ? ref : first;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " String s = first == null ? ref : first;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " ref.next = first2 == null ? ref : first2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "7. WARNING in X.java (at line 18)\n" + + " return first == null ? ref : first;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 +public void test0800() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.lang.reflect.Constructor;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final Class AnnClass = Ann.class;\n" + + " Constructor[] constrs = X.class.getConstructors();\n" + + " for (Constructor constructor : constrs) {\n" + + " final String message = constructor.getAnnotation(AnnClass).message();\n" + + " System.out.println(message);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 6)\n" + + " Constructor[] constrs = X.class.getConstructors();\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " for (Constructor constructor : constrs) {\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " final String message = constructor.getAnnotation(AnnClass).message();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " final String message = constructor.getAnnotation(AnnClass).message();\n" + + " ^^^^^^^\n" + + "The method message() is undefined for the type Annotation\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test0801() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " X.class.getConstructor(new Class[0]).getAnnotation(Ann.class).message();\n" + + " } catch(Exception e) {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test0802() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar(Y y, X x) {\n" + + " y.foo(x).zz();\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " T foo(X x) { return null; }\n" + + "}\n" + + "\n" + + "class Z {\n" + + "}\n" + + "class ZZ extends Z {\n" + + " void zz() {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void bar(Y y, X x) {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " y.foo(x).zz();\n" + + " ^^^^^^^^\n" + + "Type safety: The method foo(X) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " y.foo(x).zz();\n" + + " ^^\n" + + "The method zz() is undefined for the type Z\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101831 +public void test0803() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " ArrayList list = new ArrayList();\n" + + " ArrayList superList = new ArrayList();\n" + + " ArrayList extendsList = new ArrayList();\n" + + "\n" + + " ArrayList getList() {\n" + + " return true ? list : list;\n" + + " }\n" + + "\n" + + " ArrayList getSuperList() {\n" + + " return true ? superList : superList;\n" + + " }\n" + + "\n" + + " ArrayList getExtendsList() {\n" + + " return true ? extendsList : extendsList;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " return true ? superList : superList;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to ArrayList\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106865 +public void test0804() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " void foo(E e) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " void method1(Y y, Object[] os) {\n" + + " y.foo(os);\n" + + " }\n" + + " void method2(Y y, Cloneable c) {\n" + + " y.foo(c);\n" + + " } \n" + + " void method3(Y y, Object[] os) {\n" + + " y.foo(os);\n" + + " }\n" + + " void method4(Y y, Cloneable c) {\n" + + " y.foo(c);\n" + + " } \n" + + " \n" + + " void bar(Y y) {\n" + + " method2(y, null);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " y.foo(os);\n" + + " ^^^\n" + + "The method foo(capture#3-of ? extends Object[]) in the type Y is not applicable for the arguments (Object[])\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " y.foo(c);\n" + + " ^^^\n" + + "The method foo(capture#4-of ? extends Cloneable) in the type Y is not applicable for the arguments (Cloneable)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106936 +public void test0805() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static T foo(T t1, T t2) { return t1; }\n" + + " public static void main(String[] args) {\n" + + " Number[] numbers = {}, numbers2, numbers3;\n" + + " Float[] floats = {};\n" + + " Integer[] integers = {};\n" + + "\n" + + " numbers2 = foo(numbers, floats);\n" + + " numbers3 = numbers != null ? numbers : floats;\n" + + " String s = foo(numbers, floats); \n" + + "\n" + + " numbers2 = foo(integers, floats);\n" + + " numbers3 = integers != null ? integers : floats;\n" + + " String s2 = foo(integers, floats);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = foo(numbers, floats); \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Number[] to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " String s2 = foo(integers, floats);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Number&Comparable>[] to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107079 +public void test0806() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "/**\n" + + " * This class demonstrates a generic program that Eclipse must not compile as it\n" + + " * can lead to a ClassCastException despite having no explicit type casts.\n" + + " */\n" + + "public class X {\n" + + " private static class ValueHolder {\n" + + " public T value;\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " List> multiList = new ArrayList>();\n" + + "\n" + + " ValueHolder intHolder = new ValueHolder();\n" + + " intHolder.value = 1;\n" + + "\n" + + " ValueHolder doubleHolder = new ValueHolder();\n" + + " doubleHolder.value = 1.5;\n" + + "\n" + + " multiList.add(intHolder);\n" + + " multiList.add(doubleHolder);\n" + + "\n" + + " // I believe this line is being erroneously treated as a capture\n" + + " // conversion under 3.1 JDT.\n" + + " // I believe the problem is that ? cannot be captured except in a first\n" + + " // level wildcard.\n" + + " swapFirstTwoValues(multiList);\n" + + "\n" + + " // this line causes a ClassCastException when checked.\n" + + " Integer value = intHolder.value;\n" + + " System.out.println(value);\n" + + " }\n" + + "\n" + + " private static void swapFirstTwoValues(List> multiList) {\n" + + " ValueHolder intHolder = multiList.get(0);\n" + + " ValueHolder doubleHolder = multiList.get(1);\n" + + "\n" + + " intHolder.value = doubleHolder.value;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 29)\n" + + " swapFirstTwoValues(multiList);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method swapFirstTwoValues(List>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107756 +public void test0807() { + this.runConformTest( + new String[] { + "X.java", + "interface Prop {\n" + + " Unmarshaller.Handler createHandler();\n" + + "}\n" + + "\n" + + "abstract class Unmarshaller {\n" + + " public static abstract class Handler {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(Prop p) {\n" + + " Unmarshaller.Handler h = p.createHandler(); \n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107756 - variation +public void test0808() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.ax = new AX();\n" + + " }\n" + + " \n" + + " AX ax;\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106946 +public void test0809() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "\n" + + "class Node {}\n" + + "interface Set1 extends Iterable {}\n" + + "interface Set2 extends Iterable {}\n" + + "\n" + + "class SetIterator implements Iterator {\n" + + " public N next() {\n" + + " return null;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return true;\n" + + " }\n" + + " public void remove() {\n" + + " }\n" + + "}\n" + + "interface Set3 extends Iterable {\n" + + " SetIterator iterator();\n" + + "}\n" + + "public class X {\n" + + " void f1(Set1 s) {\n" + + " Node n_ = s.iterator().next();\n" + + " // ^Type mismatch: cannot convert from Object to Node\n" + + " // this was unexpected (s can only contain types derivered from Node)\n" + + " for (Node n : s) {\n" + + " // ^Type mismatch: cannot convert from Object to Node\n" + + " // this was unexpected\n" + + " }\n" + + " }\n" + + " void f2(Set2 s) {\n" + + " Node n_ = s.iterator().next();\n" + + " for (Node n : s) {\n" + + " }\n" + + " }\n" + + " void f3(Set3 s) {\n" + + " Node n_ = s.iterator().next();\n" + + " // (^ no error here)\n" + + " for (Node n : s) {\n" + + " // ^Type mismatch: cannot convert from Object to Node\n" + + " // this is even stranger as we already know that s.iterator().next()\n" + + " // have the right type\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 21)\n" + + " void f1(Set1 s) {\n" + + " ^^^^\n" + + "Set1 is a raw type. References to generic type Set1 should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Node n_ = s.iterator().next();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Node\n" + + "----------\n" + + "3. ERROR in X.java (at line 25)\n" + + " for (Node n : s) {\n" + + " ^\n" + + "Type mismatch: cannot convert from element type Object to Node\n" + + "----------\n" + + "4. WARNING in X.java (at line 35)\n" + + " void f3(Set3 s) {\n" + + " ^^^^\n" + + "Set3 is a raw type. References to generic type Set3 should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 38)\n" + + " for (Node n : s) {\n" + + " ^\n" + + "Type mismatch: cannot convert from element type Object to Node\n" + + "----------\n"); +} +public void test0810() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class A {\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public A foo(K type) {\n" + + " return new A();\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " A a = x.foo(null);\n" + + " System.out.println(a);\n" + + " }\n" + + "}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 +public void test0811() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T t;\n" + + " private X.Inner inner;\n" + + " private X.Inner[] inners;\n" + + " public X(T t, X.Inner in, X.Inner[] ins) {\n" + + " this.t = t;\n" + + " this.inner = in;\n" + + " this.inner = new X(null, null, null).new Inner();\n" + + " this.inners = ins;\n" + + " this.inners = new X.Inner[10];\n" + + " //Type mismatch: cannot convert from X.Inner[] to X.Inner[]\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 - variation +public void test0812() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private T t;\n" + + " private X.Inner inner;\n" + + " private X.Inner[] inners;\n" + + " public X(T t) {\n" + + " this.t = t;\n" + + " this.inner = new X.Inner();\n" + + " this.inners = new X.Inner[10];\n" + + " Zork z;\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " private T t;\n" + + " ^\n" + + "The field X.t is never read locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " private X.Inner inner;\n" + + " ^^^^^\n" + + "The field X.inner is never read locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " private X.Inner[] inners;\n" + + " ^^^^^^\n" + + "The field X.inners is never read locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " this.inner = new X.Inner();\n" + + " ^^^^^^^\n" + + "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 - variation +public void test0813() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " private T t;\n" + + " private X.Inner[] inners;\n" + + " public X(T t) {\n" + + " this.t = t;\n" + + " this.inners = new X.Inner[10];\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 +public void test0814() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void method(Object o) {\n" + + " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + + " E[] es = (E[]) o;\n" + + " }\n" + + " if (o instanceof List[]) { //incorrect too\n" + + " List[] es = (List[]) o; \n" + + " }\n" + + " if (o instanceof List[]) { // unbound is ok\n" + + " List[] es = (List[]) o;\n" + + " }\n" + + " }\n" + + " void method(ArrayList[] al) {\n" + + " if (al instanceof List[]) { //incorrect too\n" + + " List[] es = (List[]) al; \n" + + " } \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type E[]. Use instead its raw form Object[] since generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " E[] es = (E[]) o;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E[]\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (o instanceof List[]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " List[] es = (List[]) o; \n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List[]\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " if (al instanceof List[]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " List[] es = (List[]) al; \n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList[] to List[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation +public void test0815() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object[][] e) {\n" + + " E[] o = (E[]) e;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " E[] o = (E[]) e;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object[][] to E[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation +public void test0816() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void method(Object[] o) {\n" + + " if (o instanceof List[][]) { //incorrect too\n" + + " List[][] es = (List[][]) o; \n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[][]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[][]. Use instead its raw form List[][] since generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[][] es = (List[][]) o; \n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to List[][]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation +public void test0817() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private T t;\n" + + " private X.Inner inner;\n" + + " private X.Inner[] inners;\n" + + " public X(T t) {\n" + + " this.t = t;\n" + + " if (this.inner instanceof X.Inner) {}\n" + + " if (this.inners instanceof X.Inner[]) {}\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + " void foo(List l) {\n" + + " if (l instanceof List) {}\n" + + " if (l instanceof List) {}\n" + + " }\n" + + " void foo(List[] ls) {\n" + + " if (ls instanceof List[]) {}\n" + + " if (ls instanceof List[]) {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " private T t;\n" + + " ^\n" + + "The field X.t is never read locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " if (this.inner instanceof X.Inner) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.Inner is already an instance of type X.Inner\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " if (this.inners instanceof X.Inner[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.Inner[] is already an instance of type X.Inner[]\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " void foo(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " if (l instanceof List) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The expression of type List is already an instance of type List\n" + + "----------\n" + + "6. ERROR in X.java (at line 16)\n" + + " if (l instanceof List) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List. Use instead its raw form List since generic type information will be erased at runtime\n" + + "----------\n" + + "7. WARNING in X.java (at line 18)\n" + + " void foo(List[] ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 19)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type List[] is already an instance of type List\n" + + "----------\n" + + "9. ERROR in X.java (at line 20)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + + "----------\n"); +} +public void test0818() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b = this instanceof Y;\n" + + " static class Y extends X {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101380 +public void test0819() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements MyInterface {\n" + + " public void myMethod(myEnum value) {\n" + + " System.out.println(\"value is \"+value);\n" + + " }\n" + + " public static void main(String[] args){\n" + + " new X().myMethod(myEnum.one); \n" + + " }\n" + + "}\n" + + "\n" + + "interface MyInterface {\n" + + " enum myEnum {one,two};\n" + + " public void myMethod(myEnum value); \n" + + "}\n", + }, + "value is one"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101380 - variation +public void test0820() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public void x(M value) {}\n" + + "}\n" + + "interface I {\n" + + " class M {}\n" + + " void x(M value); \n" + + "}\n", + }, + ""); +} +public void test0821() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo() {\n" + + " t.run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new A()).foo();\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.println(\"AA\");\n" + + " }\n" + + "}\n", + }, + "AA"); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #15 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.t : java.io.Serializable [16]\n" + + " 4 checkcast java.lang.Runnable [25]\n" + + " 7 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 12, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n"; + + 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); + } +} +public void test0822() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo(T t) {\n" + + " t.run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new A());\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.println(\"AA\");\n" + + " }\n" + + "}\n", + }, + "AA"); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_1 [t]\n" + + " 1 checkcast java.lang.Runnable [20]\n" + + " 4 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 9, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: t index: 1 type: java.io.Serializable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: t index: 1 type: T\n"; + + 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); + } +} +public void test0823() throws Exception { + runConformTest( + true, + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo() {\n" + + " (this == null ? t : t).run();\n" + + " ((V) t).run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new A()).foo();\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.print(\"AA\");\n" + + " }\n" + + "}\n", + }, + null, + "AAAA", + null, + JavacTestOptions.JavacHasABug.JavacBug6531075); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #15 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 ifnonnull 11\n" + + " 4 aload_0 [this]\n" + + " 5 getfield X.t : java.io.Serializable [16]\n" + + " 8 goto 15\n" + + " 11 aload_0 [this]\n" + + " 12 getfield X.t : java.io.Serializable [16]\n" + + " 15 checkcast java.lang.Runnable [25]\n" + + " 18 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + + " 23 aload_0 [this]\n" + + " 24 getfield X.t : java.io.Serializable [16]\n" + + " 27 checkcast java.lang.Runnable [25]\n" + + " 30 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + + " 35 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 23, line: 10]\n" + + " [pc: 35, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 36] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 36] local: this index: 0 type: X\n"; + + 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); + } +} +public void test0824() throws Exception { + runConformTest( + true, + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo(T t) {\n" + + " (this == null ? t : t).run();\n" + + " ((V) t).run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new A());\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.print(\"AA\");\n" + + " }\n" + + "}\n", + }, + null, + "AAAA", + null, + JavacTestOptions.JavacHasABug.JavacBug6531075); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_0 [this]\n" + + " 1 ifnonnull 8\n" + + " 4 aload_1 [t]\n" + + " 5 goto 9\n" + + " 8 aload_1 [t]\n" + + " 9 checkcast java.lang.Runnable [20]\n" + + " 12 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + + " 17 aload_1 [t]\n" + + " 18 checkcast java.lang.Runnable [20]\n" + + " 21 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + + " 26 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 17, line: 6]\n" + + " [pc: 26, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 27] local: this index: 0 type: X\n" + + " [pc: 0, pc: 27] local: t index: 1 type: java.io.Serializable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 27] local: this index: 0 type: X\n" + + " [pc: 0, pc: 27] local: t index: 1 type: T\n"; + + 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); + } +} +public void test0825() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo(T t) {\n" + + " Runnable r1 = t;\n" + + " Runnable r2 = (this == null ? t : t);\n" + + " Runnable r3 = ((V) t);\n" + + " \n" + + " bar(t);\n" + + " bar(this == null ? t : t);\n" + + " bar((V)t);\n" + + " }\n" + + " void bar(Runnable r) {} \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new A());\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.println(\"AA\");\n" + + " }\n" + + "}\n", + }, + ""); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 2, Locals: 5\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_1 [t]\n" + + " 1 astore_2 [r1]\n" + + " 2 aload_0 [this]\n" + + " 3 ifnonnull 10\n" + + " 6 aload_1 [t]\n" + + " 7 goto 11\n" + + " 10 aload_1 [t]\n" + + " 11 astore_3 [r2]\n" + + " 12 aload_1 [t]\n" + + " 13 astore 4 [r3]\n" + + " 15 aload_0 [this]\n" + + " 16 aload_1 [t]\n" + + " 17 invokevirtual X.bar(java.lang.Runnable) : void [20]\n" + + " 20 aload_0 [this]\n" + + " 21 aload_0 [this]\n" + + " 22 ifnonnull 29\n" + + " 25 aload_1 [t]\n" + + " 26 goto 30\n" + + " 29 aload_1 [t]\n" + + " 30 invokevirtual X.bar(java.lang.Runnable) : void [20]\n" + + " 33 aload_0 [this]\n" + + " 34 aload_1 [t]\n" + + " 35 invokevirtual X.bar(java.lang.Runnable) : void [20]\n" + + " 38 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 15, line: 9]\n" + + " [pc: 20, line: 10]\n" + + " [pc: 33, line: 11]\n" + + " [pc: 38, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 39] local: this index: 0 type: X\n" + + " [pc: 0, pc: 39] local: t index: 1 type: java.io.Serializable\n" + + " [pc: 2, pc: 39] local: r1 index: 2 type: java.lang.Runnable\n" + + " [pc: 12, pc: 39] local: r2 index: 3 type: java.lang.Runnable\n" + + " [pc: 15, pc: 39] local: r3 index: 4 type: java.lang.Runnable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 39] local: this index: 0 type: X\n" + + " [pc: 0, pc: 39] local: t index: 1 type: T\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110570 +public void test0826() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void test(V1 p1, V2 p2) {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " XA a = new XA(){};\n" + + " XB b = new XB(){};\n" + + "\n" + + " X t1 = new X();\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " \n" + + " X t2 = new X();\n" + + " t2.test(a, b); //this compiles OK\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "\n" + + "interface XA {}\n" + + "interface XB extends XA {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method test(Object, Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110570 - variation +// ensure variable V2 is substituted with upper bound erasure (List) and not just upperbound List +// for raw generic method invocation +public void test0827() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public > void test(V1 p1, V2 p2) {}\n" + + " public static void main(String[] args) {\n" + + " XA a = new XA(){};\n" + + " List b = null;\n" + + " X t1 = new X();\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " X t2 = new X();\n" + + " t2.test(a, b); //this compiles OK\n" + + " }\n" + + "}\n" + + "interface XA {}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method test(Object, List) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " t2.test(a, b); //this compiles OK\n" + + " ^^^^\n" + + "Bound mismatch: The generic method test(V1, V2) of type X is not applicable for the arguments (XA, List). The inferred type List is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109249 +public void test0828() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Transformable\n" + + "{\n" + + " public T transform();\n" + + "}\n" + + "interface Volume extends Transformable\n" + + "{\n" + + "// public V transform();\n" + + "}\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " void foo(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + " void bar(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " interface Transformable\n" + + " ^^^^^^^^^^^^^\n" + + "Transformable is a raw type. References to generic type Transformable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " interface Volume extends Transformable\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " Volume v1 = null;\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " Volume v2 = v1.transform();\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " Volume v2 = v1.transform();\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Transformable to Volume\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " Volume v1 = null;\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " Volume v2 = v1.transform();\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109249 - variation +public void test0829() { + this.runConformTest( + new String[] { + "X.java", + "interface Transformable\n" + + "{\n" + + " public T transform();\n" + + "}\n" + + "interface Volume extends Transformable\n" + + "{\n" + + " public V transform();\n" + + "}\n" + + "public class X {\n" + + " void foo(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + " void bar(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + "}\n", + }, + ""); +} +// ensure no raw type ref complaint inside instanceof / cast +public void test0830() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o instanceof X;\n" + + " X x = (X) o;\n" + + " X xs = (X)o;\n" + + " Zork z;\n" + + " }\n" + + " void bar(ArrayList al) {\n" + + " List l = (List) al;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " X x = (X) o;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " X x = (X) o;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X xs = (X)o;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to X\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " List l = (List) al;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " List l = (List) al;\n" + + " ^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " List l = (List) al;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +//unnecessary cast may be combined with unchecked cast warning +public void test0831() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Object o1) {\n" + + " Object o2 = (List) o1;\n" + + " \n" + + " foo((List)o2);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Object o2 = (List) o1;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Object o2 = (List) o1;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " foo((List)o2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " foo((List)o2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106010 +public void test0832() { + this.runNegativeTest( + new String[] { + "X.java", + "class C1 {\n" + + " class C11 { }\n" + + " class C12 {\n" + + " T t;\n" + + " C1.C11[] m() {\n" + + " C1.C11[] ts = (C1.C11[]) new C1.C11[5];\n" + + " return ts;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111014 +public void test0833() { + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B extends A.Inner> { class Inner {} }\n", + "C.java", + "class C { B b; }\n", + }, + ""); + this.runConformTest( + new String[] { + "C.java", + "class C { B b; }\n", + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100809 +public void test0834() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set set = new HashSet();\n" + + " set.add(42);\n" + + " Collection collection;\n" + + " collection = (Collection) set;\n" + + " System.out.println(collection.iterator().next());\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " collection = (Collection) set;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Collection needs unchecked conversion to conform to Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " collection = (Collection) set;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100809 - variation +public void test0835() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(List ls) {\n" + + " ArrayList als = (ArrayList) ls;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " ArrayList als = (ArrayList) ls;\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111208 +public void test0836() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.Iterator;\n" + + " import java.util.List;\n" + + "\n" + + " public class X {\n" + + "\n" + + " interface Factory {\n" + + " T invoke();\n" + + " }\n" + + "\n" + + " public static Iterator iterate(Iterable iterable) {\n" + + " return iterable.iterator();\n" + + " }\n" + + "\n" + + " public Factory> factory(final Factory> factory) {\n" + + " return new Factory>() {\n" + + " public Iterator invoke() {\n" + + " //String s = iterate(factory.invoke());\n" + + " return iterate(factory.invoke());\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111208 - variation +public void test0837() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public void foo(List> l) {\n" + + " bar(l.get(0));\n" + + " swap(l.get(0));\n" + + " }\n" + + " void bar(String s) {}\n" + + " private static void swap(List l) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " bar(l.get(0));\n" + + " ^^^\n" + + "The method bar(String) in the type X is not applicable for the arguments (capture#1-of ? extends List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111689 +public void test0838() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class CClass> {\n" + + " }\n" + + "}\n", + "AClass.java", + "public interface AClass {\n" + + " public interface BClass extends AClass {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109118 +public void test0839() { + this.runConformTest( + new String[] { + "com/test/Tester.java", + "package com.test;\n" + + "\n" + + "import com.test.TestClass.MyException;\n" + + "\n" + + "public class Tester {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " TestClass test = new TestClass();\n" + + " } catch (MyException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + "com/test/TestClass.java", + "package com.test;\n" + + "\n" + + "public class TestClass {\n" + + " \n" + + " public TestClass() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + "\n" + + " public static class MyException extends Exception {\n" + + " \n" + + " public MyException() {\n" + + " super();\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109118 +public void test0840() { + this.runNegativeTest( + new String[] { + "generics/NodeList.java", + "package generics;\n" + + "public class NodeList {\n" + + " public class Cursor { }\n" + + "}", + "generics/user/User.java", + "package generics.user;\n" + + "import generics.NodeList;\n" + + "import generics.NodeList.Cursor;\n" + + "public class User {\n" + + " Cursor raw;\n" + + " NodeList.Cursor rawQualified;\n" + + " NodeList.Cursor parameterized;\n" + + "\n" + + " void foo() {\n" + + " parameterized= rawQualified; //unchecked warning (OK)\n" + + " rawQualified= parameterized;\n" + + "\n" + + " parameterized= raw; //should just give unchecked warning, but errors\n" + + " raw= parameterized; //should not error\n" + + "\n" + + " raw= rawQualified; //should not error\n" + + " rawQualified= raw;\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. WARNING in generics\\user\\User.java (at line 5)\n" + + " Cursor raw;\n" + + " ^^^^^^\n" + + "NodeList.Cursor is a raw type. References to generic type NodeList.Cursor should be parameterized\n" + + "----------\n" + + "2. WARNING in generics\\user\\User.java (at line 6)\n" + + " NodeList.Cursor rawQualified;\n" + + " ^^^^^^^^^^^^^^^\n" + + "NodeList.Cursor is a raw type. References to generic type NodeList.Cursor should be parameterized\n" + + "----------\n" + + "3. WARNING in generics\\user\\User.java (at line 10)\n" + + " parameterized= rawQualified; //unchecked warning (OK)\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type NodeList.Cursor needs unchecked conversion to conform to NodeList.Cursor\n" + + "----------\n" + + "4. WARNING in generics\\user\\User.java (at line 13)\n" + + " parameterized= raw; //should just give unchecked warning, but errors\n" + + " ^^^\n" + + "Type safety: The expression of type NodeList.Cursor needs unchecked conversion to conform to NodeList.Cursor\n" + + "----------\n" + + "5. ERROR in generics\\user\\User.java (at line 19)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112268 +public void test0841() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " List bar() {\n" + + " List l = foo();\n" + + " return foo();\n" + + " }\n" + + " List foo() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112500 +public void test0842() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static List merge(List a, List b) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list1 = null;\n" + + " List list2 = null;\n" + + " List result = merge(list1, list2);\n" + + " List result2 = merge(list1, list2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " List result2 = merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); +} +public void test0843() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static List merge(List a, List b) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list1 = null;\n" + + " List list2 = null;\n" + + " Object result3 = (List)merge(list1, list2);\n" + + " Object result4 = (List)merge(list1, list2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " Object result3 = (List)merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " Object result4 = (List)merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " Object result4 = (List)merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112595 +public void test0844() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " public Set< ? extends X> getModifiers()\n" + + " {\n" + + " return Collections.emptySet();\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112595 +public void test0845() { + this.runConformTest( + new String[] { + "Generic.java", // ================= + "public class Generic {\n" + + " public int size() {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", // ================= + }, + "SUCCESS"); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public void testList(ArrayList aList) {\n" + + " aList.size();\n" + + " }\n" + + " public void testGeneric(Generic aGeneric) {\n" + + " aGeneric.size();\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public void testList(ArrayList aList) {\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public void testGeneric(Generic aGeneric) {\n" + + " ^^^^^^^\n" + + "Generic cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112666 +public void test0846() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.Collection;\n" + + "public class X {\n" + + " void m() {\n" + + " Collection> col = null;\n" + + " java.util.List n = null;\n" + + " col.add(n);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112666 +public void test0847() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.Collection;\n" + + "\n" + + "public class X {\n" + + " void m() {\n" + + " Collection> col = null;\n" + + " java.util.List n = null;\n" + + " col.add(n);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " col.add(n);\n" + + " ^^^\n" + + "The method add(capture#1-of ? extends Collection) in the type Collection> is not applicable for the arguments (List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106451 +public void test0848() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Collection asList= Arrays.asList(1, 2.2);\n" + + " List nums= (List) asList; // correct warning\n" + + " List numz= (LinkedList) asList; // type safety warning missing\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Collection asList= Arrays.asList(1, 2.2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Number&Comparable is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List nums= (List) asList; // correct warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Collection to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " List numz= (LinkedList) asList; // type safety warning missing\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Collection to LinkedList\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Collection asList= Arrays.asList(1, 2.2);\n" + + " List nums= (List) asList; // correct warning\n" + + " List numz= (LinkedList) asList; // type safety warning missing\n" + + "}\n", // ================= + }, + ""); + // ensure presence of: "checkcast java.util.LinkedList" before putfield X.numz + String expectedOutput = + " // Method descriptor #14 ()V\n" + + " // Stack: 6, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [16]\n" + + " 4 aload_0 [this]\n" + + " 5 iconst_2\n" + + " 6 anewarray java.lang.Number [18]\n" + + " 9 dup\n" + + " 10 iconst_0\n" + + " 11 iconst_1\n" + + " 12 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [20]\n" + + " 15 aastore\n" + + " 16 dup\n" + + " 17 iconst_1\n" + + " 18 ldc2_w [26]\n" + + " 21 invokestatic java.lang.Double.valueOf(double) : java.lang.Double [28]\n" + + " 24 aastore\n" + + " 25 invokestatic java.util.Arrays.asList(java.lang.Object[]) : java.util.List [33]\n" + + " 28 putfield X.asList : java.util.Collection [38]\n" + + " 31 aload_0 [this]\n" + + " 32 aload_0 [this]\n" + + " 33 getfield X.asList : java.util.Collection [38]\n" + + " 36 checkcast java.util.List [40]\n" + + " 39 putfield X.nums : java.util.List [42]\n" + + " 42 aload_0 [this]\n" + + " 43 aload_0 [this]\n" + + " 44 getfield X.asList : java.util.Collection [38]\n" + + " 47 checkcast java.util.LinkedList [44]\n" + + " 50 putfield X.numz : java.util.List [46]\n" + + " 53 return\n"; + + 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); + } +} +//ensure no unsafe cast is diagnosed +public void test0849() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static T[] cast(U[] a) { return (T[]) a; }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " static T[] cast(U[] a) { return (T[]) a; }\n" + + " ^^^^^^^\n" + + "Unnecessary cast from U[] to T[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0850() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " T f(Object o) {\n" + + " return (T) o; // OK\n" + + " }\n" + + "\n" + + " T g(Object o) {\n" + + " return (T) o; // bug???\n" + + " }\n" + + "\n" + + " T h(Object o) {\n" + + " return X.castTo(o); // workaround\n" + + " }\n" + + "\n" + + " private static T castTo(Object o) {\n" + + " return (T) o;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (T) o; // OK\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " return (T) o; // bug???\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " return (T) o;\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0851() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "interface Foo {}\n" + + "interface Bar {}\n" + + "public class X {\n" + + " Object m(Foo f) {\n" + + " return (Bar)f;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " return (Bar)f;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Foo to Bar\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " return (Bar)f;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Foo to Bar\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106466 +public void test0852() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " T foo() { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo() { return null; }\n" + + " ^^^^^^^^\n" + + "Cannot specify any additional bound Runnable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112109 +public void test0853() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(java.util.List list) { list.get(0).notify(null); }\n" + + "}\n" + + "interface I { Object notify(Object o); }", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113236 +public void test0854() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Field field = new Field();\n" + + " Form form = new Form(field);\n" + + " String result = form.getField().toString();\n" + + " System.out.print(result);\n" + + " }\n" + + "}", + "Form.java", + "public class Form {\n" + + " private final Field field;\n" + + " public Form(Field field) {\n" + + " this.field = field;\n" + + " }\n" + + " public T getField() {\n" + + " return (T) field;\n" + + " }\n" + + "}", + "Field.java", + "public class Field {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113218 +public void test0855() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " FieldManager manager = new FieldManagerImpl();\n" + + " FieldMeta meta = new FieldMeta(manager);\n" + + " Field field = new FieldImpl(meta);\n" + + " FieldMeta meta2 = field.getFieldMeta();\n" + + " System.out.print(meta2.getFieldManager() instanceof ExtFieldManager);\n" + + " }\n" + + "}", + "FieldMeta.java", + "public class FieldMeta {\n" + + " private final FieldManager fieldManager;\n" + + " public FieldMeta(FieldManager fieldManager) {\n" + + " this.fieldManager = fieldManager;\n" + + " }\n" + + " public > FB getFieldManager() {\n" + + " return (FB) fieldManager;\n" + + " }\n" + + "}", + "FieldManagerImpl.java", + "public class FieldManagerImpl extends FieldManager implements\n" + + " ExtFieldManager {\n" + + "}", + "FieldManager.java", + "public abstract class FieldManager {}", + "FieldImpl.java", + "public class FieldImpl extends Field {\n" + + " public FieldImpl(FieldMeta fieldMeta) {\n" + + " super(fieldMeta);\n" + + " }\n" + + "}", + "Field.java", + "public class Field {\n" + + " private final FieldManager fieldManager;\n" + + " private final FieldMeta fieldMeta;\n" + + " public FieldMeta getFieldMeta() {\n" + + " return fieldMeta;\n" + + " }\n" + + " public Field(FieldMeta fieldMeta) {\n" + + " this.fieldMeta = fieldMeta;\n" + + " this.fieldManager = fieldMeta.getFieldManager();\n" + + " }\n" + + " public FieldManager getFieldManager() {\n" + + " return fieldManager;\n" + + " }\n" + + "}", + "ExtFieldManager.java", + "public interface ExtFieldManager {}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "true" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0856() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static class MX {\n" + + " T t = null;\n" + + " }\n" + + " static T getT() {\n" + + " return (new MX()).t;\n" + + " }\n" + + " public static void test() {\n" + + " getT().getClass(); // error: java.lang.Object cannot be dereferenced\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113070 +public void test0857() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void m(T t) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void m(T t) {\n" + + " ^^^^^^^^^\n" + + "Cannot specify any additional bound Cloneable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113560 +public void test0858() { + this.runConformTest( + new String[] { + "X.java", + "interface ExtCloneable extends Cloneable {\n" + + " public ExtCloneable clone( String arg) throws CloneNotSupportedException;\n" + + "}\n" + + "public class X {\n" + + " public static ExtCloneable cloneItem1( V value) throws CloneNotSupportedException {\n" + + " return value.clone( \"\");\n" + + " }\n" + + " public static ExtCloneable cloneItem2( ExtCloneable value) throws CloneNotSupportedException {\n" + + " return value.clone( \"\");\n" + + " }\n" + + " public static ExtCloneable cloneItem3( V value) throws CloneNotSupportedException {\n" + + " return ((ExtCloneable)value).clone( \"\");\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113710 +public void test0859() { + this.runConformTest( + new String[] { + "X.java", + "import java.awt.Graphics2D;\n" + + "import java.awt.Shape;\n" + + "public class X {\n" + + " /** Base object for wrapping */\n" + + " protected V draw;\n" + + " /**\n" + + " * Draw the object with its attached text\n" + + " * \n" + + " * @param graphics the graphics object to draw into\n" + + " */\n" + + " public void draw( Graphics2D graphics ) {\n" + + " draw.draw(graphics);\n" + + " }\n" + + "}\n" + + "abstract class DrawObject implements Drawable {\n" + + " protected void draw( Graphics2D graphics, Shape shape ) {\n" + + " }\n" + + "}\n" + + "interface Drawable {\n" + + " void draw( Graphics2D graphics );\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 +public void test0860() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " A.I foo();\n" + + " interface I { }\n" + + "}\n" + + "\n" + + "interface B extends A { }\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + " interface J extends B.I { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0861() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " A.I foo();\n" + + " interface I { }\n" + + "}\n" + + "\n" + + "interface B extends A { }\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + " interface J extends A.I { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0862() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo();\n" + + "}\n" + + "\n" + + "interface B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0863() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo();\n" + + "}\n" + + "\n" + + "interface B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "interface C extends B {\n" + + " B.J foo();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0864() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo();\n" + + "}\n" + + "\n" + + "interface B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0865() { + this.runConformTest( + new String[] { + "A.java", + "class A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo() { return null; }\n" + + "}\n" + + "\n" + + "class B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "class C extends B {\n" + + " @Override\n" + + " C.J foo() { return (B.J)super.foo(); }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114997 +public void test0866() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public interface Interface {\n" + + " // nothing\n" + + " }\n" + + " public List field = Collections.emptyList();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114087 +public void test0867() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "class Foo {\n" + + "\n" + + " static List> foo1() {\n" + + " return null;\n" + + " }\n" + + " static void bar1(List> l) {\n" + + " }\n" + + " static List foo2() {\n" + + " return null;\n" + + " }\n" + + " static void bar2(List l) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + "\n" + + " {\n" + + " List o = Foo.foo1();\n" + + " Foo.bar1(o);\n" + + " }\n" + + " {\n" + + " List o = Foo.foo2();\n" + + " Foo.bar2(o);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 20)\n" + + " List o = Foo.foo1();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " List o = Foo.foo1();\n" + + " ^^^^\n" + + "The method foo1() in the type Foo is not applicable for the arguments ()\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " Foo.bar1(o);\n" + + " ^^^^\n" + + "The method bar1(List>) in the type Foo is not applicable for the arguments (List)\n" + + "----------\n" + + "4. WARNING in X.java (at line 24)\n" + + " List o = Foo.foo2();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 25)\n" + + " Foo.bar2(o);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar2(List) of the generic method bar2(List) of type Foo\n" + + "----------\n" + + "6. WARNING in X.java (at line 25)\n" + + " Foo.bar2(o);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114365 +public void test0868() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "import java.io.Serializable;\n" + + "import java.lang.Cloneable;\n" + + "public class X implements Collection {\n" + + " public int size() {\n" + + " // TODO Auto-generated method stub\n" + + " return 0;\n" + + " }\n" + + " public boolean isEmpty() {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean contains(Object arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public Iterator iterator() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public Object[] toArray() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public Object[] toArray(Object[] arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public boolean add(Object arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean remove(Object arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean containsAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean addAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean removeAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean retainAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public void clear() {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115181 +public void test0869() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Comparator.class;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113950 +public void test0870() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public interface I {\n" + + " public void foo(List ls);\n" + + " }\n" + + "\n" + + " public abstract class A implements I {\n" + + " public void foo(List ls) { }\n" + + " }\n" + + "\n" + + " public class C extends A> { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107788 +public void test0871() { + this.runConformTest( + new String[] { + "Lister.java", + "interface Lister {\n" + + " void endPacking(PackT p, BeanT b, Accessor acc);\n" + + "\n" + + " static class IDRefs implements\n" + + " Lister.Pack> {\n" + + " public void endPacking(Pack p, BeanT b, Accessor acc) {\n" + + " }\n" + + "\n" + + " private class Pack {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Accessor {\n" + + "}\n", + }, + ""); +} +public void test0872() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.io.PrintStream;\n" + + "\n" + + "public class X {\n" + + " public void foo1(){\n" + + " M1 m = new M1();\n" + + " M1.N1 n = m.new N1();\n" + + " }\n" + + " static class M1 {\n" + + " class N1 {\n" + + " }\n" + + " }\n" + + " public void foo2(){\n" + + " M2 m = new M2();\n" + + " M2.N2 n = m.new N2();\n" + + " }\n" + + " class M2 {\n" + + " class N2 {\n" + + " }\n" + + " }\n" + + " public void foo3(){\n" + + " M3 m = new M3();\n" + + " M3.N3 n = m.new N3();\n" + + " }\n" + + " class M3 {\n" + + " static class N3 {\n" + + " }\n" + + " }\n" + + " public void foo4(){\n" + + " M4 m = new M4();\n" + + " M4.N4 n = m.new N4();\n" + + " }\n" + + " static class M4 {\n" + + " static class N4 {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " M3.N3 n = m.new N3();\n" + + " ^^^^^^^^\n" + + "The member type X.M3.N3 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M3\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " static class N3 {\n" + + " ^^\n" + + "The member type N3 cannot be declared static; static types can only be declared in static or top level types\n" + + "----------\n" + + "3. ERROR in X.java (at line 30)\n" + + " M4.N4 n = m.new N4();\n" + + " ^^^^^^^^\n" + + "The member type X.M4.N4 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M4\n" + + "----------\n"); +} +public void test0873() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static class XMap {\n" + + " XEntry[] table;\n" + + " static class XEntry {} \n" + + " void foo() {\n" + + " XEntry e = table[0];\n" + + " } \n" + + " } \n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115693 +public void test0874() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "class A {}\n" + + "abstract class B {\n" + + " public B label(String s) { return this; }\n" + + "}\n" + + "final class C extends B {\n" + + " public static C instance(String s) { return new C(); }\n" + + " @Override public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C c = (C)C.instance(\"X\").label(\"Y\");\n" + + " System.out.println(c.toString());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + // ensure only one checkcast C + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc [16]\n" + + " 2 invokestatic C.instance(java.lang.String) : C [17]\n" + + " 5 ldc [23]\n" + + " 7 invokevirtual C.label(java.lang.String) : B [25]\n" + + " 10 checkcast C [18]\n" + + " 13 astore_1 [c]\n" + + " 14 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + + " 17 aload_1 [c]\n" + + " 18 invokevirtual C.toString() : java.lang.String [35]\n" + + " 21 invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 14, line: 14]\n" + + " [pc: 24, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 14, pc: 25] local: c index: 1 type: C\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 +public void test0875() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + "\n" + + " public static class DatabaseObject {}\n" + + " public static class ObjectFormUI {}\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + "\n" + + " public static Class> getUI(\n" + + " Class persistentClass) {\n" + + " return null != null \n" + + " ? uiMap.get(persistentClass)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + " ^^^^^^^^^^^^\n" + + "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + " ^^^^^^^^^^^^\n" + + "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " return null != null \n" + + " ? uiMap.get(persistentClass)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 - variation +public void test0876() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " void foo(){\n" + + " Class> cco = null;\n" + + " Class cc = cco; // ko\n" + + " Class> cco2 = cc; // ko\n" + + " \n" + + " Class> ceco = null;\n" + + " Class cec = ceco; // ok\n" + + " Class> ceco2 = cec; // ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Class cc = cco; // ko\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Class cc = cco; // ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Class> to Class\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Class> cco2 = cc; // ko\n" + + " ^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Class cec = ceco; // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " Class> ceco2 = cec; // ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 - variation +public void test0877() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " void bar(T t) {\n" + + " Class c = t; // ok - unchecked\n" + + " }\n" + + " void bar2(List let) {\n" + + " Class c = let.get(0); // ok - unchecked\n" + + " }\n" + + " void bar3(List lec) {\n" + + " Class c = lec.get(0); // ok - unchecked\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void bar(T t) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void bar(T t) {\n" + + " ^^^^^\n" + + "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Class c = t; // ok - unchecked\n" + + " ^\n" + + "Type safety: The expression of type T needs unchecked conversion to conform to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " void bar2(List let) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " void bar2(List let) {\n" + + " ^^^^^\n" + + "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " Class c = let.get(0); // ok - unchecked\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type capture#1-of ? extends T needs unchecked conversion to conform to Class\n" + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " void bar3(List lec) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 10)\n" + + " Class c = lec.get(0); // ok - unchecked\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type capture#2-of ? extends Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "9. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115693 - variation +public void test0878() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "class A {}\n" + + "class D extends A {}\n" + + "abstract class B {\n" + + " public T label(String s) { return null; }\n" + + "}\n" + + "final class C extends B {\n" + + " public static C instance(String s) { return new C(); }\n" + + " @Override public String toString() {\n" + + " return \"SUCCESS\"; \n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = (D)C.instance(\"X\").label(\"Y\");\n" + + " System.out.println(d);\n" + + " }\n" + + "}\n", + }, + "null"); + // ensure only one checkcast D + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc [16]\n" + + " 2 invokestatic C.instance(java.lang.String) : C [17]\n" + + " 5 ldc [23]\n" + + " 7 invokevirtual C.label(java.lang.String) : java.lang.Object [25]\n" + + " 10 checkcast D [29]\n" + + " 13 astore_1 [d]\n" + + " 14 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 17 aload_1 [d]\n" + + " 18 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [37]\n" + + " 21 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 14, line: 15]\n" + + " [pc: 21, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 22] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 14, pc: 22] local: d index: 1 type: D\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122610 +public void test0879() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + "\n" + + " private class InnerClass1 {\n" + + " void foo() {\n" + + " X c = X.this;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 +public void test0880() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class Foo {\n" + + " static > U foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " {\n" + + " String s = (String) Foo.foo();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = (String) Foo.foo();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation +public void test0881() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class Foo {\n" + + " static > U foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " {\n" + + " String s = (String) Foo.foo();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = (String) Foo.foo();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List> to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " String s = (String) Foo.foo();\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo() of type Foo is not applicable for the arguments (). The inferred type List> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation +public void test0882() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static > U foo(U u) {\n" + + " String s = (String) foo(u);\n" + + " return u;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " String s = (String) foo(u);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot cast from U to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation +public void test0883() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static > U foo(U u) {\n" + + " List listu = null;\n" + + " String s = (String)foo(listu);\n" + + " return u;\n" + + " }\n" + + " static > V bar(V v) {\n" + + " List listv = null;\n" + + " String s = (String)foo(listv);\n" + + " return v;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = (String)foo(listu);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = (String)foo(listu);\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(U) of type X is not applicable for the arguments (List). The inferred type List is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " String s = (String)foo(listv);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " String s = (String)foo(listv);\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(U) of type X is not applicable for the arguments (List). The inferred type List is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=123078 +public void test0884() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public abstract class X> {\n" + + " public static > T getDefault(Class clz) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Object getDefault() {\n" + + " String s = getClass();\n" + + " return (String) getDefault(getClass());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " String s = getClass();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return (String) getDefault(getClass());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from capture#2-of ? extends X to String\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " return (String) getDefault(getClass());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation getDefault(Class) of the generic method getDefault(Class) of type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125445 +public void test0885() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static > int m(\n" + + " A comparableNumberObj) {\n" + + " return comparableNumberObj.compareTo(comparableNumberObj);\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static > int m(\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124943 +public void test0886() { + Map customOptions= getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " void test() {\n" + + " \"Hello\".compareTo((Object) \"Hello\");\n" + + " }\n" + + "}\n" , + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + new JavacTestOptions("-source 1.4") /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 +public void test0887() { + this.runNegativeTest( + new String[] { + "Bar.java", // ================= + "class Foo {}\n" + + "public class Bar>>{\n" + + " Bar(X x){\n" + + " Foo f = x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Bar.java (at line 4)\n" + + " Foo f = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to Foo\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0888() { + this.runNegativeTest( + new String[] { + "Bar.java", // ================= + "class Foo {}\n" + + "public class Bar>>{\n" + + " Bar(X x){\n" + + " Foo f = x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Bar.java (at line 4)\n" + + " Foo f = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to Foo\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0889() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "Test.java", // ================= + "import java.util.*;\n" + + "\n" + + "class Group> extends ArrayList implements\n" + + " Comparable> {\n" + + " public int compareTo(Group o) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sequence> extends TreeSet implements\n" + + " Comparable> {\n" + + " public int compareTo(Sequence o) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "class Test> {\n" + + " > void foo(SortedSet setToCheck,\n" + + " SortedSet validSet) {\n" + + " }\n" + + "\n" + + " public void containsCombination(SortedSet> groups,\n" + + " SortedSet> sequences) {\n" + + " foo(groups, sequences);\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0890() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "Simple.java", // ================= + "class A> {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class D {}\n" + + "\n" + + "public class Simple {\n" + + " , S extends T> D m(S s) {\n" + + " C c = null;\n" + + " D d = m(c);\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0891() { + this.runNegativeTest( + new String[] { + "Test.java", // ================= + "interface Function {\n" + + " B apply(A x);\n" + + "}\n" + + "class Id implements Function {\n" + + " public A apply(A x) {\n" + + " return x;\n" + + " }\n" + + "}\n" + + "class Test {\n" + + " Id identity() {\n" + + " return new Id();\n" + + " }\n" + + "\n" + + " B applyToString(Function f) {\n" + + " return f.apply(\"abc\");\n" + + " }\n" + + " void test() {\n" + + " String s = applyToString(identity());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 18)\n" + + " String s = applyToString(identity());\n" + + " ^^^^^^^^^^^^^\n" + + "The method applyToString(Function) in the type Test is not applicable for the arguments (Id)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126180 +public void test0892() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C2 c2 = null;\n" + + " C3 c3 = null;\n" + + " Object oc1 = m1(c2, c3).new C1Member();\n" + + " }\n" + + "\n" + + " public static T m1(T t1, T t2) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " class C1 {}\n" + + " interface I1 {}\n" + + " class C2 extends C1 implements I1 {}\n" + + " class C3 extends C1 implements I1 {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Object oc1 = m1(c2, c3).new C1Member();\n" + + " ^^^^^^^^\n" + + "X.C1&X.I1.C1Member cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126177 +public void test0893() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static String foo;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " C2 c2 = null;\n" + + " C3 c3 = null;\n" + + " // method access\n" + + " m1(c2, c3).c1m1();\n" + + " m1(c2, c3).i1m1();\n" + + " m1(c2, c3).i2m1();\n" + + "\n" + + " // field access\n" + + " int ic1 = m1(c2, c3).c1f1;\n" + + " int ii1 = m1(c2, c3).i1f1;\n" + + " int ii2 = m1(c2, c3).i2f1;\n" + + " \n" + + " // member type access\n" + + " Object oc1 = m1(c2, c3).new C1Member();\n" + + " Object oi1 = m1(c2, c3).new I1Member(); \n" + + " Object oi2 = m1(c2, c3).new I2Member();\n" + + " }\n" + + "\n" + + " public static T m1(T t1, T t2) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " class C1 {\n" + + " void c1m1() {}\n" + + " int c1f1 = 0;\n" + + " class C1Member {}\n" + + " }\n" + + "\n" + + " interface I1 {\n" + + " void i1m1();\n" + + " int i1f1 = 1;\n" + + " class I1Member {}\n" + + " }\n" + + "\n" + + " interface I2 {\n" + + " void i2m1();\n" + + " int i2f1 = 2;\n" + + " class I2Member {}\n" + + " }\n" + + "\n" + + " class C2 extends C1 implements I1, I2 {\n" + + " public void i1m1() {\n" + + " }\n" + + " public void i2m1() {\n" + + " }\n" + + " }\n" + + "\n" + + " class C3 extends C1 implements I1, I2 {\n" + + " public void i1m1() {\n" + + " }\n" + + " public void i2m1() {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " int ii1 = m1(c2, c3).i1f1;\n" + + " ^^^^\n" + + "The static field X.I1.i1f1 should be accessed in a static way\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " int ii2 = m1(c2, c3).i2f1;\n" + + " ^^^^\n" + + "The static field X.I2.i2f1 should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " Object oi1 = m1(c2, c3).new I1Member(); \n" + + " ^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type X.I1.I1Member\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " Object oi2 = m1(c2, c3).new I2Member();\n" + + " ^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type X.I2.I2Member\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126177 - variation +public void test0894() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " static class C1 {\n" + + " void c1m1() {\n" + + " System.out.print(\"[c1m1]\");\n" + + " }\n" + + " }\n" + + " static interface I {}\n" + + " static class C2 extends C1 implements I {}\n" + + " static class C3 extends C1 implements I {}\n" + + "\n" + + " public T m1(T t1, T t2) {\n" + + " return t1;\n" + + " }\n" + + "\n" + + " public void test(C2 c2, C3 c3, T t) {\n" + + " m1(c2, c3).c1m1(); // 1\n" + + " t.c1m1(); // 2\n" + + " (t != null ? c2 : c3).c1m1(); // 3\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " X x = new X();\n" + + " x.test(new C2(), new C3(), new C2()); // 4\n" + + " System.out.println();\n" + + " }\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "[c1m1][c1m1][c1m1]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0895() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "interface I {}\n" + + "public class X {\n" + + " Object o = new I() {};\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new I() {};\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor Object() of type Object is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", // ================= + "interface I {}\n" + + "public class X {\n" + + " Object o = new I() {};\n" + + "}\n" , + "Y.java", + "class Y extends Zork {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = new I() {};\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Object() of type Object; it should not be parameterized with arguments \n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0896() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " interface I { void f(); }\n" + + " interface J { void g(); }\n" + + "\n" + + " static class A implements I, J {\n" + + " public void f() { System.out.print(\"[A#f()]\");}\n" + + " public void g() { System.out.print(\"[A#g()]\");}\n" + + " }\n" + + "\n" + + " static class B implements J, I {\n" + + " public void f() { System.out.print(\"[B#f()]\");}\n" + + " public void g() { System.out.print(\"[B#g()]\");}\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " f(true, new A(), new B());\n" + + " f(false, new A(), new B());\n" + + " System.out.println();\n" + + " }\n" + + "\n" + + " static void f(boolean cond, A a, B b) {\n" + + " (cond ? a : b).f();\n" + + " (cond ? a : b).g();\n" + + " }\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "[A#f()][A#g()][B#f()][B#g()]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0897() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "Test.java", // ================= + "interface I { }\n" + + "class X { }\n" + + "class A extends X implements I { }\n" + + "class B extends X implements I { }\n" + + "public class Test {\n" + + " void test(A a, B b) {\n" + + " X x = (a.hashCode() == b.hashCode()) ? a : b;\n" + + " }\n" + + "}\n" + + "\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0898() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", // ================= + "interface I1 {\n" + + " void i1();\n" + + "}\n" + + "class G1 {\n" + + " T get() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface I2 {\n" + + " void i2();\n" + + "}\n" + + "public class X {\n" + + " void f1(G1 g1) {\n" + + " g1.get().i1();\n" + + " }\n" + + " void f2(G1 g1) {\n" + + " g1.get().i1();\n" + + " g1.get().i2();\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122331 +public void test0899() { + this.runConformTest( + new String[] { + "A.java", // ================= + "public class A> extends SomeArbitraryClass {\n" + + " public static class B {\n" + + " private C c;\n" + + " protected void set(C val) {\n" + + " c = val;\n" + + " }\n" + + " protected class C {\n" + + " }\n" + + " }\n" + + "}", + "C.java", + "public class C {\n" + + " \n" + + " public C() {\n" + + " //do nothing\n" + + " }\n" + + " \n" + + "}", + "ObjThatExtendsB.java", + "public class ObjThatExtendsB extends A.B {\n" + + " protected void doSomeSetting() {\n" + + " super.set(new ObjThatExtendsC());\n" + + " }\n" + + " protected class ObjThatExtendsC extends C {\n" + + " }\n" + + "}", + "ObjThatExtendsC.java", + "public class ObjThatExtendsC extends C {\n" + + " public ObjThatExtendsC() {\n" + + " //do nothing\n" + + " }\n" + + "}", + "SomeArbitraryClass.java", + "public class SomeArbitraryClass> {\n" + + " public SomeArbitraryClass() {\n" + + " //do nothing\n" + + " }\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97693 +public void test0900() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static interface Interface extends Comparable {}\n" + + "\n" + + " static final class Implements implements Interface {\n" + + " public int compareTo(String o) {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " void method() {\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " ((Comparable) new Implements()).toString();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.Implements to Comparable\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " ((Comparable) new Implements()).toString();\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// Object array vs Object into generic method +public void test0901() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static T foo(T p1, T p2) {\n" + + " return p1;\n" + + " }\n" + + " static Object[] bar(int[] i, float[] f) {\n" + + " return foo(i, f);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return foo(i, f);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object&Serializable&Cloneable to Object[]\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// circular references amongst generic interfaces with co-implementing classes +public void test0902() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "I.java", + "public interface I>> {\n" + + "}", + "J.java", + "public interface J>> {\n" + + "}", + "CI.java", + "class CI & J,\n" + + " T extends CI & I>\n" + + " implements I {\n" + + "}", + "CJ.java", + "class CJ & I,\n" + + " U extends CJ & J>\n" + + " implements J {\n" + + "}"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126914 +public void test0903() { + this.runConformTest( + new String[] { + "X.java", + "interface I, U extends I> {\n" + + " // empty\n" + + "}\n" + + "interface J, U extends I> {\n" + + " // empty\n" + + "}\n" + + "final class Y extends X implements I, Y> {\n" + + " // empty\n" + + "}\n" + + "abstract class X implements J, Y> {\n" + + " // empty\n" + + "}\n" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126914 +public void test0904() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "interface I, U extends I> {\n" + + " // empty\n" + + "}\n" + + "interface J, U extends I> {\n" + + " // empty\n" + + "}\n" + + "abstract class X implements J, Y> {\n" + + " // empty\n" + + "}\n" + + "final class Y extends X implements I, Y> {\n" + + " // empty\n" + + "}\n" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// array in super bound +public void test0905() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.List;\n" + + " \n" + + "class X {\n" + + " void foo(List p) {\n" + + " p.add(new Object[0]);\n" + + " }\n" + + "}"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// raw types in casts +public void test0906() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " // empty\n" + + "} \n" + + "public class X implements I {\n" + + " I x1 = (I) (X) null;\n" + + " I x2 = (I) new X();\n" + + " I x3 = (I) null;\n" + + " X x4 = (X) (I) null;\n" + + "}"}, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public class X implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " I x1 = (I) (X) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to I\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " I x1 = (I) (X) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to I\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " I x1 = (I) (X) null;\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from null to X\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " I x2 = (I) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to I\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " I x2 = (I) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to I\n" + + "----------\n" + + "7. WARNING in X.java (at line 7)\n" + + " I x3 = (I) null;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from null to I\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " X x4 = (X) (I) null;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from null to I\n" + + "----------\n"); +} + +// parametrized method with array extends Object upper bound verification +public void test0907() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "public class X, V> {\n" + + " public void foo() {\n" + + " Y o = (new Z()). bar(Collections\n" + + " .singleton(new Y()));\n" + + " o.toString();\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " // empty\n" + + "}\n" + + "class Z {\n" + + " public , W extends V> U bar(Collection c) {\n" + + " return null;\n" + + " }\n" + + "}\n"}, + ""); +} + +// check capture for conditional operator - variant +public void test0908() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public abstract class X {\n" + + " protected void foo(Class clazz) {\n" + + " Class l = clazz.isInterface() ? bar(clazz) : clazz;\n" + + " }\n" + + " abstract public Class bar(Class p);\n" + + "}"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126105 +public void test0909() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class B {\n" + + " private Object x;\n" + + "\n" + + " public B(T x) {\n" + + " this.x = x;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class C {\n" + + " private Object x;\n" + + "\n" + + " public C(Object x) {\n" + + " this.x = x;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Throwable {\n" + + " B b = new B(\"foo\");\n" + + " System.out.println(b.x);\n" + + "\n" + + " C c = new C(\"foo\");\n" + + " System.out.println(c.x);\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 +public void test0910() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List> lc2 = null;\n" + + " List> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ko\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ko\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ok\n" + + " lc4 = lc3; //12 ok\n" + + " }\n" + + " private final List aList = new ArrayList();\n" + + " public void foo() {\n" + + " final List> listCopy = new ArrayList>(this.aList); // ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "9. ERROR in X.java (at line 18)\n" + + " lc3 = lc1; //7 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "10. ERROR in X.java (at line 20)\n" + + " lc3 = lc4; //9 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "11. WARNING in X.java (at line 25)\n" + + " private final List aList = new ArrayList();\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 25)\n" + + " private final List aList = new ArrayList();\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "13. ERROR in X.java (at line 27)\n" + + " final List> listCopy = new ArrayList>(this.aList); // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor ArrayList>(List) is undefined\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0911() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List> lc2 = null;\n" + + " List> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ok\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ok\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ko\n" + + " lc4 = lc3; //12 ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "9. ERROR in X.java (at line 21)\n" + + " lc4 = lc2; //11 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "10. ERROR in X.java (at line 22)\n" + + " lc4 = lc3; //12 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0912() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo(List[]> l1, List l2) {\n" + + " l1 = l2;\n" + + " l2 = l1;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List[]> l1, List l2) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " l1 = l2;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " l2 = l1;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0913() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List[]> lc2 = null;\n" + + " List[]> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ko\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ko\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ok\n" + + " lc4 = lc3; //12 ok \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List[]>\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "9. ERROR in X.java (at line 14)\n" + + " lc3 = lc1; //7 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "10. ERROR in X.java (at line 16)\n" + + " lc3 = lc4; //9 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0914() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List[]> lc2 = null;\n" + + " List[]> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ok\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ok\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ko\n" + + " lc4 = lc3; //12 ko \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List[]>\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "9. ERROR in X.java (at line 18)\n" + + " lc4 = lc2; //11 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "10. ERROR in X.java (at line 19)\n" + + " lc4 = lc3; //12 ko \n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128389 +public void test0915() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y1 extends Throwable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " T t;\n" + + " }\n" + + " static class Y2 extends Throwable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " class Y3 extends Throwable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "\n" + + " T t;\n" + + " }\n" + + "}\n" + + "class Y4 extends Throwable {}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y1 extends Throwable {\n" + + " ^^^^^^^^^\n" + + "The generic class X.Y1 may not subclass java.lang.Throwable\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y3 extends Throwable {\n" + + " ^^^^^^^^^\n" + + "The generic class X.Y3 may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " class Y4 extends Throwable {}\n" + + " ^^\n" + + "The serializable class Y4 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " class Y4 extends Throwable {}\n" + + " ^^^^^^^^^\n" + + "The generic class Y4 may not subclass java.lang.Throwable\n" + + "----------\n"); +} + +// synchronized inheritance for multiple generic types +public void test0916() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X> {\n" + + " T m2;\n" + + " T getX2() {\n" + + " return this.m2;\n" + + " }\n" + + "}\n" + + "class X2 {\n" + + " T m3;\n" + + " T getX3() {\n" + + " return this.m3;\n" + + " }\n" + + "}\n" + + "class X3 {\n" + + "}\n" + + "class Y1> extends X {\n" + + " public void foo() {\n" + + " getX2().getX3().bar(); // getX3 appropriately returns an Y3\n" + + " }\n" + + "}\n" + + "class Y2 extends X2 {\n" + + "}\n" + + "class Y3 extends X3 {\n" + + " public void bar() {\n" + + " }\n" + + "}\n"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 +// [1.5][compiler] ClassCastException on illegal code fragment +public void test0917() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X2 { }\n" + + "class X2 { }\n" + + "class A { static class M {} }" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X2 { }\n" + + " ^^^\n" + + "Illegal qualified access from the type parameter T\n" + + "----------\n" + // cannot select from a type variable + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation +public void test0917a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X2 { }\n" + + "class X2 { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X2 { }\n" + + " ^^^^^^^\n" + + "Illegal qualified access from the type parameter T\n" + + "----------\n" + // cannot select from a type variable + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation +public void test0917b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { Class c = T.class; }" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { Class c = T.class; }\n" + + " ^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation +public void test0917c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X2 { }\n" + + "class X2 { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X2 { }\n" + + " ^^^^^\n" + + "Syntax error on token \"class\", Identifier expected\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128560 +public void test0918() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "BasicNode.java", + "class BasicEdge & Node, E extends BasicEdge & Edge>\n" + + " implements Edge {\n" + + "}\n" + + "\n" + + "public class BasicNode & Edge, N extends BasicNode & Node>\n" + + " implements Node {\n" + + "}\n" + + "\n" + + "interface Edge>> {\n" + + "}\n" + + "\n" + + "interface Node>> {\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +public void test0919() { + this.runConformTest( + new String[] { + "X.java", + "class Box {\n" + + " private E element;\n" + + " void put(E elem) {\n" + + " this.element = elem;\n" + + " }\n" + + " E get() {\n" + + " return this.element;\n" + + " }\n" + + " Pair asPair() {\n" + + " return new Pair(this.element, this.element);\n" + + " }\n" + + " Box> nest() {\n" + + " Box> wrapper = new Box>();\n" + + " wrapper.put(this);\n" + + " return wrapper;\n" + + " }\n" + + "}\n" + + "\n" + + "class Pair {\n" + + " Pair(U u, V v) {\n" + + " }\n" + + "}\n" + + "\n" + + "class PandoraBox> extends Box {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void test(PandoraBox pbox) {\n" + + " Box box = pbox.get();\n" + + " Pair pair = pbox.asPair();\n" + + " Box nbox = pbox.nest();\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test0920() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class Stack {\n" + + " private List contents = new ArrayList();\n" + + " void push(E e) {\n" + + " this.contents.add(e);\n" + + " }\n" + + " E pop() {\n" + + " int last = this.contents.size() - 1;\n" + + " if (last < 0) throw new EmptyStackException();\n" + + " return this.contents.remove(last);\n" + + " }\n" + + " private static void doSwap(Stack s) {\n" + + " T t1 = s.pop();\n" + + " T t2 = s.pop();\n" + + " s.push(t1);\n" + + " s.push(t2);\n" + + " }\n" + + " static void swap(Stack s) { doSwap(s); }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Stack si = new Stack();\n" + + " Integer[] ints = { 12, 13, 14, 15, };\n" + + " for (Integer i : ints) si.push(i);\n" + + " try {\n" + + " while(true) {\n" + + " System.out.print(\"[\"+si.pop()+\"]\");\n" + + " }\n" + + " } catch(EmptyStackException e) {\n" + + " System.out.println(\"[done]\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "[15][14][13][12][done]"); +} +public void test0921() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "Graph.java", + "class Node, E extends Edge> {\n" + + "}\n" + + "class Edge, E extends Edge> {\n" + + "}\n" + + "class Graph, E extends Edge>{\n" + + " N n;\n" + + " E e;\n" + + " private Graph(N n, E e) {\n" + + " this.n = n;\n" + + " this.e = e;\n" + + " }\n" + + " static , E extends Edge>\n" + + " Graph copy(Graph g) {\n" + + " return create(g.n,g.e);\n" + + " }\n" + + " static , E extends Edge>\n" + + " Graph create(N n, E e) {\n" + + " return new Graph(n,e);\n" + + " }\n" + + " Graph builder() {\n" + + " Graph g = null;\n" + + " return copy(g);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +// Test case which comes from JDT/UI tests TypeEnvironmentTest.testWildcardAssignements +public void test0922() { + this.runNegativeTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "public class Test {\n" + + " List list_raw_list;\n" + + " {\n" + + " Collection> col = list_raw_list;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " List list_raw_list;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " Collection> col = list_raw_list;\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to Collection>\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129129 +public void test0923() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static void a(Class> c) {}\n" + + "\n" + + " static void b(X t) {\n" + + " X.a(t.getClass());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.a(t.getClass());\n" + + " ^\n" + + "The method a(Class>) in the type X is not applicable for the arguments (Class)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 +public void test0924() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "ExtendedOuter.java", + "class Outer {\n" + + " class Inner {\n" + + " }\n" + + "\n" + + " static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new ExtendedOuter().new ExtendedInner();\n" + + " }\n" + + "}\n" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0925() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " private List toAdd;\n" + + "\n" + + " public X(List toAdd) {\n" + + " this.toAdd = toAdd;\n" + + " }\n" + + "\n" + + " private List getRelated(B b) {\n" + + " // some application logic\n" + + " // for demo\n" + + " return toAdd;\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public , LF extends Factory> L addOrCreate4(\n" + + " B b, L l, LF lf) {\n" + + " if (l == null) {\n" + + " l = lf.create();\n" + + " }\n" + + " ((List) l).addAll(getRelated(b)); \n" + + " l.addAll(getRelated(b));\n" + + " return l;\n" + + " }\n" + + "\n" + + " public static class ListFactory implements Factory> {\n" + + " public List create() {\n" + + " return new ArrayList();\n" + + " }\n" + + " }\n" + + "\n" + + " public static interface Factory {\n" + + " public T create();\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " ListFactory lf = new ListFactory();\n" + + " List longs = new ArrayList();\n" + + " longs.add(new Long(1));\n" + + " X test = new X(longs);\n" + + " List ret4 = null;\n" + + " ret4 = test.addOrCreate4(1, ret4, lf);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 +public void test0926() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "\n" + + " public void foo() {\n" + + " NonTerminalSourcePart> RESULT = null;\n" + + " NonTerminalSourcePart> t = null;\n" + + " RESULT = NonTerminalSourcePart.create(Tuple.create(true, t.value().fst()));\n" + + " }\n" + + "}\n" + + "\n" + + "class Term {\n" + + "}\n" + + "\n" + + "class Formula {\n" + + "}\n" + + "\n" + + "final class NonTerminalSourcePart {\n" + + " static NonTerminalSourcePart create(final V _value) {\n" + + " return null;\n" + + " }\n" + + " final V value() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class Tuple {\n" + + " public static Tuple create(final A a, final B b) {\n" + + " return null;\n" + + " }\n" + + " public A fst() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " RESULT = NonTerminalSourcePart.create(Tuple.create(true, t.value().fst()));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from NonTerminalSourcePart> to NonTerminalSourcePart>\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6557661 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0927() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " List> RESULT = null;\n" + + " List lst = null;\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " }\n" + + " public void bar() {\n" + + " List> RESULT = null;\n" + + " List lst = null;\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " }\n" + + " public void baz() {\n" + + " List> RESULT = null;\n" + + " List lst = null;\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " }\n" + + " public void bar2(List lst) {\n" + + " List RESULT = null;\n" + + " RESULT = lst;\n" + + " RESULT = Collections.singletonList(lst.get(0));\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " List ls = new ArrayList();\n" + + " ls.add(\"str\");\n" + + " new X().bar2(ls);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " RESULT = lst;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 21)\n" + + " RESULT = Collections.singletonList(lst.get(0));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0928() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " List x1 = new ArrayList();\n" + + " List x2 = new ArrayList();\n" + + " x1.addAll(x2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x1.addAll(x2);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117119 +public void test0929() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static > void fails () {\n" + + " Class enumType = null;\n" + + " final Collection test = allOf(enumType);\n" + + "\n" + + " Collection colType = null;\n" + + " final Collection test2 = colType;\n" + + " }\n" + + " \n" + + " public static > Collection allOf(final Class enumType) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Class enumType = null;\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " final Collection test = allOf(enumType);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " final Collection test = allOf(enumType);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to Collection\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Collection colType = null;\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " final Collection test2 = colType;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to Collection\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 +public void test0930() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int I;\n" + + " public void foo() {\n" + + " X.I= 10;\n" + + " }\n" + + " { Zork z; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " { Zork z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 - variation +public void test0931() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int I;\n" + + " public void foo() {\n" + + " X.I= 10;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.I= 10;\n" + + " ^\n" + + "Syntax error on token \"I\", VariableDeclaratorId expected after this token\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 - variation +public void test0932() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int Method() { return 0; }\n" + + " public void foo() {\n" + + " X.Method();\n" + + " }\n" + + " public void bar() {\n" + + " X.Method();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X.Method();\n" + + " ^^^^^^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 +public void test0933() { + this.runNegativeTest( + new String[] { + "a/AbstractFoo.java", //================================ + "package a;\n" + + "public abstract class AbstractFoo> {\n" + + " protected static class Inner> {\n" + + " public Inner() {\n" + + " }\n" + + "\n" + + " public final void doSmth() {\n" + + " }\n" + + " }\n" + + "}\n", + "b/CustomFoo.java", //================================ + "package b;\n" + + "import a.AbstractFoo;\n" + + "public final class CustomFoo extends AbstractFoo {\n" + + " private Inner defaultInner;\n" + + "\n" + + " Inner getDefaultInner() {\n" + + " return (this.defaultInner == null)\n" + + " ? this.defaultInner = new Inner()\n" + + " : this.defaultInner;\n" + + " } \n" + + "\n" + + " private Inner customInner;\n" + + "\n" + + " Inner getCustomInner() {\n" + + " return (this.customInner == null)\n" + + " ? this.customInner = new Inner()\n" + + " : this.customInner;\n" + + " } \n" + + "}\n", + "b/DefaultFoo.java", //================================ + "package b;\n" + + "import a.AbstractFoo;\n" + + "public final class DefaultFoo extends AbstractFoo {\n" + + " private Inner defaultInner;\n" + + "\n" + + " Inner getDefaultInner() {\n" + + " return (this.defaultInner == null)\n" + + " ? this.defaultInner = new Inner()\n" + + " : this.defaultInner;\n" + + " } \n" + + "\n" + + " private Inner customInner;\n" + + "\n" + + " Inner getCustomInner() {\n" + + " return (this.customInner == null)\n" + + " ? this.customInner = new Inner()\n" + + " : this.customInner;\n" + + " }\n" + + "\n" + + " ///////////////////////////////////////////////////////////////////////\n" + + " public void testCompilationFailure(final CustomFoo foo) {\n" + + " final DefaultFoo foo1 = this;\n" + + " final CustomFoo foo2 = foo;\n" + + "\n" + + " // These get compiled w/o error:\n" + + " foo1.getCustomInner().doSmth();\n" + + " foo1.getDefaultInner().doSmth();\n" + + "\n" + + " // These do not (Eclipse 3.2.0 M4):\n" + + " foo2.getCustomInner().doSmth();\n" + + " foo2.getDefaultInner().doSmth();\n" + + "\n" + + " // Expect error\n" + + " String s11 = foo1.getCustomInner();\n" + + " String s12 = foo2.getDefaultInner();\n" + + " String s21 = foo2.getCustomInner();\n" + + " String s22 = foo2.getDefaultInner();\n" + + "\n" + + " // However, if we split statements, everything\'s ok: \n" + + " final Inner customInner2 = foo2.getCustomInner();\n" + + " customInner2.doSmth();\n" + + "\n" + + " final Inner defaultInner2 = foo2.getDefaultInner();\n" + + " defaultInner2.doSmth();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in b\\DefaultFoo.java (at line 34)\n" + + " String s11 = foo1.getCustomInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n" + + "2. ERROR in b\\DefaultFoo.java (at line 35)\n" + + " String s12 = foo2.getDefaultInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n" + + "3. ERROR in b\\DefaultFoo.java (at line 36)\n" + + " String s21 = foo2.getCustomInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n" + + "4. ERROR in b\\DefaultFoo.java (at line 37)\n" + + " String s22 = foo2.getDefaultInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation +public void test0934() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " static class Inner {\n" + + " static class InInner {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " Inner inner = null;\n" + + " String s = inner;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = inner;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X.Inner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation +public void test0935() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " static class Inner {\n" + + " class InInner {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " Inner.InInner inner = null;\n" + + " String s = inner;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = inner;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X.Inner.InInner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation +public void test0936() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " class Inner {\n" + + " class InInner {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " Inner inner = null;\n" + + " String s = inner;\n" + + " \n" + + " Inner.InInner inner2 = null;\n" + + " s = inner2;\n" + + "\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = inner;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X.Inner to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " s = inner2;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Inner.InInner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +public void test0937() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static void method(Outer.Inner x) {}\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in ExtendedOuter.java (at line 4)\n" + + " static void method(Outer.Inner x) {}\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +public void test0938() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static void method(Outer.Inner x) {}\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +public void test0939() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static void method(Outer.Inner x) {}\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0940() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " void bar3(List lst) {\n" + + " List RESULT = null;\n" + + " RESULT = lst; // 1\n" + + " RESULT = Collections.singletonList(lst.get(0)); // 2\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " RESULT = lst; // 1\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " RESULT = Collections.singletonList(lst.get(0)); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0941() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Map foo(T t1, T t2) {\n" + + " return null;\n" + + " }\n" + + " void bar(U u, V v) {\n" + + " Map map1 = foo(u, v);\n" + + " Map map2 = foo(u, v);\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map map1 = foo(u, v);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0942() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Map foo(T t1, T t2, T t3) {\n" + + " return null;\n" + + " }\n" + + " void bar(U u, V v) {\n" + + " Map map1 = foo(u, v, null);\n" + + " Map map2 = foo(u, v, null);\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map map1 = foo(u, v, null);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0943() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Map foo(T t1, T t2, T t3) {\n" + + " return null;\n" + + " }\n" + + " void bar(U u, V v, List lv) {\n" + + " Map map1 = foo(u, v, lv.get(0));\n" + + " Map map2 = foo(u, v, lv.get(0));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map map1 = foo(u, v, lv.get(0));\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129996 +public void test0944() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " public static Set method(List list) {\n" + + " return new HashSet();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ArrayList l = new ArrayList();\n" + + " Set s1 = method(l);\n" + + " Set s2 = (Set) method(l);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Set s2 = (Set) method(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Set to Set\n" + + "----------\n"); +} +public void test0945() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args){\n" + + " Object[] objArray = {new Object()};\n" + + " ArrayList strList = new ArrayList();\n" + + " transferBug(objArray, strList);\n" + + " String str = strList.get(0);\n" + + "}\n" + + "public static void transferBug(Var[] src, Collection dest){\n" + + " dest.add(src[0]);\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " transferBug(objArray, strList);\n" + + " ^^^^^^^^^^^\n" + + "The method transferBug(Var[], Collection) in the type X is not applicable for the arguments (Object[], ArrayList)\n" + + "----------\n"); +} +public void test0946() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", //================================ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " operate(Operations.create());\n" + + " }\n" + + " static > void operate(Operators operators) {\n" + + " System.out.println(operators.spawn());\n" + + " }\n" + + "}\n" + + "class Operations {\n" + + " static Operators create() {\n" + + " return new IntOperators();\n" + + " }\n" + + "}\n" + + "interface Num {\n" + + " public O spawn();\n" + + "}\n" + + "class Int implements Num {\n" + + " public Int spawn() {\n" + + " return new Int();\n" + + " }\n" + + " public String toString() {\n" + + " return \"Int\";\n" + + " }\n" + + "}\n" + + "interface Operators> {\n" + + " O spawn();\n" + + "}\n" + + "class IntOperators implements Operators {\n" + + " public Int spawn() {\n" + + " return new Int();\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "Int" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0947() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " public void bar2(Box b) {\n" + + " Box bx = box(b.element);\n" + + " box(b.element).element.run();\n" + + " }\n" + + " static Box box(U u) {\n" + + " return new Box(u);\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " E element;\n" + + " Box(E element) {\n" + + " this.element = element;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Box bx = box(b.element);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236236); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0948() { + this.runConformTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " public void bar2(Box b1, Box b2) {\n" + + " Pair blist = pair(b1.element, b2.element);\n" + + " }\n" + + " static Pair pair(U u1, U u2) {\n" + + " return new Pair(u1,u2);\n" + + " }\n" + + "}\n" + + "class Pair {\n" + + " Pair(E e, F f){}\n" + + "}\n" + + "class Box {\n" + + " E element;\n" + + " Box(E element) {\n" + + " this.element = element;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 +public void test0949() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public Iterable m(T... ts) {\n" + + " return Arrays.asList(ts);\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " public void m2() {\n" + + " m3(m(3, 3, 3));\n" + + " m3(m());\n" + + " m3(m(new Object[]{}));\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " m3(m(3, 3, 3));\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " m3(m());\n" + + " ^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " m3(m(new Object[]{}));\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation +public void test0950() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public Iterable m(T[]... ts) {\n" + + " return Arrays.asList(ts[0]);\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " public void m2() {\n" + + " m3(m(new Integer[]{3, 3, 3}));\n" + + " m3(m());\n" + + " m3(m(new Object[][]{}));\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " m3(m(new Integer[]{3, 3, 3}));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " m3(m());\n" + + " ^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " m3(m(new Object[][]{}));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation +public void test0951() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public Iterable m(T[]... ts) {\n" + + " return Arrays.asList(ts[0]);\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public void m2() {\n" + + " m3(m(new Integer[]{3, 3, 3}));\n" + + " m3(m());\n" + + " m3(m(new Object[][]{}));\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation +public void test0952() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public Iterable m(T... ts) {\n" + + " return null;\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " public void m2() {\n" + + " m3(m(null));\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " m3(m(null));\n" + + " ^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterable is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " m3(m(null));\n" + + " ^^^^^^^\n" + + "The argument of type null should explicitly be cast to Object[] for the invocation of the varargs method m(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106325 +public void test0953() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.lang.ref.WeakReference;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void m(WeakReference ref) {\n" + + " List> list= Arrays.asList(ref);\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " List> list= Arrays.asList(ref);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of WeakReference is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130543 +public void test0954() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " class Member {}\n" + + " static class SMember {}\n" + + " void foo1() {\n" + + " X[] xs = new X[]{};//1\n" + + " for(X x : xs) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " void bar1() {\n" + + " Member[] members = new Member[]{};//2\n" + + " for(Member m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void bas1() {\n" + + " SMember[] members = new SMember[]{};//3\n" + + " for(SMember m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void baz1() {\n" + + " class Local{}\n" + + " Local[] locals = new Local[]{};//4\n" + + " for(Local l : locals) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + " void foo2() {\n" + + " X[] xs = new X[5];//5\n" + + " for(X x : xs) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " void bar2() {\n" + + " Member[] members = new Member[5];//6\n" + + " for(Member m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void bas2() {\n" + + " SMember[] members = new SMember[5];//7\n" + + " for(SMember m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void baz2() {\n" + + " class Local{}\n" + + " Local[] locals = new Local[5];//8\n" + + " for(Local l : locals) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + " void foo3() {\n" + + " X[] xs = new X[5];//9\n" + + " for(X x : xs) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " void bar3() {\n" + + " X.Member[] members = new X.Member[5];//10\n" + + " for(X.Member m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " static void baz3() {\n" + + " class Local{}\n" + + " Local[] locals = new Local[5];//11\n" + + " for(Local l : locals) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " Member[] members = new Member[]{};//2\n" + + " ^^\n" + + "Cannot create a generic array of X.Member\n" + + "----------\n" + + "2. ERROR in X.java (at line 26)\n" + + " Local[] locals = new Local[]{};//4\n" + + " ^^\n" + + "Cannot create a generic array of Local\n" + + "----------\n" + + "3. ERROR in X.java (at line 38)\n" + + " Member[] members = new Member[5];//6\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X.Member\n" + + "----------\n" + + "4. ERROR in X.java (at line 51)\n" + + " Local[] locals = new Local[5];//8\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of Local\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105049 +public void test0955() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.List;\n" + + "public class X {\n" + + " void method(Object o) {\n" + + " if (o instanceof List[]) { //incorrect: bug 104695\n" + + " List[] es= (List[]) o; //unchecked\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[]) { //incorrect: bug 104695\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[] es= (List[]) o; //unchecked\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130128 +public void test0956() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + "\n" + + " public void printNickname(Person person) {\n" + + " Person.Nickname nickname = person.getNickname();\n" + + " System.out.println(nickname);\n" + + " }\n" + + "\n" + + " static class Person {\n" + + " private Nickname nickname;\n" + + "\n" + + " public Nickname getNickname() {\n" + + " return nickname;\n" + + " }\n" + + "\n" + + " public void setNickname(Nickname nickname) {\n" + + " this.nickname = nickname;\n" + + " }\n" + + "\n" + + " class Nickname {\n" + + " private String name;\n" + + " private boolean insulting;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=132348 +public void test0957() { + this.runNegativeTest( + new String[] { + "AnyInterface.java", //================================ + "public interface AnyInterface {\n" + + " public void doSomething();\n" + + "}", + "UsingGenericsClass", + "public class UsingGenericsClass {\n" + + " public UsingGenericsClass(){\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in UsingGenericsClass (at line 1)\n" + + " public class UsingGenericsClass {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot specify any additional bound AnyInterface when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=131935 +public void test0958() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.lang.ref.ReferenceQueue;\n" + + "import java.lang.ref.SoftReference;\n" + + "import java.util.Hashtable;\n" + + "\n" + + "public class X {\n" + + " private static final Hashtable cache = new Hashtable();\n" + + "\n" + + " private static final ReferenceQueue trash = new ReferenceQueue();\n" + + "\n" + + " private static final class Soft extends SoftReference {\n" + + " int key;\n" + + "\n" + + " Soft() {\n" + + " super(null);\n" + + " }\n" + + " }\n" + + "\n" + + " final Thread clean = new Thread(\"BigTableModel cleaner\") {\n" + + " @Override\n" + + " public void run() {\n" + + " for (;;)\n" + + " try {\n" + + " cache.remove(((Soft) trash.remove()).key);\n" + + " } catch (final InterruptedException e) {\n" + + " return;\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 27)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133803 +public void test0959() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.lang.ref.*;\n" + + "\n" + + "class Soft extends SoftReference {\n" + + " Soft() { super(null); }\n" + + "}\n" + + "\n" + + "class Bug {\n" + + " void m(Reference remove) {\n" + + " Soft soft= (Soft) remove;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Soft soft= (Soft) remove;\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from Reference to Soft\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273 +public void test0960() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " > X newInstance() {\n" + + " return new X();\n" + + " }\n" + + "\n" + + " X[] bugDemo() {\n" + + " X x = newInstance();\n" + + " return new X[] { x };\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = newInstance();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " return new X[] { x };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X[] needs unchecked conversion to conform to X[]\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273 - variation +public void test0961() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " > B newInstance2(X xb) {\n" + + " return null;\n" + + " }\n" + + " void foo() {\n" + + " X x = new X();\n" + + " Comparable c = newInstance2(x);\n" + + " }\n" + + " Zork z;\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 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 should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " Comparable c = newInstance2(x);\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Comparable c = newInstance2(x);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation newInstance2(X) of the generic method newInstance2(X) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " Comparable c = newInstance2(x);\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 +public void test0962() { + runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public void bug() throws Exception {\n" + + " throw new Exception(\"Bug134645\") {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Bug134645\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " throw new Exception(\"Bug134645\") {\n" + + " ^^^^^^^^^\n" + + "The generic class new Exception(){} may not subclass java.lang.Throwable\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " throw new Exception(\"Bug134645\") {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 - variation +public void test0963() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public void bug() throws Exception {\n" + + " throw new Exception(\"Bug134645\") {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Bug134645\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 - variation +public void test0964() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public static void bug() throws Exception {\n" + + " throw new Exception(\"Bug134645\") {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Bug134645\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97494 +public void test0965() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " protected static final Class> theClass = (Class>) X.class;\n" + + " void foo(Class cx) {\n" + + " Class> cx1 = cx;\n" + + " Class> cx2 = (Class>) cx;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " protected static final Class> theClass = (Class>) X.class;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Class to Class>\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void foo(Class cx) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Class> cx1 = cx;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Class> cx2 = (Class>) cx;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115918 +public void test0966() { + this.runConformTest( + new String[] { + "Child.java", //================================ + "public class Child extends Parent implements Comparable {\n" + + " public int compareTo(Child o) { return 0; }\n" + + "}\n" + + "class Parent extends Base {}\n" + + "class Base {}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=81949 +public void test0967() { + this.runConformTest( + new String[] { + "CSS.java", //================================ + "interface Ac,A extends Ac> {}\n" + + "interface St,A extends Ac> {}\n" + + "class CSN extends CSS implements Ac, CSN> {}\n" + + "public class CSS implements St, CSN> {}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108045 +public void test0968() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X extends ArrayList implements I {\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends ArrayList implements I {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public class X extends ArrayList implements I {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " interface I extends Collection {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133071 +public void test0969() { + this.runConformTest( + new String[] { + "B.java", //================================ + "class B extends A {}\n" + + "class C extends B {}\n" + + "class A {}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=136946 +public void test0970() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public interface X { \n" + + " interface I1 extends X {\n" + + " interface I2 extends I1 {\n" + + " }\n" + + "\n" + + " interface I3 extends I1 {\n" + + " }\n" + + "\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " }\n" + + " }\n" + + "}\n" + + "class XSub implements X {\n" + + " I1 i1 = null;\n" + + " I1.I2 i2 = null;\n" + + " I1.I2 i1i2 = null;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " I1.I2 i1i2 = null;\n" + + " ^^^^^^^^\n" + + "The member type X.I1.I2 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.I1\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=136946 - variation +public void test0971() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public interface X { \n" + + " interface I1 extends X {\n" + + " interface I2 extends I1 {\n" + + " }\n" + + "\n" + + " interface I3 extends I1 {\n" + + " }\n" + + "\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " }\n" + + " }\n" + + "}\n" + + "class XSub implements X {\n" + + " I1 i1 = null;\n" + + " I1.I2 i2 = null;\n" + + " I1.I2 i1i2 = null;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " interface I1 extends X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " interface I2 extends I1 {\n" + + " ^^\n" + + "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " interface I3 extends I1 {\n" + + " ^^\n" + + "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " ^^^^^\n" + + "X.I1.I2 is a raw type. References to generic type X.I1.I2 should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " ^^^^^\n" + + "X.I1.I3 is a raw type. References to generic type X.I1.I3 should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 14)\n" + + " I1 i1 = null;\n" + + " ^^\n" + + "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " I1.I2 i2 = null;\n" + + " ^^^^^\n" + + "X.I1.I2 is a raw type. References to generic type X.I1.I2 should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " I1.I2 i1i2 = null;\n" + + " ^^^^^^^^\n" + + "The member type X.I1.I2 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.I1\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 +// simulate incremental compile +public void test0972() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + }, + "SUCCESS", + null, + false, + null); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 - variation +//pure source scenario +public void test0973() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 - variation +//simulate incremental compile +public void test0974() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.Inner in;\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122999 +public void test0975() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.ArrayList;\n" + + "\n" + + "public class X extends ArrayList {\n" + + " public static class Bean {}\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X extends ArrayList {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public class X extends ArrayList {\n" + + " ^^^^\n" + + "Bean cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139525 +public void test0976() { + this.runConformTest( + new String[] { + "S.java", // ================= + "import java.util.Collection;\n" + + "public class S {\n" + + " public static void cow(IDA s) {\n" + + " Collection ids = s.getIds(); // Error here\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + "ID.java", // ================= + "import java.util.Collection;\n" + + "public interface ID {\n" + + " Collection> getIds();\n" + + "}\n", // ================= + "IDA.java", // ================= + "import java.util.Collection;\n" + + "public interface IDA extends ID {\n" + + " enum Enum1 {\n" + + " ONE, TWO\n" + + " }\n" + + " Collection getIds();\n" + + "}\n", // ================= + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "S.java", // ================= + "import java.util.Collection;\n" + + "public class S {\n" + + " public static void cow(IDA s) {\n" + + " Collection ids = s.getIds(); // Error here\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS2\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS2", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139619 +public void test0977() { + this.runConformTest( + new String[] { + "MMTPProtocol.java", // ================= + "import java.io.InputStream;\n" + + "import java.util.HashSet;\n" + + "import bug.ProtocolManager;\n" + + "abstract class AbstractProtocol implements ProtocolManager {\n" + + " public AbstractProtocol(HashSet manager, String grp) {}\n" + + " AbstractProtocol(){} \n" + + " public void connect(ConnectType type) { }\n" + + "}\n" + + "public abstract class MMTPProtocol extends AbstractProtocol {\n" + + " public void connect(ConnectType type) {}\n" + + "}\n", // ================= + "bug/ProtocolManager.java", // ================= + "package bug;\n" + + "public interface ProtocolManager{\n" + + " public enum ConnectType {Client,Server}\n" + + " public void connect(ConnectType type) ;\n" + + " public boolean receive(R input) throws Exception;\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "MMTPProtocol.java", // ================= + "import java.io.InputStream;\n" + + "import java.util.HashSet;\n" + + "import bug.ProtocolManager;\n" + + "abstract class AbstractProtocol implements ProtocolManager {\n" + + " public AbstractProtocol(HashSet manager, String grp) {}\n" + + " AbstractProtocol(){} \n" + + " public void connect(ConnectType type) { }\n" + + "}\n" + + "public abstract class MMTPProtocol extends AbstractProtocol {\n" + + " public void connect(ConnectType type) {}\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139669 +public void test0978() { + this.runConformTest( + new String[] { + "B.java", // ================= + "public class B implements A {\n" + + " public void foo(A.C c) {}\n" + + "}", // ================= + "A.java", // ================= + "public interface A {\n" + + " void foo(A.C c);\n" + + " class C {}\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "A.java", // ================= + "public interface A {\n" + + " void foo(A.C c);\n" + + " class C {}\n" + + "}", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139669 +public void test0979() { + this.runConformTest( + new String[] { + "B.java", // ================= + "public class B extends A {\n" + + " @Override\n" + + " public void foo(A.C c) {}\n" + + "}", // ================= + "A.java", // ================= + "public class A {\n" + + " public void foo(A.C c) {}\n" + + " public static class C {}\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "A.java", // ================= + "public class A {\n" + + " public void foo(A.C c) {}\n" + + " public static class C {}\n" + + "}", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140772 +public void test0980() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.Collections;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public Set keySet() {\n" + + " return Collections. emptySet();\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140569 +//simulate incremental compile +public void test0981() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + "}\n", + "Worker.java", //================================ + "public class Worker {\n" + + " public static void method(Outer.Inner i) {}\n" + + "}\n", //================================ + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", //================================ + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140569 +//simulate incremental compile +public void test0982() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {\n" + + " public class Inner2 {}\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " class ExtendedInner2 extends Inner2 {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + "Worker.java", //================================ + "public class Worker {\n" + + " public static void method(Outer.Inner.Inner2 i) {}\n" + + "}\n", //================================ + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " class ExtendedInner2 extends Inner2 {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", //================================ + }, + "SUCCESS", + null, + false, + null); +} +public void test0983() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " List l1 = new ArrayList();\n" + + " List l2 = new ArrayList();\n" + + " l1.addAll(l2);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " l1.addAll(l2);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n"); +} +// generic inner class within a non generic one +public void test0984() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public class XX {}\n" + + "}", + "I.java", + "public interface I {\n" + + " X.XX foo();\n" + + "}", + "Y.java", + "public class Y extends X implements I {\n" + + " public XX foo() {\n" + + " return null;\n" + + " }\n" + + "}", + }, + // runtime results + "" /* expected output string */); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "Y.java", + "public class Y extends X implements I {\n" + + " public XX foo() {\n" + + " return null;\n" + + " }\n" + + "}", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141330 +public void test0985() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " public void testBreak() {\n" + + " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Class> is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List>> to List>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=91709 +public void test0986() { + this.runConformTest( + new String[] { + "T.java", // ================= + "public class T {\n" + + " public T() {\n" + + " S s = new S();\n" + + " s.setObj(\"S\");\n" + + " System.out.print(s.getObj());\n" + + " S i = new S();\n" + + " i.setObj(new Integer(100));\n" + + " System.out.print(i.getObj());\n" + + " S m = new S();\n" + + " m.setObj(new MyClass(\"[Terry]\"));\n" + + " System.out.print(m.getObj());\n" + + " S x = new S(new MyClass(\"[Corbet]\"));\n" + + " System.out.print(x.getObj());\n" + + " } // End of Constructor for T.\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new T();\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch (Exception ex) {\n" + + " ex.printStackTrace();\n" + + " }\n" + + " } // End of main().\n" + + "\n" + + " class MyClass {\n" + + " private String str;\n" + + " public MyClass(String str) {\n" + + " this.str = str;\n" + + " } // End of Constructor for MyClass.\n" + + " @Override\n" + + " public String toString() {\n" + + " return (\"MyClass = \" + str);\n" + + " } // End of toString().\n" + + " } // End of Embedded MyClass Class.\n" + + "} // End of T Class.\n", // ================= + "S.java", // ================= + "public class S<$T> extends B<$T> {\n" + + " public S() {\n" + + " super();\n" + + " } // End of Constructor for S.\n" + + " public S($T obj) {\n" + + " super(obj);\n" + + " } // End of Constructor for S.\n" + + "} // End of S Class.\n", // ================= + "B.java", // ================= + "public abstract class B<$T> {\n" + + " $T obj;\n" + + " public B() {\n" + + " ;\n" + + " } // End of Constructor for B.\n" + + " public B($T obj) {\n" + + " this.obj = obj;\n" + + " } // End ofg Constructor of B.\n" + + " public $T getObj() {\n" + + " return (obj);\n" + + " } // End of getObj().\n" + + " public void setObj($T obj) {\n" + + " this.obj = obj;\n" + + " } // End of setObj().\n" + + "} // End of B Class.", // ================= + + }, + "S100MyClass = [Terry]MyClass = [Corbet]SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 +public void test0987() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " public ISheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with EditPart.getViewer()\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public ISheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^\n" + + "The method getViewer() of type AbstractLinkView must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " public ISheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with EditPart.getViewer()\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " void bar(GLinkElementView g) {\n" + + " g.getViewer();\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class GLinkElementView extends AbstractLinkView {}\n" + + "\n" + + "abstract class AbstractLinkView extends AbstractConnectionEditPart implements ILinkViewElement {\n" + + " @Override\n" + + " public ISheetViewer getViewer() { return null; } \n" + + "}\n" + + "\n" + + "abstract class AbstractConnectionEditPart implements EditPart {}\n" + + "\n" + + "abstract class AbstractEditPart implements EditPart {\n" + + " public EditPartViewer getViewer() { return null; }\n" + + "}\n" + + "\n" + + "interface ILinkViewElement {\n" + + " public ISheetViewer getViewer();\n" + + "}\n" + + "\n" + + "interface ISheetViewer {}\n" + + "\n" + + "interface EditPart {\n" + + " EditPartViewer getViewer();\n" + + "}\n" + + "\n" + + "interface EditPartViewer {}\n", // ================= + }, + expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation +public void test0988() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " void bar(GLinkElementView g) {\n" + + " g.getViewer();\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class GLinkElementView extends AbstractLinkView {}\n" + + "\n" + + "abstract class AbstractLinkView extends AbstractConnectionEditPart implements ILinkViewElement, IModelChangeListener {\n" + + " @Override\n" + + " public SheetViewer getViewer() { return null; } \n" + + "}\n" + + "\n" + + "abstract class AbstractConnectionEditPart extends AbstractGraphicalEditPart implements ConnectionEditPart {}\n" + + "\n" + + "abstract class AbstractGraphicalEditPart extends AbstractEditPart implements GraphicalEditPart {}\n" + + "\n" + + "abstract class AbstractEditPart implements EditPart {\n" + + " public EditPartViewer getViewer() { return null; }\n" + + "}\n" + + "\n" + + "interface ILinkViewElement extends INodeViewElement {\n" + + " public ISheetViewer getViewer();\n" + + "}\n" + + "\n" + + "class SheetViewer implements ISheetViewer {}\n" + + "\n" + + "interface ISheetViewer {}\n" + + "\n" + + "interface EditPart {\n" + + " EditPartViewer getViewer();\n" + + "}\n" + + "\n" + + "interface ConnectionEditPart extends GraphicalEditPart {}\n" + + "interface GraphicalEditPart extends EditPart {}\n" + + "interface EditPartViewer {}\n" + + "interface IModelChangeListener {}\n" + + "\n" + + "interface INodeViewElement {\n" + + " public ISheetViewer getViewer();\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " public SheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^\n" + + "The return type is incompatible with AbstractEditPart.getViewer()\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 +public void test0989() { + this.runNegativeTest( + new String[] { + "Child.java",//=================== + "public class Child extends Parent {}\n" + + "abstract class Parent extends Grandparent implements IParent {}\n" + + "interface IParent extends IGrandparent {}\n" + + "abstract class Grandparent implements IGrandparent {}\n" + + "interface IGrandparent {}", // =================, // ================= + }, + "----------\n" + + "1. ERROR in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^\n" + + "The interface IGrandparent cannot be implemented more than once with different arguments: IGrandparent and IGrandparent\n" + + "----------\n" + + "2. WARNING in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^^\n" + + "IParent is a raw type. References to generic type IParent should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0990() { + this.runNegativeTest( + new String[] { + "Child.java",//=================== + "public class Child extends Parent {}\n" + + "abstract class Parent extends Grandparent implements IParent {}\n" + + "interface IParent extends IGrandparent {}\n" + + "abstract class Grandparent implements IGrandparent {}\n" + + "interface IGrandparent {}", // =================, // ================= + }, + "----------\n" + + "1. ERROR in Child.java (at line 1)\n" + + " public class Child extends Parent {}\n" + + " ^^^^^\n" + + "The hierarchy of the type Child is inconsistent\n" + + "----------\n" + + "2. ERROR in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^^\n" + + "The type Parent cannot extend or implement IParent. A supertype may not specify any wildcard\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0991() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X extends SX implements IX {}\n" + + "class SX extends TX implements IX {}\n" + + "class TX implements IX {}\n" + + "interface IX {}\n", // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends SX implements IX {}\n" + + " ^\n" + + "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " class SX extends TX implements IX {}\n" + + " ^^\n" + + "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0992() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.*;\n" + + "public abstract class X implements Collection, I {\n" + + " \n" + + " void foo() {\n" + + " this.add(new Object());\n" + + " this.add(null);\n" + + " }\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n", // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public abstract class X implements Collection, I {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public abstract class X implements Collection, I {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " this.add(new Object());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " this.add(null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 +public void test0993() { + runConformTest( + true, + new String[] { + "X.java",//=================== + "public class X {\n" + + " public class Inner {\n" + + " Inner() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new ATest();\n" + + " }\n" + + "}\n" + + "\n" + + "class ATest {\n" + + " public ATest() {\n" + + " T instance = makeInstance();\n" + + " X.Inner peq = instance.new Inner(); //**\n" + + " }\n" + + "\n" + + " private T makeInstance() {\n" + + " return (T) new X();\n" + + " }\n" + + "}", // ================= + }, + null, + "SUCCESS", + null, + JavacTestOptions.JavacHasABug.JavacBug6569404); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 - variation +public void test0994() { + this.runConformTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " public class Inner {\n" + + " Inner() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " void foo(boolean b, X1 x1, X2 x2) {\n" + + " (b ? x1 : x2).new Inner();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(true, new X1(), new X2());\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 extends X implements Comparable {\n" + + " public int compareTo(X1 other) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class X2 extends X implements Comparable {\n" + + " public int compareTo(X2 other) {\n" + + " return 0;\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142964 +public void _test0995() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " public class Inner {\n" + + " }\n" + + " void foo(boolean b, X1 x1, X2 x2) {\n" + + " Comparable cx1 = b ? x1 : x2;\n" + + " Comparable cx2 = b ? x1 : x2;\n" + + " String s = b ? x1 : x2;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class X1 extends X implements Comparable {}\n" + + "abstract class X2 extends X implements Comparable {}", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143793 +public void test0996() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private T aObject = null;\n" + + " public static List castList(final List pList, final Class pClass) {\n" + + " final List result = new ArrayList();\n" + + " for (Object o:pList) {\n" + + " if (pClass.isInstance(o)) {\n" + + " result.add(pClass.cast(o));\n" + + " }\n" + + " }\n" + + " return result;\n" + + " }\n" + + "\n" + + " public static void main(final String[] pArgs) {\n" + + " final List l1 = new ArrayList();\n" + + " l1.add(new X());\n" + + " l1.add(new X());\n" + + " final List> l2 = castList(l1, List.class);\n" + + " \n" + + " List l3 = l2;\n" + + " List> l4 = null;\n" + + " l3 = l4;\n" + + " }\n" + + "\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private T aObject = null;\n" + + " ^^^^^^^\n" + + "The field X.aObject is never read locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " final List> l2 = castList(l1, List.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "3. WARNING in X.java (at line 22)\n" + + " List l3 = l2;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 22)\n" + + " List l3 = l2;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 24)\n" + + " l3 = l4;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 - variation +public void test0997() { + runConformTest( + true, + new String[] { + "X.java",//=================== + "public class X implements Outer {\n" + + " public static void main(String[] args) {\n" + + " new ATest();\n" + + " }\n" + + "}\n" + + "interface Outer {\n" + + " public class Inner {\n" + + " Inner() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class ATest {\n" + + " public ATest() {\n" + + " Outer.Inner peq = new T.Inner(); //**\n" + + " }\n" + + "\n" + + " private T makeInstance() {\n" + + " return (T) new X();\n" + + " }\n" + + "}", // ================= + }, + null, + "SUCCESS", + null, + JavacTestOptions.JavacHasABug.JavacBug6569404); +} +//regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=144261 +public void test0998() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " static abstract class Generic {\n" + + " static class Inner {\n" + + " static class InnerInner { }\n" + + " InnerInner createTableModel() {\n" + + " return new InnerInner();\n" + + " }\n" + + " }\n" + + " }\n" + + " static class SubGeneric extends Generic {\n" + + " static class SubInner extends Inner {\n" + + " InnerInner createTableModel() {\n" + + " return super.createTableModel(); \n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 +public void test0999() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " return null;\n" + + " }\n" + + " void foo1() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " }\n" + + " void foo2() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " }\n" + + " void foo3() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator...) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^\n" + + "The method chain(Iterator...) in the type X is not applicable for the arguments (Iterator, Iterator)\n" + + "----------\n" + + "4. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterator is created for a varargs parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 +public void test1000() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " return null;\n" + + " }\n" + + " void foo1() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " }\n" + + " void foo2() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " }\n" + + " void foo3() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator...) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterator> is created for a varargs parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator> to Iterator\n" + + "----------\n" + + "5. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Iterator is created for a varargs parameter\n" + + "----------\n" + + "6. ERROR in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator to Iterator\n" + + "----------\n"); +} +public void test1001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Box {}\n" + + " static class ABox {}\n" + + " static class A {}\n" + + " \n" + + " void foo(ABox a1, ABox a2) {\n" + + " a1 = a2; \n" + + " }\n" + + "}", // ================= + }, + ""); +} +public void test1002() { + this.runNegativeTest( + new String[] { + "Base.java", + "class Base {\n" + + "}\n" + + "class Foo>> {\n" + + " U u;\n" + + " V v;\n" + + "}\n" + + "class Bar>> {\n" + + " E e;\n" + + " F f;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Base.java (at line 3)\n" + + " class Foo>> {\n" + + " ^^^\n" + + "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter >> of the type Bar\n" + + "----------\n" + + "2. ERROR in Base.java (at line 7)\n" + + " class Bar>> {\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter >> of the type Foo\n" + + "----------\n"); +} +public void test1003() { + this.runConformTest( + new String[] { + "B.java", + "class B {\n" + + "}\n" + + "class S, TT extends T> {\n" + + " BB b;\n" + + " TT t;\n" + + "}\n" + + "class T, TT extends T> {\n" + + " BB b;\n" + + " SS t;\n" + + "}\n", // ================= + }, + ""); +} +public void test1004() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " B getOtherValue() {\n" + + " return null;\n" + + " }\n" + + " A getValue() {\n" + + " return getOtherValue();\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145420 +public void test1005() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "\n" + + " private static final Object NULL_REF = new Object();\n" + + " private Object data;\n" + + "\n" + + " private static RT unwrap(Object obj) {\n" + + " return (RT)(obj == NULL_REF ? null : obj);\n" + + " }\n" + + "\n" + + " public T1 getAsT1() {\n" + + " return unwrap(data);\n" + + " }\n" + + "\n" + + " public T2 getAsT2() {\n" + + " return unwrap(data);\n" + + " }\n" + + "}", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=145420 - variant +public void test1005b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static final Object NULL_REF = new Object();\n" + + " private Object data;\n" + + "\n" + + " private static RT unwrap(Object obj) {\n" + + " return (RT)(obj == NULL_REF ? null : obj);\n" + + " }\n" + + "\n" + + " public T1 getAsT1() {\n" + + " return unwrap(data);\n" + + " }\n" + + "\n" + + " public T2 getAsT2() {\n" + + " return unwrap(data);\n" + + " }\n" + + " Zork z;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " return (RT)(obj == NULL_REF ? null : obj);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to RT\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1006() { + this.runConformTest( + new String[] { + "X.java", + "class Reference {\n" + + " T target;\n" + + " Reference(T target) {\n" + + " this.target = target;\n" + + " }\n" + + " T deref() {\n" + + " return this.target;\n" + + " }\n" + + " static Reference create(U u) {\n" + + " return new Reference(u);\n" + + " }\n" + + "}\n" + + "class BaseObject {}\n" + + "class Person extends BaseObject {}\n" + + "class Building extends BaseObject {}\n" + + "\n" + + "public class X {\n" + + " void foo(Building b, Person p) {\n" + + " Reference bRef = Reference.create(b);\n" + + " Reference pRef = Reference.create(p);\n" + + "\n" + + " final Building building = bRef.deref();\n" + + " final Person person = pRef.deref();\n" + + " }\n" + + "}", // ================= + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147381 +public void test1007() { + this.runNegativeTest( + new String[] { + "GenericsProblem.java", + "public class GenericsProblem {\n" + + " public void test(T val) {\n" + + " GenericsProblem gp = new GenericsProblem();\n" + + " Class cl2 = gp.getClass();\n" + + " Class cl = val.getClass();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in GenericsProblem.java (at line 5)\n" + + " Class cl = val.getClass();\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 +public void test1008() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l, C c) {\n" + + " X x = bar(l, c);\n" + + " }\n" + + " T bar(L l, C c) { \n" + + " return null;\n" + + " } \n" + + "}\n" + + "class C {}\n" + + "class L {}\n" + + "\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\r\n" + + " void foo(L l, C c) {\r\n" + + " ^\n" + + "L is a raw type. References to generic type L should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\r\n" + + " X x = bar(l, c);\r\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(L, C) of the generic method bar(L, C) of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\r\n" + + " X x = bar(l, c);\r\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\r\n" + + " X x = bar(l, c);\r\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug148061); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1009() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + "\n" + + " void foo(Map map) {\n" + + " bar(map);\n" + + " }\n" + + " void bar(Map> map) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(Map map) {\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " bar(map);\n" + + " ^^^\n" + + "The method bar(Map>) in the type X is not applicable for the arguments (Map)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1010() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + "\n" + + " void foo(Map map) {\n" + + " bar(map);\n" + + " }\n" + + " void bar(Map> map) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(Map map) {\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " bar(map);\n" + + " ^^^\n" + + "The method bar(Map>) in the type X is not applicable for the arguments (Map)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1011() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(HashMap map, String s, Map map2) {\n" + + " bar(map, s, map2); //1\n" + + " bar(map2, s, map2); //2\n" + + " bar2(map, s, map2); //3\n" + + " bar3(map, s, map2); //4\n" + + " }\n" + + " void bar(Map map, U u, Map map2) {}\n" + + " void bar2(Map map, String s, Map map2) {}\n" + + " void bar3(Map map, U s, Map map2) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo(HashMap map, String s, Map map2) {\n" + + " ^^^^^^^\n" + + "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " bar(map, s, map2); //1\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(Map, Object, Map) of the generic method bar(Map, U, Map) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " bar(map, s, map2); //1\n" + + " ^^^\n" + + "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " bar2(map, s, map2); //3\n" + + " ^^^\n" + + "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " bar3(map, s, map2); //4\n" + + " ^^^\n" + + "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1012() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l, C c) {\n" + + " X x = bar1(l, c);\n" + + " L lx = bar2(l, c);\n" + + " C cx = bar3(l, c);\n" + + " }\n" + + " T bar1(L l, C c) {\n" + + " return null;\n" + + " }\n" + + " L bar2(L l, C c) {\n" + + " return null;\n" + + " }\n" + + " C bar3(L l, C c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class C {}\n" + + "class L {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\r\n" + + " void foo(L l, C c) {\r\n" + + " ^\n" + + "L is a raw type. References to generic type L should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\r\n" + + " X x = bar1(l, c);\r\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar1(L, C) of the generic method bar1(L, C) of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\r\n" + + " X x = bar1(l, c);\r\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\r\n" + + " X x = bar1(l, c);\r\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "5. WARNING in X.java (at line 4)\r\n" + + " L lx = bar2(l, c);\r\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar2(L, C) of the generic method bar2(L, C) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 4)\r\n" + + " L lx = bar2(l, c);\r\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "7. WARNING in X.java (at line 4)\r\n" + + " L lx = bar2(l, c);\r\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "8. WARNING in X.java (at line 5)\r\n" + + " C cx = bar3(l, c);\r\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar3(L, C) of the generic method bar3(L, C) of type X\n" + + "----------\n" + + "9. WARNING in X.java (at line 5)\r\n" + + " C cx = bar3(l, c);\r\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type C needs unchecked conversion to conform to C\n" + + "----------\n" + + "10. WARNING in X.java (at line 5)\r\n" + + " C cx = bar3(l, c);\r\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug148061); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1013() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List ls = new ArrayList();\n" + + " ls.add(\"foo\");\n" + + " List lx = new ArrayList();\n" + + " lx.add(new X());\n" + + " new X().foo(ls, lx);\n" + + " }\n" + + " void done() {\n" + + " System.out.println(\"[done]\");\n" + + " }\n" + + " void foo(List l1, List l2) {\n" + + " X x = bar1(l1, l2);\n" + + " x.done();\n" + + " List lx = bar2(l1, l2);\n" + + " lx.get(0).done();\n" + + " }\n" + + " T bar1(List l1, List l2) {\n" + + " return l1.get(0);\n" + + " }\n" + + " List bar2(List l1, List l2) {\n" + + " return l1;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\r\n" + + " void foo(List l1, List l2) {\r\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\r\n" + + " X x = bar1(l1, l2);\r\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar1(List, List) of the generic method bar1(List, List) of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\r\n" + + " X x = bar1(l1, l2);\r\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\r\n" + + " X x = bar1(l1, l2);\r\n" + + " ^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\r\n" + + " List lx = bar2(l1, l2);\r\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar2(List, List) of the generic method bar2(List, List) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\r\n" + + " List lx = bar2(l1, l2);\r\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\r\n" + + " List lx = bar2(l1, l2);\r\n" + + " ^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug148061); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1014() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo1(List l, List ls) {\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " String s = bar(l, ls).entrySet();\n" + + " }\n" + + " Map bar(List lu, List lv) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo1(List l, List ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set needs unchecked conversion to conform to Set>\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " String s = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " String s = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Set to String\n" + + "----------\n" + + "7. WARNING in X.java (at line 6)\n" + + " String s = bar(l, ls).entrySet();\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1015() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo1(List l, List ls) {\n" + + " List ls1 = bar(l, ls);\n" + + " String s = bar(l, ls);\n" + + " }\n" + + " List bar(List lu, List lv) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo1(List l, List ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(l, ls);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " String s = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " String s = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to String\n" + + "----------\n" + + "7. WARNING in X.java (at line 5)\n" + + " String s = bar(l, ls);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1016() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo1() {\n" + + " List ls1 = bar(null);\n" + + " List ls2 = bar(null);\n" + + " String s = bar(null);\n" + + " }\n" + + " List bar(List lu) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(null);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = bar(null);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1017() { + this.runNegativeTest( + new String[] { + "SortedList.java", + "import java.util.*;\n" + + "\n" + + "public class SortedList extends LinkedList\n" + + "{\n" + + " public boolean add(E e){\n" + + " int index = Collections.binarySearch(this,e);\n" + + " if (index<0)\n" + + " super.add(-index-1,e);\n" + + " return true;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in SortedList.java (at line 3)\n" + + " public class SortedList extends LinkedList\n" + + " ^^^^^^^^^^\n" + + "The serializable class SortedList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in SortedList.java (at line 3)\n" + + " public class SortedList extends LinkedList\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. WARNING in SortedList.java (at line 5)\n" + + " public boolean add(E e){\n" + + " ^^^^^^^^\n" + + "The method add(E) of type SortedList should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "4. ERROR in SortedList.java (at line 6)\n" + + " int index = Collections.binarySearch(this,e);\n" + + " ^^^^^^^^^^^^\n" + + "The method binarySearch(List>, T) in the type Collections is not applicable for the arguments (SortedList, E)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1018() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo(U u) {\n" + + " bar(u, new Exception());\n" + + " }\n" + + " T bar(U u, T t) { return null; }\n" + + "}", // ================= + }, + ""); +} +public void test1018a() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class A {}\n" + + "\n" + + "class B extends A> {}\n" + + "\n" + + "public class X extends B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test1019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " double[] d1 = new double[] { 1.0, 2.0, 3.0, 4.0 };\n" + + " System.out.println(deepToString(d1));\n" + + "\n" + + " Double[] d2 = new Double[] { 1.0, 2.0, 3.0, 4.0 };\n" + + " System.out.println(deepToString(d2));\n" + + " \n" + + " }\n" + + "\n" + + " public static String deepToString(T[] array) {\n" + + " StringBuffer s = new StringBuffer();\n" + + " for (T t : array) {\n" + + " s.append(t.toString());\n" + + " s.append(\",\");\n" + + " }\n" + + " if (s.length() > 0) {\n" + + " s.setLength(s.length() - 1); // removes last \",\"\n" + + " }\n" + + " return s.toString();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.println(deepToString(d1));\n" + + " ^^^^^^^^^^^^\n" + + "The method deepToString(T[]) in the type X is not applicable for the arguments (double[])\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149573 +public void test1020() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List l1, List l2) {\n" + + " l1.add(l2.get(0));\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " l1.add(l2.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? extends Exception) in the type List is not applicable for the arguments (capture#2-of ? extends Exception)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149376 +public void test1021() { + this.runConformTest( + new String[] { + "p/SomeClass.java", + "package p;\n" + + "import static p.SomeClass.SomeEnum.*;\n" + + "public abstract class SomeClass extends Object {\n" + + " public enum SomeEnum {\n" + + " A;\n" + + " };\n" + + "}\n", + }, + "" + ); +} +public void test1021b() { // should this case be allowed? + this.runNegativeTest( + new String[] { + "p/SomeClass2.java", + "package p;\n" + + "import static p.SomeClass2.M1.*;\n" + + "public abstract class SomeClass2 extends M {\n" + + " public static class M1 extends M2 {}\n" + + " public static class M2 extends M3 {}\n" + + " public static class M3 {\n" + + " public static class M {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\SomeClass2.java (at line 3)\n" + + " public abstract class SomeClass2 extends M {\n" + + " ^\n" + + "Cycle detected: the type SomeClass2 cannot extend/implement itself or one of its own member types\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=151410 (duplicate of 149376) +public void test1021c() { + runConformTest( + new String[] { + "ccs/jdtbug/filters/NameRF.java", + "package ccs.jdtbug.filters;\n" + + "import static ccs.jdtbug.ResultFilter.Action.*;\n" + + "import ccs.jdtbug.*;\n" + + "public class NameRF implements ResultFilter {\n" + + " public NameRF() {}\n" + + " public Action getAction(String in, int ntotal, int naccept) {\n" + + " return YES;\n" + + " }\n" + + "} // end class\n", + "ccs/jdtbug/ResultFilter.java", + "package ccs.jdtbug;\n" + + "import java.io.*;\n" + + "public interface ResultFilter {\n" + + " public enum Action {\n" + + " YES, NO, CANCEL\n" + + " }\n" + + " public Action getAction(T in, int ntotal, int naccept) throws IOException;\n" + + "} // end interface\n" + } + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150294 +public void test1022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String testString = \"test string\";\n" + + "\n" + + " testWithNonGeneric(testString);\n" + + " testWithGeneric(testString);\n" + + " }\n" + + "\n" + + " private static void testWithNonGeneric(String input) {\n" + + " Class clazz = input.getClass();\n" + + "\n" + + " System.out.println(clazz.getName());\n" + + " }\n" + + "\n" + + " private static void testWithGeneric(T input) {\n" + + " Class clazz = input.getClass();\n" + + "\n" + + " System.out.println(clazz.getName());\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " Class clazz = input.getClass();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150362 +public void test1023() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Properties;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Properties props = new Properties();\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Map.Entry to Map.Entry\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Properties to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151275 +public void test1024() { + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer castInteger = genericCast(1); // works\n" + + " int castInt1 = genericCast(1); // fails in javac but works in Eclipse\n" + + " int castInt2 = X. genericCast(1); // workaround for javac\n" + + " int castInt3 = (Integer) genericCast(1); // workaround for javac\n" + + " }\n" + + " private static T genericCast(Object input) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T castValue = (T) input;\n" + + " return castValue;\n" + + " }\n" + + "}", // =================, + }, + null, + "", + null, + JavacTestOptions.EclipseJustification.EclipseBug151275); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 +public void test1025() { + this.runConformTest( + new String[] { + "GenericBaseClass.java", + "public class GenericBaseClass {\n" + + " public GenericBaseClass() {\n" + + " if (!(this instanceof ASubGenericClass)) {\n" + + " System.out.println(\"I\'m not ASubClass\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class ASubGenericClass extends GenericBaseClass {\n" + + " public ASubGenericClass() {\n" + + " // This compiles with both\n" + + " GenericBaseClass hey = this;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 +public void test1026() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.LinkedHashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public class A {};\n" + + " public class B extends A {};\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X g = new X();\n" + + " Set set = g.newSet(g.new B());\n" + + " }\n" + + " public Set newSet(V v) {\n" + + " Set set = new LinkedHashSet();\n" + + " set.add(v);\n" + + " return set;\n" + + " }\n" + + "}\n" // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 - variation +public void test1027() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.LinkedHashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public class A {};\n" + + " public class B extends A {};\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X g = new X();\n" + + " Set set = g.newSet(g.new B());\n" + + " }\n" + + " public Set newSet(V... objects) {\n" + + " Set set = new LinkedHashSet();\n" + + " for (T t : objects) {\n" + + " set.add(t);\n" + + " }\n" + + " return set;\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 - variation +public void test1028() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.LinkedHashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X g = new X();\n" + + " Set set = g.newSet(new B());\n" + + " }\n" + + " public Set newSet(V v) {\n" + + " Set set = new LinkedHashSet();\n" + + " set.add(v);\n" + + " return set;\n" + + " }\n" + + "}\n" + + "\n" + + "class A {};\n" + + "class B extends A {};\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156016 +public void test1029() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static List makeNumberList(T a, T b) {\n" + + " return Arrays.asList(a, b);\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " List name = makeNumberList(5, 5D);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return Arrays.asList(a, b);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of T is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " List name = makeNumberList(5, 5D);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n"); +} +public void test1030() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public class PointList extends Object implements Iterable {\n" + + " private List theList = new ArrayList();\n" + + "\n" + + " public Iterator iterator() {\n" + + " return theList.iterator();\n" + + " }\n" + + " }\n" + + "\n" + + " private PointList waypoints = new PointList();\n" + + "\n" + + " public void printWaypoints() {\n" + + " for (Waypoint waypoint : waypoints) { // ***** This line does not compile *****\n" + + " System.out.println(waypoint.toString());\n" + + " }\n" + + " for (Iterator it = waypoints.iterator(); it.hasNext();) {\n" + + " Waypoint waypoint = it.next();\n" + + " System.out.println(waypoint.toString());\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Waypoint {}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156765 +public void test1031() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "interface IValue extends Serializable {\n" + + " public > T getComparableValue();\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " public static void foo0() {\n" + + " IValue val1 = null;\n" + + " Object o = val1.getComparableValue(); // 0\n" + + " }\n" + + " public static void foo1() {\n" + + " IValue val1 = null;\n" + + " String s = val1.getComparableValue(); // 1\n" + + " }\n" + + " public static int foo2() {\n" + + " IValue val1 = null;\n" + + " IValue val2 = null;\n" + + " return val1.getComparableValue().compareTo(val2.getComparableValue()); // 2\n" + + " } \n" + + " public static int foo3() {\n" + + " Comparable c = \"aaa\"; // 3\n" + + " Comparable o = new Object(); // 4\n" + + " return 0;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " Comparable o = new Object(); // 4\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Comparable\n" + + "----------\n"); +} +public void test1032() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " T test(String name) {\n" + + "\n" + + " try {\n" + + " InputStream in = new FileInputStream(name);\n" + + " return (T) new ObjectInputStream(in).readObject();\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " U text() {\n" + + " return test(\"data\");\n" + + " }\n" + + "}", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test1032a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " T test(String name) {\n" + + "\n" + + " try {\n" + + " InputStream in = new FileInputStream(name);\n" + + " return (T) new ObjectInputStream(in).readObject();\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " U text() {\n" + + " return test(\"data\");\n" + + " }\n" + + " Zork z;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " return (T) new ObjectInputStream(in).readObject();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.bar1(Integer.TYPE);\n" + + " x.bar2(Integer.TYPE);\n" + + " x.bar2(\"\");\n" + + " } \n" + + " void bar1(Class... classes) {}\n" + + " void bar2(Class... classes) {}\n" + + " \n" + + "}", // ================= + + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " x.bar1(Integer.TYPE);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar1(Class...) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " x.bar2(\"\");\n" + + " ^^^^\n" + + "The method bar2(Class...) in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " void bar2(Class... classes) {}\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158519 +public void test1034() { + this.runNegativeTest( + new String[] { + "ChainedClosure.java", + "interface Closure {\n" + + " public void execute(I input);\n" + + "}\n" + + "\n" + + "class ChainedClosure implements Closure {\n" + + " private final Closure[] iClosures;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static Closure getInstance(Closure closure1, Closure closure2) {\n" + + " if (closure1 == null || closure2 == null) {\n" + + " throw new IllegalArgumentException(\"Closures must not be null\");\n" + + " }\n" + + " Closure[] closures = new Closure[] { closure1, closure2 };\n" + + " return new ChainedClosure(closures);\n" + + " }\n" + + " public ChainedClosure(Closure[] closures) {\n" + + " super();\n" + + " iClosures = closures;\n" + + " }\n" + + " public void execute(I input) {\n" + + " for (int i = 0; i < iClosures.length; i++) {\n" + + " iClosures[i].execute(input);\n" + + " }\n" + + " }\n" + + "}\n" + + "class ClosureUtils {\n" + + " public static Closure chainedClosure(Closure closure1, Closure closure2) {\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " }\n" + + " public static Closure chainedClosure2(Closure closure1, Closure closure2) {\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " }\n" + + " public static Closure chainedClosure3(Closure closure1, Closure closure2) {\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " }\n" + + "}", // ================= + + }, + "----------\n" + + "1. ERROR in ChainedClosure.java (at line 33)\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " ^^^^^^^^^^^\n" + + "The method getInstance(Closure, Closure) in the type ChainedClosure is not applicable for the arguments (Closure, Closure)\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236370); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158531 +public void test1035() { + this.runNegativeTest( + new String[] { + "ComparableComparator.java", + "import java.util.Comparator;\n" + + "\n" + + "@SuppressWarnings(\"unchecked\")\n" + + "class ComparableComparator> implements Comparator {\n" + + "\n" + + " static ComparableComparator instance = new ComparableComparator();\n" + + "\n" + + "public static > ComparableComparator getInstance() {\n" + + " return instance;\n" + + "}\n" + + "static > Comparator bar() {\n" + + " return null;\n" + + "}\n" + + "static Comparator baz() {\n" + + " return null;\n" + + "}\n" + + "public int compare(T obj1, T obj2) {\n" + + " return obj1.compareTo(obj2);\n" + + "}\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"unchecked\")\n" + + "class ComparatorUtils {\n" + + "\n" + + " static Comparator BAR = ComparableComparator.bar();//0\n" + + " static Comparator NATURAL_COMPARATOR = ComparableComparator.getInstance();//1\n" + + " static Object BAR2 = ComparableComparator.bar();//1a\n" + + " static Comparator BAR3 = ComparableComparator.baz();//1b\n" + + "\n" + + "public static > Comparator naturalComparator() {\n" + + " return NATURAL_COMPARATOR;\n" + + "}\n" + + "\n" + + "public static Comparator nullLowComparator(Comparator comparator) {\n" + + " if (comparator == null)\n" + + " comparator = (Comparator) naturalComparator();//2\n" + + " return new NullComparator(comparator, false);\n" + + "}\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"unchecked\")\n" + + "class NullComparator implements Comparator {\n" + + "\n" + + " Comparator nonNullComparator;\n" + + " boolean nullsAreHigh;\n" + + "\n" + + "public NullComparator() {\n" + + " this((Comparator) ComparableComparator.getInstance(), true);//3\n" + + "}\n" + + "\n" + + "public NullComparator(Comparator nonNullComparator) {\n" + + " this(nonNullComparator, true);\n" + + "}\n" + + "\n" + + "public NullComparator(boolean nullsAreHigh) {\n" + + " this((Comparator) ComparableComparator.getInstance(), nullsAreHigh);//4\n" + + "}\n" + + "\n" + + "public NullComparator(Comparator nonNullComparator, boolean nullsAreHigh) {\n" + + " this.nonNullComparator = nonNullComparator;\n" + + " this.nullsAreHigh = nullsAreHigh;\n" + + " if (nonNullComparator == null) {\n" + + " throw new NullPointerException(\"null nonNullComparator\");\n" + + " }\n" + + "}\n" + + "\n" + + "public int compare(V obj1, V obj2) {\n" + + " return 0;\n" + + "}\n" + + "}", // ================= + + }, + "----------\n" + + "1. WARNING in ComparableComparator.java (at line 14)\n" + + " static Comparator baz() {\n" + + " ^^^^^^\n" + + "The type parameter M should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in ComparableComparator.java (at line 27)\n" + + " static Object BAR2 = ComparableComparator.bar();//1a\n" + + " ^^^\n" + + "Bound mismatch: The generic method bar() of type ComparableComparator is not applicable for the arguments (). The inferred type Comparable> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 +public void test1036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " List list;\n" + + " Map.Entry,List> entry;\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " \n" + + " p.q.Map.Entry entry3;\n" + + " \n" + + " String.Y y; // wrong\n" + + " X.Y y1; // wrong\n" + + " X.Y y2;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\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 3)\n" + + " List list;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " List list;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "10. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "11. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^^^\n" + + "jaavaa cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "13. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "14. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "15. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "16. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "17. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "18. ERROR in X.java (at line 7)\n" + + " p.q.Map.Entry entry3;\n" + + " ^\n" + + "p cannot be resolved to a type\n" + + "----------\n" + + "19. ERROR in X.java (at line 9)\n" + + " String.Y y; // wrong\n" + + " ^^^^^^\n" + + "The type String is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "20. ERROR in X.java (at line 10)\n" + + " X.Y y1; // wrong\n" + + " ^^^^^^^^^^^\n" + + "X.Y cannot be resolved to a type\n" + + "----------\n" + + "21. ERROR in X.java (at line 10)\n" + + " X.Y y1; // wrong\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "22. ERROR in X.java (at line 10)\n" + + " X.Y y1; // wrong\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "23. ERROR in X.java (at line 11)\n" + + " X.Y y2;\n" + + " ^^^^^^^^^^^\n" + + "X.Y cannot be resolved to a type\n" + + "----------\n" + + "24. ERROR in X.java (at line 11)\n" + + " X.Y y2;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 - variation +public void test1037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " List list;\n" + + " Map.Entry entry;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\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 3)\n" + + " List list;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " List list;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Map.Entry entry;\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " Map.Entry entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation +public void test1038() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int CONST = A.foo();\n" + + "}\n" + + "\n" + + "class A {\n" + + " static int foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class B implements I {\n" + + " static int LOCAL_STATIC;\n" + + " int local_field;\n" + + " B(int param) {\n" + + " int i = CONST; // keep for possible \n" + + " int j = param; // may optimize out\n" + + " int k = LOCAL_STATIC; // may optimize out\n" + + " int l = local_field; // may optimize out\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B(12);\n" + + " }\n" + + "}", // ================= + }, + "SUCCESS", + null, + false, + null, + options, + null); + // check the reference to I.CONST still got generated (for invocation side-effect) + String expectedOutput = + " // Method descriptor #10 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " B(int param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 getstatic B.CONST : int [15]\n" + + " 7 pop\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 4, line: 15]\n" + + " [pc: 8, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: this index: 0 type: B\n" + + " [pc: 0, pc: 9] local: param index: 1 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation +public void test1039() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Value CONST = A.foo(\"[I.CONST]\");\n" + + "}\n" + + "class Value {\n" + + " static String NAME = \"\";\n" + + " V v;\n" + + " Value(V v) {\n" + + " this.v = v;\n" + + " }\n" + + "}\n" + + "class A {\n" + + " static Value foo(String str) {\n" + + " System.out.print(str);\n" + + " return new Value(\"str\");\n" + + " }\n" + + "}\n" + + "class B implements I {\n" + + " static Value LOCAL_STATIC = A.foo(\"[B.LOCAL_STATIC]\");\n" + + " Value local_field = A.foo(\"[B.local_field]\");\n" + + " B(Value param) {\n" + + " String i = CONST.NAME; // keep for possible \n" + + " String j = param.NAME; // may optimize out\n" + + " String k = LOCAL_STATIC.NAME; // may optimize out\n" + + " String l = local_field.NAME; // may optimize out\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B(new Value(\"[PARAM]\"));\n" + + " }\n" + + "}", // ================= + }, + "[B.LOCAL_STATIC][B.local_field][I.CONST]", + null, + false, + null, + options, + null); + // check the reference to I.CONST still got generated (for invocation side-effect) + String expectedOutput = + " // Method descriptor #28 (LValue;)V\n" + + " // Signature: (LValue;)V\n" + + " // Stack: 2, Locals: 2\n" + + " B(Value param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [30]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [32]\n" + + " 7 invokestatic A.foo(java.lang.String) : Value [17]\n" + + " 10 putfield B.local_field : Value [34]\n" + + " 13 getstatic B.CONST : Value [36]\n" + + " 16 pop\n" + + " 17 getstatic Value.NAME : java.lang.String [39]\n" + + " 20 pop\n" + + " 21 getstatic Value.NAME : java.lang.String [39]\n" + + " 24 pop\n" + + " 25 getstatic Value.NAME : java.lang.String [39]\n" + + " 28 pop\n" + + " 29 getstatic Value.NAME : java.lang.String [39]\n" + + " 32 pop\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 20]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 13, line: 21]\n" + + " [pc: 21, line: 22]\n" + + " [pc: 25, line: 23]\n" + + " [pc: 29, line: 24]\n" + + " [pc: 33, line: 25]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: this index: 0 type: B\n" + + " [pc: 0, pc: 34] local: param index: 1 type: Value\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation +public void test1040() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Value CONST = A.foo(\"[I.CONST]\");\n" + + "}\n" + + "class Value {\n" + + " static String NAME = \"\";\n" + + " V v;\n" + + " Value(V v) {\n" + + " this.v = v;\n" + + " }\n" + + "}\n" + + "class A {\n" + + " static Value foo(String str) {\n" + + " System.out.print(str);\n" + + " return new Value(\"str\");\n" + + " }\n" + + "}\n" + + "class B implements I {\n" + + " static Value LOCAL_STATIC = A.foo(\"[B.LOCAL_STATIC]\");\n" + + " Value local_field = A.foo(\"[B.local_field]\");\n" + + " B(Value param) {\n" + + " String i = this.CONST.NAME; // keep for possible \n" + + " String k = this.LOCAL_STATIC.NAME; // may optimize out\n" + + " String l = this.local_field.NAME; // may optimize out\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B(new Value(\"[PARAM]\"));\n" + + " }\n" + + "}", // ================= + }, + "[B.LOCAL_STATIC][B.local_field][I.CONST]", + null, + false, + null, + options, + null); + // check the reference to I.CONST still got generated (for invocation side-effect) + String expectedOutput = + " // Method descriptor #28 (LValue;)V\n" + + " // Signature: (LValue;)V\n" + + " // Stack: 2, Locals: 2\n" + + " B(Value param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [30]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [32]\n" + + " 7 invokestatic A.foo(java.lang.String) : Value [17]\n" + + " 10 putfield B.local_field : Value [34]\n" + + " 13 getstatic B.CONST : Value [36]\n" + + " 16 pop\n" + + " 17 getstatic Value.NAME : java.lang.String [39]\n" + + " 20 pop\n" + + " 21 getstatic Value.NAME : java.lang.String [39]\n" + + " 24 pop\n" + + " 25 getstatic Value.NAME : java.lang.String [39]\n" + + " 28 pop\n" + + " 29 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 20]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 13, line: 21]\n" + + " [pc: 21, line: 22]\n" + + " [pc: 25, line: 23]\n" + + " [pc: 29, line: 24]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: this index: 0 type: B\n" + + " [pc: 0, pc: 30] local: param index: 1 type: Value\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159245 +public void test1041() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "\n" + + "public class X {\n" + + " {\n" + + " X rawx = null;\n" + + " X[] rawxs = { rawx };\n" + + " System.out.println(rawxs.length);\n" + + " }\n" + + " {\n" + + " p.X rawx = null;\n" + + " p.X[] rawxs = { rawx };\n" + + " System.out.println(rawxs.length);\n" + + " }\n" + + " Zork z;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 5)\n" + + " X rawx = null;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 6)\n" + + " X[] rawxs = { rawx };\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 10)\n" + + " p.X rawx = null;\n" + + " ^^^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in p\\X.java (at line 11)\n" + + " p.X[] rawxs = { rawx };\n" + + " ^^^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "5. ERROR in p\\X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159818 +public void test1042() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(T x) {\n" + + " Class c = x.getClass();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Class c = x.getClass();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 +public void test1043() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " T t;\n" + + " S s;\n" + + " void test(A a) {\n" + + " this.t = this.s; //fine\n" + + " a.t = a.s;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " a.t = a.s;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from capture#4-of ? extends S to capture#1-of ? extends Long\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug159214); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 - variation +public void test1044() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X x;\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 - variation +public void test1045() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X x;\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 +public void test1046() { + this.runConformTest( + new String[] { + "X.java", //======================== + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation +public void test1047() { + this.runConformTest( + new String[] { + "p/X.java", //======================== + "package p;\n" + + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "import p.X.Entry.Internal;\n" + + "public class Y implements Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "import p.X.Entry.Internal;\n" + + "public class Y implements Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation +public void test1048() { + this.runConformTest( + new String[] { + "X.java", //======================== + "public interface X {\n" + + " static class Entry {\n" + + " static abstract class Internal extends Entry {\n" + + " abstract Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "public class Y extends X.Entry.Internal {\n" + + " @Override public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "public class Y extends X.Entry.Internal {\n" + + " @Override public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +public void test1049() { + this.runConformTest( + new String[] { + "X.java", //======================== + "import java.util.*;\n" + + "public class X {\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface FooHandle> extends BarHandle {}\n" + + "interface Foo> extends FooHandle, Bar {\n" + + " FooHandle foo();\n" + + "}\n" + + "//===================\n" + + "interface EveHandle> extends SimpleHandle {}\n" + + "interface Eve> extends Simple, EveHandle {\n" + + " List foo();\n" + + " BazHandle handles();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface BobHandle extends BillHandle {}\n" + + "interface Bob extends BobHandle, Bill {}\n" + + "\n" + + "//===================\n" + + "interface BarHandle> extends BazHandle {\n" + + " boolean same(BarHandle o);\n" + + "}\n" + + "interface Bar> extends Baz, BarHandle {\n" + + " BarHandle handle();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface BazHandle> {\n" + + " T baz();\n" + + " boolean same(BazHandle o);\n" + + "}\n" + + "interface Baz> extends BazHandle {\n" + + " BazHandle handle();\n" + + " T baz();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface BillHandle extends FooHandle {}\n" + + "interface Bill extends BillHandle, Foo {}\n" + + "\n" + + "//===================\n" + + "interface SimpleHandle extends BazHandle {}\n" + + "interface Simple extends Baz, SimpleHandle {}\n" + + "\n" + + "//===================\n" + + "interface KeyHandle extends FooHandle {}\n" + + "interface Key extends Foo, KeyHandle {}\n" + + "\n" + + "//===================\n" + + "interface ClydeHandle extends BillHandle {}\n" + + "interface Clyde extends ClydeHandle, Bill {\n" + + " void add(BobHandle h);\n" + + " public List handles();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface FredHandle> extends BarHandle {}\n" + + "interface Fred> extends FredHandle, Bar {}\n" + + "\n", // ================= + }, + ""); +} +public void test1050() { + String expectedOutput = + "xxx\n" + + "true\n" + + "ClassCastException: Object[] cannot be cast to String[]\n" + + "ClassCastException: Object[] cannot be cast to String[]"; + + this.runConformTest( + new String[] { + "X.java", //======================== + "class Container {\n" + + " public Container() {\n" + + " data = (E[]) new Object[100];\n" + + " }\n" + + " protected E[] data;\n" + + " protected int size;\n" + + " E get(int index) {\n" + + " return data[index];\n" + + " }\n" + + " void add(E object) {\n" + + " data[size++] = object;\n" + + " }\n" + + " E[] data() {\n" + + " return data;\n" + + " }\n" + + "}\n" + + "class StringContainer extends Container {\n" + + " public StringContainer() {\n" + + " }\n" + + " public void doSomething() {\n" + + " add(\"xxx\");\n" + + " System.out.println(get(0));\n" + + " System.out.println((\"\" + data()).\n" + + " startsWith(\"[Ljava.lang.Object;@\"));\n" + + " try {\n" + + " System.out.println(data[0]);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"ClassCastException: Object[] cannot be cast to String[]\");\n" + + " }\n" + + " try {\n" + + " System.out.println(data()[0]);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"ClassCastException: Object[] cannot be cast to String[]\");\n" + + " }\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " StringContainer x = new StringContainer();\n" + + " x.doSomething();\n" + + " }\n" + + "}", // ================= + }, + expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114088 +public void test1051() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public interface Intf {\n" + + " void foo(List.Inner> ls);\n" + + " }\n" + + "\n" + + " public class Conc {\n" + + " Intf impl;\n" + + " public Conc(Intf impl) {\n" + + " this.impl = impl;\n" + + " }\n" + + " public class Inner { }\n" + + "\n" + + " public void bar(List.Inner> ls) {\n" + + " impl.foo(ls);\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115691 +public void test1052() { + Map options = this.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X extends java.util.ArrayList {\n" + + " private static final long serialVersionUID = 713223190582506215L;\n" + + " static void test() {\n" + + " java.util.ArrayList a1 = new X();\n" + + " X b1 = (X) a1;\n" + + " X c1 = X.class.cast(a1);\n" + + " java.util.ArrayList a2 = new X();\n" + + " X b2 = (X) a2;\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122163 +public void test1053() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " class innerclass {\n" + + " void foo() {\n" + + " X c = X.this;\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142935 +public void test1054() { + Map customOptions = getCompilerOptions(); + // check no unsafe type operation problem is issued + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + String expectedOutput = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Bar bar= clazz.getAnnotation(Bar.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to Bar\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\r\n" + + "import java.lang.annotation.RetentionPolicy;\r\n" + + "import java.lang.reflect.Method;\r\n" + + "\r\n" + + "@Bar\r\n" + + "public class X {\r\n" + + "\r\n" + + " @Bar\r\n" + + " public void bar() throws Exception {\r\n" + + " Class clazz= X.class;\r\n" + + " Bar bar= clazz.getAnnotation(Bar.class);\n" + + " Method method= clazz.getMethod(\"bar\");\r\n" + + " Bar bar2= method.getAnnotation(Bar.class);\r\n" + + " }\r\n" + + "}\r\n" + + "\r\n" + + "@Retention(RetentionPolicy.RUNTIME)\r\n" + + "@interface Bar {\r\n" + + "}", + }, + expectedOutput, + null, + true, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142935 +public void test1055() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\r\n" + + "import java.lang.annotation.RetentionPolicy;\r\n" + + "import java.lang.reflect.Method;\r\n" + + "\r\n" + + "@Bar\r\n" + + "public class X {\r\n" + + "\r\n" + + " @Bar\r\n" + + " public void bar() throws Exception {\r\n" + + " Class clazz= X.class;\r\n" + + " Bar bar= clazz.getAnnotation(Bar.class);\n" + + " Method method= clazz.getMethod(\"bar\");\r\n" + + " Bar bar2= method.getAnnotation(Bar.class);\r\n" + + " }\r\n" + + "}\r\n" + + "\r\n" + + "@Retention(RetentionPolicy.RUNTIME)\r\n" + + "@interface Bar {\r\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162400 +public void test1056() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static T foo() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String[] s = { foo() };\n" + + " } \n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159738 +public void test1057() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "class GenericType & Map.Entry> {\n" + + " public void doSomething(E e) {\n" + + " System.out.println(e.compareTo(e.getValue()));\n" + + " }\n" + + "}\n" + + "class ConcreteType {\n" + + " public void doSomething(Object obj) {\n" + + " System.out.println(((Comparable) obj).compareTo(((Map.Entry) obj).getValue()));\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new GenericType().doSomething(\"a1\");\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":1]\");\n" + + " }\n" + + " try {\n" + + " new ConcreteType().doSomething(\"a2\");\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":2]\");\n" + + " }\n" + + " }\n" + + "}\n", // =================, + }, + "[ClassCastException:1][ClassCastException:2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 +public void test1058() throws Exception { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " int foo = 0;\n" + + " String bar = \"zero\";\n" + + " System.out.println((foo != 0 ? foo : bar).compareTo(null));\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [foo]\n" + + " 2 ldc [16]\n" + + " 4 astore_2 [bar]\n" + + " 5 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 8 iload_1 [foo]\n" + + " 9 ifeq 19\n" + + " 12 iload_1 [foo]\n" + + " 13 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [24]\n" + + " 16 goto 20\n" + + " 19 aload_2 [bar]\n" + + " 20 aconst_null\n" + + " 21 invokeinterface java.lang.Comparable.compareTo(java.lang.Object) : int [30] [nargs: 2]\n" + + " 26 invokevirtual java.io.PrintStream.println(int) : void [36]\n" + + " 29 goto 41\n" + + " 32 astore_1 [e]\n" + + " 33 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 36 ldc [42]\n" + + " 38 invokevirtual java.io.PrintStream.println(java.lang.String) : void [44]\n" + + " 41 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 29] -> 32 when : java.lang.NullPointerException\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 5, line: 6]\n" + + " [pc: 32, line: 7]\n" + + " [pc: 33, line: 8]\n" + + " [pc: 41, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 42] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 32] local: foo index: 1 type: int\n" + + " [pc: 5, pc: 32] local: bar index: 2 type: java.lang.String\n" + + " [pc: 33, pc: 41] local: e index: 1 type: java.lang.NullPointerException\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160795 +public void test1059() { + this.runNegativeTest( + new String[] { + "A.java", // ================= + "class A {\n" + + " S test(A a) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " void m() {\n" + + " A a = null;\n" + + " Number b = test(a);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in A.java (at line 8)\n" + + " Number b = test(a);\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to Number\n" + + "----------\n"); +} +public void test1060() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", // ================= + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void m(List list,Collection coll) {\n" + + " m(list,coll);\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159752 +public void test1061() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "predicate/Predicate.java", // ================= + "package predicate;\n" + + "public interface Predicate {\n" + + " public boolean evaluate(T object);\n" + + "}\n" + + "final class AndPredicate implements Predicate {\n" + + " private final Predicate iPredicate1;\n" + + " private final Predicate iPredicate2;\n" + + " public static Predicate getInstance(Predicate predicate1,\n" + + " Predicate predicate2) {\n" + + " if (predicate1 == null || predicate2 == null) {\n" + + " throw new IllegalArgumentException(\"Predicate must not be null\");\n" + + " }\n" + + " return new AndPredicate(predicate1, predicate2);\n" + + " }\n" + + " public AndPredicate(Predicate predicate1,\n" + + " Predicate predicate2) {\n" + + " super();\n" + + " iPredicate1 = predicate1;\n" + + " iPredicate2 = predicate2;\n" + + " }\n" + + " public boolean evaluate(T object) {\n" + + " return iPredicate1.evaluate(object) && iPredicate2.evaluate(object);\n" + + " }\n" + + "}\n" + + "class PredicateUtils {\n" + + "\n" + + " public static Predicate andPredicate(\n" + + " Predicate predicate1, Predicate predicate2) {\n" + + " return AndPredicate.getInstance(predicate1, predicate2);\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 +public void test1062() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashSet;\n" + + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set set = new HashSet();\n" + + " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + + " Set element1 = iterator.next();\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Set element1 = iterator.next();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to Set\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to Set\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation +public void test1063() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashSet;\n" + + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set set = new HashSet();\n" + + " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + + " Set element1 = iterator.next();\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Set element1 = iterator.next();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Cloneable to Set\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Cloneable to Set\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation +public void test1064() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashSet;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " HashSet set = new HashSet();\n" + + " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + + " HashSet element1 = iterator.next();\n" + + " HashSet element2 = (HashSet) iterator.next();\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " HashSet element1 = iterator.next();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to HashSet\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " HashSet element2 = (HashSet) iterator.next();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to HashSet\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 - variation +public void test1065() throws Exception { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " void testFoo(boolean t, A a, B b) {\n" + + " System.out.print((t ? a : b).foo());\n" + + " }\n" + + " void testBar(boolean t, A a, B b) {\n" + + " System.out.print((t ? a : b).bar());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " A a = new A();\n" + + " B b = new B();\n" + + " x.testFoo(true, a, b);\n" + + " x.testFoo(false, a, b);\n" + + " x.testBar(true, a, b);\n" + + " x.testBar(false, a, b);\n" + + " }\n" + + "}\n" + + "interface Foo { String foo(); }\n" + + "interface Bar { String bar(); }\n" + + "class A implements Foo, Bar {\n" + + " public String foo() { return \"[A#foo()]\"; }\n" + + " public String bar() { return \"[A#bar()]\"; }\n" + + "}\n" + + "class B implements Foo, Bar {\n" + + " public String foo() { return \"[B#foo()]\"; }\n" + + " public String bar() { return \"[B#bar()]\"; }\n" + + "}\n", // ================= + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "[A#foo()][B#foo()][A#bar()][B#bar()]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + // check presence of checkcast in #testFoo() and #testBar() + String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_5 + ? " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testFoo(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 invokeinterface Foo.foo() : java.lang.String [22] [nargs: 1]\n" + + " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 20, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 0, pc: 21] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 21] local: a index: 2 type: A\n" + + " [pc: 0, pc: 21] local: b index: 3 type: B\n" + + " \n" + + " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testBar(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 checkcast Bar [41]\n" + + " 15 invokeinterface Bar.bar() : java.lang.String [43] [nargs: 1]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 23 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 23, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 24] local: this index: 0 type: X\n" + + " [pc: 0, pc: 24] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 24] local: a index: 2 type: A\n" + + " [pc: 0, pc: 24] local: b index: 3 type: B\n" + : " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testFoo(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 invokeinterface Foo.foo() : java.lang.String [22] [nargs: 1]\n" + + " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 20, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 0, pc: 21] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 21] local: a index: 2 type: A\n" + + " [pc: 0, pc: 21] local: b index: 3 type: B\n" + + " Stack map table: number of frames 2\n" + + " [pc: 11, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 12, full, stack: {java.io.PrintStream, Foo}, locals: {X, int, A, B}]\n" + + " \n" + + " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testBar(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 checkcast Bar [46]\n" + + " 15 invokeinterface Bar.bar() : java.lang.String [48] [nargs: 1]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 23 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 23, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 24] local: this index: 0 type: X\n" + + " [pc: 0, pc: 24] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 24] local: a index: 2 type: A\n" + + " [pc: 0, pc: 24] local: b index: 3 type: B\n" + + " Stack map table: number of frames 2\n" + + " [pc: 11, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 12, full, stack: {java.io.PrintStream, Foo}, locals: {X, int, A, B}]\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 - variation +public void test1066() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " List l = new ArrayList();\n" + + " l.add(\"zork\");\n" + + " List la = l;\n" + + " List lb = l;\n" + + " boolean t = true, f = false;\n" + + " try {\n" + + " System.out.print((t ? la.get(0) : lb.get(0)).foo());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":foo(1)]\");\n" + + " } \n" + + " try {\n" + + " System.out.print((f ? la.get(0) : lb.get(0)).foo());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":foo(2)]\");\n" + + " } \n" + + " try {\n" + + " System.out.print((t ? la.get(0) : lb.get(0)).bar());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":bar(1)]\");\n" + + " } \n" + + " try {\n" + + " System.out.print((f ? la.get(0) : lb.get(0)).bar());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":bar(2)]\");\n" + + " } \n" + + " }\n" + + "}\n" + + "interface Foo { String foo(); }\n" + + "interface Bar { String bar(); }\n" + + "abstract class A implements Foo, Bar { }\n" + + "abstract class B implements Foo, Bar { }\n", // ================= + }, + "[ClassCastException:foo(1)][ClassCastException:foo(2)][ClassCastException:bar(1)][ClassCastException:bar(2)]"); + // check presence of checkcast + String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_5 + ? " // Stack: 4, Locals: 8\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [16]\n" + + " 7 astore_1 [x]\n" + + " 8 new java.util.ArrayList [17]\n" + + " 11 dup\n" + + " 12 invokespecial java.util.ArrayList() [19]\n" + + " 15 astore_2 [l]\n" + + " 16 aload_2 [l]\n" + + " 17 ldc [20]\n" + + " 19 invokeinterface java.util.List.add(java.lang.Object) : boolean [22] [nargs: 2]\n" + + " 24 pop\n" + + " 25 aload_2 [l]\n" + + " 26 astore_3 [la]\n" + + " 27 aload_2 [l]\n" + + " 28 astore 4 [lb]\n" + + " 30 iconst_1\n" + + " 31 istore 5 [t]\n" + + " 33 iconst_0\n" + + " 34 istore 6 [f]\n" + + " 36 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 39 iload 5 [t]\n" + + " 41 ifeq 57\n" + + " 44 aload_3 [la]\n" + + " 45 iconst_0\n" + + " 46 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 51 checkcast Foo [38]\n" + + " 54 goto 68\n" + + " 57 aload 4 [lb]\n" + + " 59 iconst_0\n" + + " 60 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 65 checkcast Foo [38]\n" + + " 68 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 73 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 76 goto 115\n" + + " 79 astore 7 [e]\n" + + " 81 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 84 new java.lang.StringBuilder [50]\n" + + " 87 dup\n" + + " 88 ldc [52]\n" + + " 90 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 93 aload 7 [e]\n" + + " 95 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 98 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 101 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 104 ldc [69]\n" + + " 106 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 109 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 112 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 115 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 118 iload 6 [f]\n" + + " 120 ifeq 136\n" + + " 123 aload_3 [la]\n" + + " 124 iconst_0\n" + + " 125 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 130 checkcast Foo [38]\n" + + " 133 goto 147\n" + + " 136 aload 4 [lb]\n" + + " 138 iconst_0\n" + + " 139 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 144 checkcast Foo [38]\n" + + " 147 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 155 goto 194\n" + + " 158 astore 7 [e]\n" + + " 160 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 163 new java.lang.StringBuilder [50]\n" + + " 166 dup\n" + + " 167 ldc [52]\n" + + " 169 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 172 aload 7 [e]\n" + + " 174 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 177 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 180 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 183 ldc [74]\n" + + " 185 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 188 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 191 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 194 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 197 iload 5 [t]\n" + + " 199 ifeq 215\n" + + " 202 aload_3 [la]\n" + + " 203 iconst_0\n" + + " 204 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 209 checkcast Foo [38]\n" + + " 212 goto 226\n" + + " 215 aload 4 [lb]\n" + + " 217 iconst_0\n" + + " 218 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 223 checkcast Foo [38]\n" + + " 226 checkcast Bar [76]\n" + + " 229 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 234 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 237 goto 276\n" + + " 240 astore 7 [e]\n" + + " 242 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 245 new java.lang.StringBuilder [50]\n" + + " 248 dup\n" + + " 249 ldc [52]\n" + + " 251 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 254 aload 7 [e]\n" + + " 256 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 259 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 262 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 265 ldc [81]\n" + + " 267 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 270 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 273 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 276 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 279 iload 6 [f]\n" + + " 281 ifeq 297\n" + + " 284 aload_3 [la]\n" + + " 285 iconst_0\n" + + " 286 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 291 checkcast Foo [38]\n" + + " 294 goto 308\n" + + " 297 aload 4 [lb]\n" + + " 299 iconst_0\n" + + " 300 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 305 checkcast Foo [38]\n" + + " 308 checkcast Bar [76]\n" + + " 311 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 316 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 319 goto 358\n" + + " 322 astore 7 [e]\n" + + " 324 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 327 new java.lang.StringBuilder [50]\n" + + " 330 dup\n" + + " 331 ldc [52]\n" + + " 333 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 336 aload 7 [e]\n" + + " 338 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 341 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 344 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 347 ldc [83]\n" + + " 349 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 352 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 355 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 358 return\n" + + " Exception Table:\n" + + " [pc: 36, pc: 76] -> 79 when : java.lang.Throwable\n" + + " [pc: 115, pc: 155] -> 158 when : java.lang.Throwable\n" + + " [pc: 194, pc: 237] -> 240 when : java.lang.Throwable\n" + + " [pc: 276, pc: 319] -> 322 when : java.lang.Throwable\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 25, line: 7]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 36, line: 11]\n" + + " [pc: 79, line: 12]\n" + + " [pc: 81, line: 13]\n" + + " [pc: 115, line: 16]\n" + + " [pc: 158, line: 17]\n" + + " [pc: 160, line: 18]\n" + + " [pc: 194, line: 21]\n" + + " [pc: 240, line: 22]\n" + + " [pc: 242, line: 23]\n" + + " [pc: 276, line: 26]\n" + + " [pc: 322, line: 27]\n" + + " [pc: 324, line: 28]\n" + + " [pc: 358, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 359] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 359] local: x index: 1 type: X\n" + + " [pc: 16, pc: 359] local: l index: 2 type: java.util.List\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + + " [pc: 33, pc: 359] local: t index: 5 type: boolean\n" + + " [pc: 36, pc: 359] local: f index: 6 type: boolean\n" + + " [pc: 81, pc: 115] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 160, pc: 194] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 242, pc: 276] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 324, pc: 358] local: e index: 7 type: java.lang.Throwable\n" + + " Local variable type table:\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + : " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 8\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [16]\n" + + " 7 astore_1 [x]\n" + + " 8 new java.util.ArrayList [17]\n" + + " 11 dup\n" + + " 12 invokespecial java.util.ArrayList() [19]\n" + + " 15 astore_2 [l]\n" + + " 16 aload_2 [l]\n" + + " 17 ldc [20]\n" + + " 19 invokeinterface java.util.List.add(java.lang.Object) : boolean [22] [nargs: 2]\n" + + " 24 pop\n" + + " 25 aload_2 [l]\n" + + " 26 astore_3 [la]\n" + + " 27 aload_2 [l]\n" + + " 28 astore 4 [lb]\n" + + " 30 iconst_1\n" + + " 31 istore 5 [t]\n" + + " 33 iconst_0\n" + + " 34 istore 6 [f]\n" + + " 36 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 39 iload 5 [t]\n" + + " 41 ifeq 57\n" + + " 44 aload_3 [la]\n" + + " 45 iconst_0\n" + + " 46 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 51 checkcast Foo [38]\n" + + " 54 goto 68\n" + + " 57 aload 4 [lb]\n" + + " 59 iconst_0\n" + + " 60 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 65 checkcast Foo [38]\n" + + " 68 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 73 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 76 goto 115\n" + + " 79 astore 7 [e]\n" + + " 81 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 84 new java.lang.StringBuilder [50]\n" + + " 87 dup\n" + + " 88 ldc [52]\n" + + " 90 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 93 aload 7 [e]\n" + + " 95 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 98 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 101 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 104 ldc [69]\n" + + " 106 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 109 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 112 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 115 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 118 iload 6 [f]\n" + + " 120 ifeq 136\n" + + " 123 aload_3 [la]\n" + + " 124 iconst_0\n" + + " 125 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 130 checkcast Foo [38]\n" + + " 133 goto 147\n" + + " 136 aload 4 [lb]\n" + + " 138 iconst_0\n" + + " 139 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 144 checkcast Foo [38]\n" + + " 147 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 155 goto 194\n" + + " 158 astore 7 [e]\n" + + " 160 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 163 new java.lang.StringBuilder [50]\n" + + " 166 dup\n" + + " 167 ldc [52]\n" + + " 169 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 172 aload 7 [e]\n" + + " 174 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 177 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 180 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 183 ldc [74]\n" + + " 185 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 188 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 191 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 194 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 197 iload 5 [t]\n" + + " 199 ifeq 215\n" + + " 202 aload_3 [la]\n" + + " 203 iconst_0\n" + + " 204 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 209 checkcast Foo [38]\n" + + " 212 goto 226\n" + + " 215 aload 4 [lb]\n" + + " 217 iconst_0\n" + + " 218 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 223 checkcast Foo [38]\n" + + " 226 checkcast Bar [76]\n" + + " 229 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 234 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 237 goto 276\n" + + " 240 astore 7 [e]\n" + + " 242 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 245 new java.lang.StringBuilder [50]\n" + + " 248 dup\n" + + " 249 ldc [52]\n" + + " 251 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 254 aload 7 [e]\n" + + " 256 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 259 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 262 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 265 ldc [81]\n" + + " 267 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 270 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 273 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 276 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 279 iload 6 [f]\n" + + " 281 ifeq 297\n" + + " 284 aload_3 [la]\n" + + " 285 iconst_0\n" + + " 286 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 291 checkcast Foo [38]\n" + + " 294 goto 308\n" + + " 297 aload 4 [lb]\n" + + " 299 iconst_0\n" + + " 300 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 305 checkcast Foo [38]\n" + + " 308 checkcast Bar [76]\n" + + " 311 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 316 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 319 goto 358\n" + + " 322 astore 7 [e]\n" + + " 324 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 327 new java.lang.StringBuilder [50]\n" + + " 330 dup\n" + + " 331 ldc [52]\n" + + " 333 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 336 aload 7 [e]\n" + + " 338 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 341 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 344 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 347 ldc [83]\n" + + " 349 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 352 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 355 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 358 return\n" + + " Exception Table:\n" + + " [pc: 36, pc: 76] -> 79 when : java.lang.Throwable\n" + + " [pc: 115, pc: 155] -> 158 when : java.lang.Throwable\n" + + " [pc: 194, pc: 237] -> 240 when : java.lang.Throwable\n" + + " [pc: 276, pc: 319] -> 322 when : java.lang.Throwable\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 25, line: 7]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 36, line: 11]\n" + + " [pc: 79, line: 12]\n" + + " [pc: 81, line: 13]\n" + + " [pc: 115, line: 16]\n" + + " [pc: 158, line: 17]\n" + + " [pc: 160, line: 18]\n" + + " [pc: 194, line: 21]\n" + + " [pc: 240, line: 22]\n" + + " [pc: 242, line: 23]\n" + + " [pc: 276, line: 26]\n" + + " [pc: 322, line: 27]\n" + + " [pc: 324, line: 28]\n" + + " [pc: 358, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 359] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 359] local: x index: 1 type: X\n" + + " [pc: 16, pc: 359] local: l index: 2 type: java.util.List\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + + " [pc: 33, pc: 359] local: t index: 5 type: boolean\n" + + " [pc: 36, pc: 359] local: f index: 6 type: boolean\n" + + " [pc: 81, pc: 115] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 160, pc: 194] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 242, pc: 276] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 324, pc: 358] local: e index: 7 type: java.lang.Throwable\n" + + " Local variable type table:\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + + " Stack map table: number of frames 16\n" + + " [pc: 57, full, stack: {java.io.PrintStream}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 68, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 79, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 115, same]\n" + + " [pc: 136, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 147, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 158, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 194, same]\n" + + " [pc: 215, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 226, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 240, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 276, same]\n" + + " [pc: 297, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 308, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 322, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 358, same]\n"; + + 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); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162991 +// using only source types +public void test1067() { + this.runConformTest( + new String[] { + "Something.java", + "public interface Something {\n" + + "\n" + + "}", // ================= + "Doing.java", // ================= + "public interface Doing {\n" + + " public T get(Class clazz);\n" + + "}", // ================= + "DoingImpl.java", // ================= + "public class DoingImpl implements Doing {\n" + + " public T get(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}" // ================= + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162991 +// using source and binary types +public void test1068() { + this.runConformTest( + new String[] { + "Something.java", + "public interface Something {\n" + + "\n" + + "}", // ================= + "Doing.java", // ================= + "public interface Doing {\n" + + " public T get(Class clazz);\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "DoingImpl.java", // ================= + "public class DoingImpl implements Doing {\n" + + " public T get(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}" // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163262 +public void test1069() { + this.runConformTest( + new String[] { + "Bug.java", // ================= + "public class Bug {\n" + + " void bug() {\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " Bug bug = Bug.this;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163262 +public void test1070() { + this.runConformTest( + new String[] { + "Bug.java", // ================= + "public class Bug {\n" + + " Bug reproduce() {\n" + + " return Bug.this;\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1071() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " void[] local;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void[] local;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1072() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " void[] local;\n" + + " Class c = void[].class;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void[] local;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " Class c = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1073() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " try {\n" + + " void[] local;\n" + + " Class c = void[].class;\n" + + " } catch(void[] e) {\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " void[] local;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Class c = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " } catch(void[] e) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1074() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " try {\n" + + " void[] local = new void[0];\n" + + " void[] local1 = new void[]{ null, null };\n" + + " void[] local2 = { null, null };\n" + + " System.out.println((void[]) null);\n" + + " Class c = void[].class;\n" + + " } catch(void[] e) {\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " void[] local = new void[0];\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " void[] local = new void[0];\n" + + " ^^^^^^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " void[] local1 = new void[]{ null, null };\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "8. ERROR in X.java (at line 8)\n" + + " void[] local1 = new void[]{ null, null };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "9. ERROR in X.java (at line 9)\n" + + " void[] local2 = { null, null };\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "10. ERROR in X.java (at line 10)\n" + + " System.out.println((void[]) null);\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "11. ERROR in X.java (at line 11)\n" + + " Class c = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "12. ERROR in X.java (at line 12)\n" + + " } catch(void[] e) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n", + null, + true, + options); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163680 +public void test1075() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X .J>{\n" + + " public class J implements I{}\n" + + "}\n", + "I.java", + "public interface I {}\n", + "Y.java", + "public class Y extends X {}\n", + }, + // runtime results + "" /* expected output string */); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { + "Y.java", + "public class Y extends X {}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +public void test1076() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " List threads;\n" + + " void foo(String[] strings) {}\n" + + " void bar() {\n" + + " foo(this.threads.toArray(new String[this.threads.size()]));\n" + + " foo(myToArray(this.threads, new String[this.threads.size()]));\n" + + " foo(myToArray2(this.threads, new String[this.threads.size()]));\n" + + " }\n" + + " \n" + + " static T[] myToArray(List list, T[] a) {\n" + + " return list.toArray(a);\n" + + " }\n" + + " static T[] myToArray2(List list, T[] a) {\n" + + " return list.toArray(a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " foo(myToArray2(this.threads, new String[this.threads.size()]));\n" + + " ^^^^^^^^^^\n" + + "Bound mismatch: The generic method myToArray2(List, T[]) of type X is not applicable for the arguments (List, String[]). The inferred type Thread is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +// check presence of field hiding warning +public void test1077() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y {\n" + + " static int foo;\n" + + " }\n" + + " static class Z extends Y {\n" + + " int foo;\n" + + " {\n" + + " foo = 1;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " int foo;\n" + + " ^^^\n" + + "The field X.Z.foo is hiding a field from type X.Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 +public void test1078() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X \n" + + "{\n" + + " public static void main(String[] args)\n" + + " {\n" + + " Object object = null;\n" + + "\n" + + " List list = (List)object;//[1]\n" + + "\n" + + " foo((List)object);//[2]\n" + + " foo((List)object);//[3]\n" + + " foo((List)object);//[4]unchecked cast\n" + + " foo((List)object);//[5]\n" + + "\n" + + " foo((Map)object);//[6]\n" + + " foo((Map)object);//[7]\n" + + " foo((Map)object);//[8]unchecked cast\n" + + " foo((Map)object);//[9]unchecked cast\n" + + " foo((Map)object);//[10]unchecked cast\n" + + " foo((Map)object);//[11]unchecked cast\n" + + " foo((Map)object);//[12]\n" + + " Zork z;\n" + + " }\n" + + "\n" + + " public static void foo(List list) {\n" + + " }\n" + + "\n" + + " public static void foo(Map map) {\n" + + " }\n" + + "}", // =================, + }, + // unchecked warnings on [4][5][8][9][10][11][12] + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List list = (List)object;//[1]\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List list = (List)object;//[1]\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " foo((List)object);//[2]\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " foo((List)object);//[4]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " foo((List)object);//[5]\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " foo((Map)object);//[6]\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " foo((Map)object);//[8]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "8. WARNING in X.java (at line 20)\n" + + " foo((Map)object);//[9]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "9. WARNING in X.java (at line 21)\n" + + " foo((Map)object);//[10]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "10. WARNING in X.java (at line 22)\n" + + " foo((Map)object);//[11]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "11. WARNING in X.java (at line 23)\n" + + " foo((Map)object);//[12]\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "12. ERROR in X.java (at line 24)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1079() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar(Object o) {\n" + + " return (AX) o;\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "class AX extends X {}\n", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (AX) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1080() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " CX foo(X x) {\n" + + " return (CX) x; // unchecked\n" + + " }\n" + + " BX bar(X x) {\n" + + " return (BX) x;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class AX extends X {}\n" + + "class BX extends AX {}\n" + + "class CX extends AX {}\n", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (CX) x; // unchecked\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to CX\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1081() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " AX foo(X x) {\n" + + " return (BX) x;\n" + + " }\n" + + "}\n" + + "class AX extends X {}\n" + + "class BX extends AX {}\n", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return (BX) x;\n" + + " ^^^^^^\n" + + "Cannot cast from X to BX\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1082() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " CX foo(X x) {\n" + + " return (CX) x; // unchecked\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class AX extends X {}\n" + + "class CX extends AX {}\n", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (CX) x; // unchecked\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to CX\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " class CX extends AX {}\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106451 - variation +public void test1083() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.io.Serializable;\n" + + "import java.util.LinkedList;\n" + + "\n" + + "class SerializableList extends LinkedList {\n" + + " private static final long serialVersionUID = 1L; \n" + + "}\n" + + "public class X {\n" + + " @SuppressWarnings({\"nls\", \"unused\"})\n" + + " public static void main(String[] args) {\n" + + " LinkedList linkedList= new LinkedList();\n" + + " linkedList.add(\"Hello\");\n" + + " java.util.List a = linkedList;\n" + + " java.util.List b = (LinkedList) a; // unchecked\n" + + " java.util.List c = (LinkedList) a; // unchecked\n" + + " java.util.List d = (LinkedList) a; // inconvertible / unchecked ?\n" + + " c.get(0).intValue(); // fails at run time\n" + + " d.get(0).gc(); // fails at run time\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " java.util.List b = (LinkedList) a; // unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " java.util.List c = (LinkedList) a; // unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " java.util.List d = (LinkedList) a; // inconvertible / unchecked ?\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 +public void test1084() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + "}\n" + + "class Z {\n" + + "}\n" + + "class X {\n" + + " void foo() {\n" + + " Z> l1 = null;\n" + + " Z l2 = (Z) l1;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " Z l2 = (Z) l1;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Z l2 = (Z) l1;\n" + + " ^^^^^^^^^\n" + + "Cannot cast from Z> to Z\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " Z l2 = (Z) l1;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165291 +public void test1085() { + this.runNegativeTest( + new String[] { + "Y.java", + "class Z {\n" + + " Z z1 = z1;\n" + + " Z[] z2 = z2;\n" + + "}\n" + + "public class Y {\n" + + " E e0 = es[0];\n" + + " E e = e;\n" + + " E[] es = es;\n" + + " E e2 = e2.e;\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " Z z1 = z1;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " Z[] z2 = z2;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " E e0 = es[0];\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. ERROR in Y.java (at line 7)\n" + + " E e = e;\n" + + " ^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " E[] es = es;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "6. ERROR in Y.java (at line 9)\n" + + " E e2 = e2.e;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "7. ERROR in Y.java (at line 9)\n" + + " E e2 = e2.e;\n" + + " ^^^^\n" + + "e2.e cannot be resolved or is not a field\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165645 +public void test1086() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IFoo { void foo(); }\n" + + "interface IBar { void bar(); }\n" + + "public class X {\n" + + " class Bar implements IBar { public void bar(){} }\n" + + " void foo(Bar b) {\n" + + " b.foo(); // unbound (Bar is member type)\n" + + " b.bar(); // ok\n" + + " }\n" + + "}\n", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " b.foo(); // unbound (Bar is member type)\n" + + " ^^^\n" + + "The method foo() is undefined for the type X.Bar\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165645 - variation +public void test1087() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static public class M {\n" + + " }\n" + + " static public class M2 extends M {\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 +public void test1088() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static public class M {}\n" + + " Zork z;\n" + + " void foo() {\n" + + " class M {} // hides member\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Local {}\n" + + " void foo() {\n" + + " class T {}; // hiding warning\n" + + " class Local {};\n" + + " }\n" + + " static void bar() {\n" + + " class T {}; // no hiding warning\n" + + " class Local {}; // no hiding warning\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " class M {} // hides member\n" + + " ^\n" + + "The type M is hiding the type X.M\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class T {}; // hiding warning\n" + + " ^\n" + + "The nested type T is hiding the type parameter T of type Y\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " class T {}; // hiding warning\n" + + " ^\n" + + "The type T is never used locally\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " class Local {};\n" + + " ^^^^^\n" + + "The type Local is hiding the type Y.Local\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " class Local {};\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " class T {}; // no hiding warning\n" + + " ^\n" + + "The type T is never used locally\n" + + "----------\n" + + "8. WARNING in X.java (at line 16)\n" + + " class Local {}; // no hiding warning\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 - variation +public void test1089() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class U {}\n" + + " void foo(T t) {\n" + + " class T {\n" + + " T t = t;\n" + + " }\n" + + " class U {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class T {\n" + + " ^\n" + + "The nested type T is hiding the type parameter T of the generic method foo(T) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " T t = t;\n" + + " ^\n" + + "The field T.t is hiding another local variable defined in an enclosing type scope\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " T t = t;\n" + + " ^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " class U {\n" + + " ^\n" + + "The type U is hiding the type X.U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 - variation +public void _test1090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class T {} // warn hiding type parameter\n" + + " class U {}// warn hiding type parameter+warn param hiding member type\n" + + " \n" + + " void foo() {\n" + + " class Local {\n" + + " class T {} // warn hiding type parameter\n" + + " class U {}// warn hiding type parameter+warn param hiding member type\n" + + " }\n" + + " }\n" + + " static void bar() {\n" + + " class Local {\n" + + " class T {} // no warn\n" + + " class U {} // no warn\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "???"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165909 +public void test1091() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " Object a = null;\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " }\n" + + " void bar() {\n" + + " Number a = null;\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map.Entry\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Number to Map.Entry\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166490 +public void test1092() { + Map customOptions = this.getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "Class_01.java", + "public interface Class_01> extends\r\n" + + " Class_09 {\r\n" + + "}", + "Class_02.java", + "public interface Class_02> extends\r\n" + + " Class_10 {\r\n" + + "}", + "Class_03.java", + "public abstract class Class_03, H extends Class_02, P extends Class_06>\r\n" + + " extends Class_08 implements Class_05 {\r\n" + + "}", + "Class_04.java", + "public interface Class_04 extends Class_06, Class_19{\r\n" + + "}", + "Class_05.java", + "public interface Class_05{\r\n" + + "}", + "Class_06.java", + "public interface Class_06> extends\r\n" + + " Class_13, Class_17 {\r\n" + + "}", + "Class_07.java", + "public interface Class_07

> extends\r\n" + + " Class_14 {\r\n" + + "}", + "Class_08.java", + "public abstract class Class_08, H extends Class_10, P extends Class_06>\r\n" + + " extends Class_11 implements Class_05 {\r\n" + + "}", + "Class_09.java", + "public interface Class_09> extends\r\n" + + " Class_13, Class_17 {\r\n" + + "}", + "Class_10.java", + "public interface Class_10> extends\r\n" + + " Class_14 {\r\n" + + "}", + "Class_11.java", + "public abstract class Class_11, H extends Class_14, O>\r\n" + + " extends Class_15 implements Class_05 {\r\n" + + "}", + "Class_12.java", + "public final class Class_12 {\r\n" + + "}", + "Class_13.java", + "public interface Class_13, O>{\r\n" + + "}", + "Class_14.java", + "public interface Class_14, O>{\r\n" + + "}", + "Class_15.java", + "public abstract class Class_15, H extends Class_14, O>\r\n" + + " extends Class_16 {\r\n" + + "}", + "Class_16.java", + "public abstract class Class_16{\r\n" + + "}", + "Class_17.java", + "public interface Class_17{\r\n" + + "}", + "Class_18.java", + "public interface Class_18 extends Class_07{\r\n" + + "}", + "Class_19.java", + "public interface Class_19{\r\n" + + "}", + "MyClass.java", + "abstract class MyClass, H extends Class_02>\r\n" + + " extends Class_03 implements Class_05 {\r\n" + + "}" + }, + "", + null, + true, + null, + customOptions, + null); + + // incremental build + this.runConformTest( + new String[] { + "Class_01.java", + "public interface Class_01> extends\r\n" + + " Class_09 {\r\n" + + "}", + }, + "", + null, + false, + null, + customOptions, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=156952 +// invalid bug - regression test only +public void test1093() { + Map customOptions = this.getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X foo() {\n" + + " return this;\n" + + " }\n" + + " T bar(T p) {\n" + + " return p;\n" + " }\n" + + " public static void main (String args) {\n" + + " X x1 = new X();\n" + + " System.out.println(x1.foo().bar(\"OK\"));\n" + // OK + " X x2 = new X();\n" + + " System.out.println(x2.foo().bar(\"OK\"));\n" + // KO: type safety issue + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 12)\n" + + " System.out.println(x2.foo().bar(\"OK\"));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + customOptions, + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + false /* do not perform statements recovery */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167268 +public void test1094() { + Map customOptions = this.getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "Crazy.java", + "public interface Crazy {}", + "ExampleFactory.java", + "public interface ExampleFactory {\n" + + " Crazy createCrazy();\n" + + "}", + "Other.java", + "public interface Other {}", + "ExampleFactoryImpl.java", + "public class ExampleFactoryImpl implements ExampleFactory {\n" + + " public Crazy createCrazy() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null /* vm arguments*/, + customOptions, + null /* compiler requestor*/); + this.runConformTest( + new String[] { + "ExampleFactoryImpl.java", + "public class ExampleFactoryImpl implements ExampleFactory {\n" + + " public Crazy createCrazy() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + false /* flush output directory */, + null /* vm arguments*/, + customOptions, + null /* compiler requestor*/); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 +//invalid bug - regression test only +public void test1095() { + Map customOptions = this.getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.lang.reflect.Constructor;\n" + + "\n" + + "@interface Annot {\n" + + " String message() default \"\"; //$NON-NLS-1$\n" + + "}\n" + + "\n" + + "public class X {\n" + + " X() {\n" + + " }\n" + + " public String getAnnotationValue(Constructor constructor){\n" + + " Annot annotation = constructor.getAnnotation(Annot.class);\n" + + " return (annotation != null) ? annotation.message() : null;\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 11)\n" + + " Annot annotation = constructor.getAnnotation(Annot.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to Annot\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 +//invalid bug - regression test only +public void test1096() { + Map customOptions = this.getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Constructor;\n" + + "\n" + + "@interface Annot {\n" + + " String message() default \"\"; //$NON-NLS-1$\n" + + "}\n" + + "\n" + + "public class X {\n" + + " X() {\n" + + " }\n" + + " public String getAnnotationValue(Constructor constructor){\n" + + " Annot annotation = constructor.getAnnotation(Annot.class);\n" + + " return (annotation != null) ? annotation.message() : null;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null, + customOptions, + null/* do not perform statements recovery */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=168232 +public void test1097() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " String[] foo = new String[] {};\n" + + "}" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " String[] foo = new String[] {};\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " String[] foo = new String[] {};\n" + + " ^\n" + + "Syntax error on token \">\", , expected\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 +public void test1098() { + this.runNegativeTest(new String[] { + "X.java", + "public class X { \n" + + " private class A {\n" + + " class B {}\n" + + " }\n" + + " private class Y extends A {\n" + + " }\n" + + " Y.B d = null;\n" + + "}\n" + + "class Y extends Zork {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private class Y extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1099() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public class A {};\n" + + " public class B extends A {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " List l = x.newList(x.new B());\n" + + " for (A a: l) {\n" + + " System.out.println(a);\n" + + " }\n" + + " }\n" + + "\n" + + " public List newList(V... values) {\n" + + " List l = new ArrayList();\n" + + " for (V v : values) {\n" + + " l.add(v);\n" + + " }\n" + + " return l;\n" + + " }\n" + + "\n" + + "}\n" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170318 +public void test1100() { + this.runNegativeTest(new String[] { + "X.java", + "class X {\n" + + "}\n" + + "class Y {\n" + + " public void foo(final X x) {\n" + + " }\n" + + "}\n" + + "class Z extends Y {\n" + + " public void foo(final X x) {\n" + + " super.foo(x);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " class Z extends Y {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void foo(final X x) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(X) of type Z has the same erasure as foo(X) of type Y but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " super.foo(x);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The method foo(X) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172189 +public void test1101() { + this.runNegativeTest(new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public final class X {\n" + + " public A a;\n" + + " public B b;\n" + + " public X(A pa, B pb) {\n" + + " a = pa;\n" + + " b = pb;\n" + + " }\n" + + " public static X create(A pa, B pb) {\n" + + " return new X(pa, pb);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List> list = new ArrayList>();\n" + + " list.add(X.create(\"\", \"\"));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " list.add(X.create(\"\", \"\"));\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 +public void test1102() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + "\n" + + " class A {\n" + + " A(T t) {\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X(null);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 +public void test1103() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + " X(int i) {\n" + + " this(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(null);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 +public void test1104() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X(T t) { }\n" + + " \n" + + " class A {\n" + + " A(T t) { }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X(null).new A(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " new X(null).new A(null);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174724 +public void test1105() { + Map customOptions = this.getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class foo = Class.forName(Integer.class.getName());\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Class foo = Class.forName(Integer.class.getName());\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174766 +public void test1106() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public class Y extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " public class Y extends Exception {\n" + + " ^^^^^^^^^\n" + + "The generic class X.Y may not subclass java.lang.Throwable\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172913 +public void test1107() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.HashMap;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private void processLocks(HashMap locksMap, Object key) {\n" + + " for (Iterator iter = locksMap.keySet().iterator(); iter.hasNext();) {\n" + + " Object call = iter.next();\n" + + " List locks = externLocks((Collection) locksMap.get(call), call);\n" + + " // ...\n" + + " }\n" + + " }\n" + + " private List externLocks(Collection locks, Object call) {\n" + + " List result = new ArrayList();\n" + + " // ..\n" + + " return result;\n" + + " }\n" + + "}\n", + }, + ""); + // ensure only one instance of: checkcast java.util.Collection + String expectedOutput = + " // Method descriptor #15 (Ljava/util/HashMap;Ljava/lang/Object;)V\n" + + " // Stack: 3, Locals: 6\n" + + " private void processLocks(java.util.HashMap locksMap, java.lang.Object key);\n" + + " 0 aload_1 [locksMap]\n" + + " 1 invokevirtual java.util.HashMap.keySet() : java.util.Set [16]\n" + + " 4 invokeinterface java.util.Set.iterator() : java.util.Iterator [22] [nargs: 1]\n" + + " 9 astore_3 [iter]\n" + + " 10 goto 38\n" + + " 13 aload_3 [iter]\n" + + " 14 invokeinterface java.util.Iterator.next() : java.lang.Object [28] [nargs: 1]\n" + + " 19 astore 4 [call]\n" + + " 21 aload_0 [this]\n" + + " 22 aload_1 [locksMap]\n" + + " 23 aload 4 [call]\n" + + " 25 invokevirtual java.util.HashMap.get(java.lang.Object) : java.lang.Object [34]\n" + + " 28 checkcast java.util.Collection [38]\n" + + " 31 aload 4 [call]\n" + + " 33 invokespecial X.externLocks(java.util.Collection, java.lang.Object) : java.util.List [40]\n" + + " 36 astore 5\n" + + " 38 aload_3 [iter]\n" + + " 39 invokeinterface java.util.Iterator.hasNext() : boolean [44] [nargs: 1]\n" + + " 44 ifne 13\n" + + " 47 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 13, line: 10]\n" + + " [pc: 21, line: 11]\n" + + " [pc: 38, line: 9]\n" + + " [pc: 47, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 48] local: this index: 0 type: X\n" + + " [pc: 0, pc: 48] local: locksMap index: 1 type: java.util.HashMap\n" + + " [pc: 0, pc: 48] local: key index: 2 type: java.lang.Object\n" + + " [pc: 10, pc: 47] local: iter index: 3 type: java.util.Iterator\n" + + " [pc: 21, pc: 38] local: call index: 4 type: java.lang.Object\n"; + + 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); + } +} +public void test1108() { + this.runConformTest( + new String[] { + "X.java", + "interface UnaryFunction {\n" + + " public R invoke(A o) throws X;\n" + + "}\n" + + " \n" + + "public class X implements UnaryFunction {\n" + + " public Void invoke(String o) throws RuntimeException {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591 +//?: cuts assignment context +public void test1109() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public Y foo()\n" + + " {\n" + + " return true ? Z.bar() : null;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}\n" + + "class Z {\n" + + " static Y bar() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return true ? Z.bar() : null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to Y\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591 +//variant +public void test1110() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public Y foo()\n" + + " {\n" + + " return true ? Z.bar() : null;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}\n" + + "class Z {\n" + + " static Y bar() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 +public void test1111() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo(Object o) {\n" + + " return (T) o; // should get unchecked warning\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " try {\n" + + " X s = a.foo(new Object());\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1112() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " A ua = a;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = a.foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1113() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1114() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = this.foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1115() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static X ROOT;\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " A ua = a;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = a.foo.ROOT;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1116() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "interface I {\n" + + " int CONST = 1;\n" + + "}\n" + + "\n" + + "class Z {\n" + + " T c;\n" + + " Z(T c) {\n" + + " this.c = c;\n" + + " }\n" + + " int foo() {\n" + + " return c.CONST;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X implements Serializable, I {\n" + + " public static void main(String argv[]) {\n" + + " Z z = new Z(new X());\n" + + " Z rawz = z;\n" + + " rawz.c = new Serializable(){};\n" + + " try {\n" + + " z.foo();\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1117() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Value CONST = null;\n" + + "}\n" + + "class Value {\n" + + " String NAME = \"VALUE\";\n" + + "}\n" + + "class B implements I {\n" + + " B(Value param) {\n" + + " Value v0 = CONST;\n" + + " Value v1 = this.CONST;\n" + + " String s2 = CONST.NAME;\n" + + " Value v3 = I.CONST;\n" + + " Value v4 = B.CONST;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new B(new Value());\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + false, + null, + options, + null); + // check the reference to I.CONST is generated as B.CONST, except for v3 still issuing I.CONST + String expectedOutput = + " // Method descriptor #8 (LValue;)V\n" + + " // Signature: (LValue;)V\n" + + " // Stack: 1, Locals: 2\n" + + " B(Value param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 getstatic B.CONST : Value [15]\n" + + " 7 pop\n" + + " 8 getstatic B.CONST : Value [15]\n" + + " 11 pop\n" + + " 12 getstatic B.CONST : Value [15]\n" + + " 15 getfield Value.NAME : java.lang.String [19]\n" + + " 18 pop\n" + + " 19 getstatic I.CONST : Value [25]\n" + + " 22 pop\n" + + " 23 getstatic B.CONST : Value [15]\n" + + " 26 pop\n" + + " 27 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 8, line: 10]\n" + + " [pc: 12, line: 11]\n" + + " [pc: 19, line: 12]\n" + + " [pc: 23, line: 13]\n" + + " [pc: 27, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 28] local: this index: 0 type: B\n" + + " [pc: 0, pc: 28] local: param index: 1 type: Value\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 28] local: this index: 0 type: B\n" + + " [pc: 0, pc: 28] local: param index: 1 type: Value\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715 +public void test1118() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " X() {\n" + + " Class> cls = null;\n" + + " foo(cls);\n" + + " }\n" + + "\n" + + " > T foo(Class pClass) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + // javac options + JavacTestOptions.EclipseHasABug.EclipseBug177715 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169728 +public void test1119() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X & Runnable> {\n" + + " T get() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X x1 = null; // error\n" + + " X x2 = null; // error\n" + + " X x3 = null; // ok\n" + + " X x4 = null; // ok\n" + + " \n" + + " foo1(x1); // ok\n" + + " foo1(x2); // ok\n" + + " foo1(x3); // ok\n" + + " foo1(x4); // ok\n" + + "\n" + + " foo2(x1); // error\n" + + " foo2(x2); // error\n" + + " foo2(x3); // error\n" + + " foo2(x4); // ok\n" + + " }\n" + + " \n" + + " static void foo1(X x) {\n" + + " x.get().run(); // ok\n" + + " x.get().compareTo(null); // ok\n" + + " x.get().compareTo(x.get()); // error\n" + + " }\n" + + " static void foo2(X x) {\n" + + " x.get().run(); // ok\n" + + " x.get().compareTo(null); // ok\n" + + " x.get().compareTo(x.get()); // error\n" + + " } \n" + + "}\n" + + "\n" + + "abstract class OnlyRunnable implements Runnable {}\n" + + "abstract class OnlyComparable implements Comparable {}\n" + + "abstract class ComparableRunnable implements Comparable, Runnable {}\n" + + "abstract class ComparableRunnableThrowable extends Throwable implements Comparable, Runnable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X x1 = null; // error\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type OnlyRunnable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X x2 = null; // error\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type OnlyComparable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " X x4 = null; // ok\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ComparableRunnableThrowable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " foo2(x1); // error\n" + + " ^^^^\n" + + "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "5. ERROR in X.java (at line 18)\n" + + " foo2(x2); // error\n" + + " ^^^^\n" + + "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "6. ERROR in X.java (at line 19)\n" + + " foo2(x3); // error\n" + + " ^^^^\n" + + "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "7. ERROR in X.java (at line 26)\n" + + " x.get().compareTo(x.get()); // error\n" + + " ^^^^^^^^^\n" + + "The method compareTo(capture#3-of ?) in the type Comparable is not applicable for the arguments (capture#4-of ?)\n" + + "----------\n" + + "8. ERROR in X.java (at line 31)\n" + + " x.get().compareTo(x.get()); // error\n" + + " ^^^^^^^^^\n" + + "The method compareTo(capture#7-of ? extends Throwable) in the type Comparable is not applicable for the arguments (capture#8-of ? extends Throwable)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166963 +public void test1120() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X() {\n" + + " System.out.println();\n" + + " this(zork);\n" + + " Zork.this.this();\n" + + " this();\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " this(zork);\n" + + " ^^^^^^^^^^^\n" + + "Constructor call must be the first statement in a constructor\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " this(zork);\n" + + " ^^^^\n" + + "zork cannot be resolved\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork.this.this();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Constructor call must be the first statement in a constructor\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork.this.this();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " this();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " this();\n" + + " ^^^^^^^\n" + + "Constructor call must be the first statement in a constructor\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 +public void test1121() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\r\n" + + " System.out.println(T[].class);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(T[].class);\n" + + " ^^^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 +public void test1122() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\r\n" + + " System.out.println(T[].class);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(T[].class);\n" + + " ^^^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 - variation +public void test1123() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Class c1 = int.class;\n" + + " Class c2 = Integer.class;\n" + + " Class c3 = int[].class;\n" + + " Class c4 = int[].class;\n" + + " Class c5 = void.class;\n" + + " Class c6 = void[].class;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Class c3 = int[].class;\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Class c6 = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Class c6 = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=182192 +public void test1124() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + "\n" + + " static protected final Map myMap = new HashMap();\n" + + " private final T theGenericThing;\n" + + "\n" + + " private X(T something) {\n" + + " this.theGenericThing = something;\n" + + " }\n" + + "\n" + + " public static class InnerClassThatShowsBug extends X {\n" + + " public InnerClassThatShowsBug() {\n" + + " super(null);\n" + + " }\n" + + "\n" + + " public void printMap() {\n" + + " for (Map.Entry entry : myMap().entrySet()) {\n" + + " System.out.println(entry.getKey() + \" => \" + entry.getValue());\n" + + " }\n" + + " }\n" + + " protected Map myMap2() {\n" + + " return myMap;\n" + + " }\n" + + " public void printMap2() {\n" + + " for (Map.Entry entry : myMap2().entrySet()) {\n" + + " System.out.println(entry.getKey() + \" => \" + entry.getValue());\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " protected Map myMap() {\n" + + " return myMap;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " private final T theGenericThing;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The field X.theGenericThing is never read locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " public static class InnerClassThatShowsBug extends X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " super(null);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " super(null);\n" + + " ^^^^^^^^^^^^\n" + + "Access to enclosing constructor X(T) is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " for (Map.Entry entry : myMap().entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to Map.Entry\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 +public void test1125() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " class B {\n" + + " T t;\n" + + " T getValue() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class C extends A {\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static C.B c = new C().new B();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " C.B temp = new C().new B();\n" + + " String s = temp.getValue();\n" + + " System.out.println(s);\n" + + " foo(bar());\n" + + " }\n" + + "\n" + + " static C.B bar() {\n" + + " return new C().new B();\n" + + " }\n" + + "\n" + + " static void foo(C.B arg) {\n" + + " Object o = arg.getValue();\n" + + " Double d = c.getValue();\n" + + " System.out.println(o);\n" + + " System.out.println(d);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " static C.B c = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " C.B temp = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 25)\n" + + " return new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation +public void test1126() { + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " class B {\n" + + " T t;\n" + + " T getValue() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static A.B c = new A().new B();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A.B temp = new A().new B();\n" + + " String s = temp.getValue();\n" + + " System.out.print(s);\n" + + " foo(bar());\n" + + " }\n" + + "\n" + + " static A.B bar() {\n" + + " return new A().new B();\n" + + " }\n" + + "\n" + + " static void foo(A.B arg) {\n" + + " Object o = arg.getValue();\n" + + " Double d = c.getValue();\n" + + " System.out.print(o);\n" + + " System.out.print(d);\n" + + " }\n" + + "}\n", // ================= + }, + "nullnullnull"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation +public void test1127() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " class B {\n" + + " T t;\n" + + " T getValue() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class C extends A {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static C.B c = new C().new B();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " C.B temp = new C().new B();\n" + + " String s = temp.getValue();\n" + + " System.out.println(s);\n" + + " foo(bar());\n" + + " }\n" + + "\n" + + " static C.B bar() {\n" + + " return new C().new B();\n" + + " }\n" + + "\n" + + " static void foo(C.B arg) {\n" + + " Object o = arg.getValue();\n" + + " Double d = c.getValue();\n" + + " System.out.println(o);\n" + + " System.out.println(d);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " static C.B c = new C().new B();\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " static C.B c = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " static C.B c = new C().new B();\n" + + " ^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " C.B temp = new C().new B();\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " C.B temp = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " C.B temp = new C().new B();\n" + + " ^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "7. ERROR in X.java (at line 23)\n" + + " static C.B bar() {\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "8. WARNING in X.java (at line 24)\n" + + " return new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "9. ERROR in X.java (at line 24)\n" + + " return new C().new B();\n" + + " ^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "10. ERROR in X.java (at line 27)\n" + + " static void foo(C.B arg) {\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation +public void test1128() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " class Member {}\n" + + "}\n" + + "\n" + + "public class X extends A {\n" + + " void foo() {\n" + + " new Member();\n" + + " new X().new Member();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public class X extends A {\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " new Member();\n" + + " ^^^^^^\n" + + "The member type A.Member must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().new Member();\n" + + " ^^^^^^\n" + + "The member type A.Member must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); +} +public void test1129() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "abstract class Arg1 implements Comparable, Serializable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "abstract class Arg2 implements Serializable, Comparable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "\n" + + "interface IX {}\n" + + "\n" + + "public class X {\n" + + " void foo1(boolean b, IX arg2) {\n" + + " IX o = b ? null : arg2;\n" + + " IX o2 = b ? arg2 : null;\n" + + " }\n" + + " void foo2(boolean b, IX arg1, IX arg2) {\n" + + " String s = b ? arg1 : arg2;\n" + + " }\n" + + " void foo3(boolean b, Arg1 arg1, Arg2 arg2) {\n" + + " String s = b ? arg1 : arg2;\n" + + " }\n" + + "} ", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from IX to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object&Comparable&Serializable to String\n" + + "----------\n"); +} +public void test1130() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "interface IX&Serializable> {}\n" + + "\n" + + "public class X&Serializable> {\n" + + " void foo4(boolean b, List l1, List> l2) {\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparable to String\n" + + "----------\n"); +} +public void test1131() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "public class X&Serializable> {\n" + + " void foo4(boolean b, List l1, List> l2) {\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " }\n" + + "} \n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparable to String\n" + + "----------\n"); +} +public void test1132() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public void thisDoesntCompile() {\n" + + " X myThing = new X();\n" + + " Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" + + " // myThing is unbounded, return\n" + + " // type List\n" + + " // incorrectly becomes unbounded\n" + + " }\n" + + "\n" + + " public List getList() {\n" + + " ArrayList l = new ArrayList();\n" + + " l.add(new Integer(0));\n" + + " return l;\n" + + " }\n" + + "\n" + + " public void thisMethodCompilesOk() {\n" + + " X myThing = new X();\n" + + " Integer i = myThing.getList().get(0);\n" + + " }\n" + + "\n" + + " public void thisMethodAlsoCompilesOk() {\n" + + " X myThing = new X();\n" + + " List l = myThing.getList();\n" + + " Integer i = l.get(0);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " X myThing = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 25)\n" + + " X myThing = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 26)\n" + + " List l = myThing.getList();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +public void test1133() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class Y {\n" + + " List foo() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " List bar() { return null; }\n" + + " \n" + + " void m(X x) {\n" + + " List l1 = x.foo();\n" + + " List l2 = x.bar();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " void m(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " List l1 = x.foo();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " List l2 = x.bar();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +public void test1134() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class Y {\n" + + " List foo() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " List bar() { return null; }\n" + + " \n" + + " void m(X x) {\n" + + " List l1 = x.foo();\n" + + " List l2 = x.bar();\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " void m(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " List l1 = x.foo();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " List l2 = x.bar();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 +public void test1135() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Foo {\n" + + " private T myT;\n" + + "\n" + + " public T getT() {\n" + + " return myT;\n" + + " }\n" + + "\n" + + " public void setT(T aT) {\n" + + " myT = aT;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Foo {\n" + + " X.Baz baz;\n" + + " public static void main(String[] args) {\n" + + " X myBar = new X();\n" + + " myBar.setT(new Baz());\n" + + " System.out.println(myBar.getT().toString());\n" + + " }\n" + + "\n" + + " private static class Baz {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Baz\";\n" + + " }\n" + + " } \n" + + "}\n", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "Baz" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug185422 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154029 +public void test1136() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List l1 = Arrays.asList(1, \"X\");\n" + + " \n" + + " B b = null;\n" + + " Cc = null;\n" + + " List l2 = Arrays.asList(b, c);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "interface I {}\n" + + "class B extends A implements I {}\n" + + "class C extends A implements I {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List l1 = Arrays.asList(1, \"X\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Object&Comparable&Serializable is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " List l1 = Arrays.asList(1, \"X\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List&Serializable> to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " List l2 = Arrays.asList(b, c);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of A&I is created for a varargs parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " List l2 = Arrays.asList(b, c);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List&I> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154267 +public void test1137() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.awt.Container;\n" + + "import java.util.Collection;\n" + + "\n" + + "abstract class Kollection implements Collection {}\n" + + "abstract class Kontainer extends Container {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " private Collection foo() {\n" + + " return null;\n" + + " }\n" + + " private Kollection bar() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void showProblem() {\n" + + " Collection result = foo();\n" + + " Collection result1 = foo();\n" + + " \n" + + " Collection result2 = (Collection)foo();\n" + + " String result3 = foo();\n" + + " String result4 = (String) foo(); \n" + + "\n" + + " Kollection result5 = bar();\n" + + " Kollection result6 = bar();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 21)\n" + + " Collection result2 = (Collection)foo();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Collection to Collection\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " String result3 = foo();\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from Collection to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " String result4 = (String) foo(); \n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from Collection to String\n" + + "----------\n"); +} +public void test1138() { + // binary prerequisite + this.runConformTest( + new String[] { + "p/E.java", + "package p;\n" + + "public enum E {\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "import static p.E.*;\n" + + "public class X implements java.io.Serializable {\n" + + "}\n", // ================= + }, + "", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186833 +public void test1139() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import p.X.Super;\n" + + "import static p.Top.*;\n" + + "\n" + + "class Top {\n" + + " static class A {}\n" + + "}\n" + + "\n" + + "public class X extends Super> {\n" + + " static class Super extends Top{\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 9)\r\n" + + " public class X extends Super> {\r\n" + + " ^^^^^\n" + + "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186788 +public void test1140() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.X.Super;\n" + + "import static p.Top.*;\n" + + "\n" + + "class Top {\n" + + " static class A {}\n" + + "}\n" + + "\n" + + "public class X extends Super> {\n" + + " class Super extends Top{\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\r\n" + + " import static p.X.Super;\r\n" + + " ^^^^^^^^^\n" + + "The import p.X.Super cannot be resolved\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 9)\r\n" + + " public class X extends Super> {\r\n" + + " ^^^^^\n" + + "Super cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186833 - variation +public void test1141() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.Top.*;\n" + + "\n" + + "class Top {\n" + + " static class A {}\n" + + "}\n" + + "\n" + + "public class X extends p.X.Super> {\n" + + " static class Super extends Top{\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 8)\r\n" + + " public class X extends p.X.Super> {\r\n" + + " ^^^^^^^^^\n" + + "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 +public void test1142() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static Comparator compound(Comparator a, Comparator b) {\n" + + " return compound(asList(a, b));\n" + + " }\n" + + "\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " return compound(asList(a, b));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6573446 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1143() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static Comparator compound(Comparator a, Comparator b) {\n" + + " int i = asList(a, b);\n" + + " }\n" + + "\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int i = asList(a, b);\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1144() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " Iterable> itc1;\n" + + " Iterable> itc2 = itc1;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Iterable> itc2 = itc1;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from Iterable> to Iterable>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1145() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Comparator compound(Comparator a, Comparator b) {\n" + + " return compound(asList(a));\n" + + " }\n" + + " Comparator compound(Iterable> c) {\n" + + " return null;\n" + + " }\n" + + " List asList(E a) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1146() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static Comparator compound(\n" + + " Comparator a,\n" + + " Comparator b, \n" + + " Comparator... rest) {\n" + + " int i = asList(a, b, rest);\n" + + " int j = asList2(a, b);\n" + + " return compound(asList(a, b, rest));\n" + + " }\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b, E... rest) {\n" + + " return null;\n" + + " }\n" + + " public static List asList2(E a, E b) {\n" + + " return null;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int i = asList(a, b, rest);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " int j = asList2(a, b);\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " return compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1147() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Comparator cx, Comparator[] cxs) {\n" + + " int i = cx;\n" + + " int j = cxs;\n" + + " int k = cxs[0];\n" + + " int l = asList2(cxs[0], cxs[1]);\n" + + " }\n" + + " public static List asList2(E a, E b) {\n" + + " return null;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int i = cx;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Comparator to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = cxs;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Comparator[] to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " int k = cxs[0];\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Comparator to int\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " int l = asList2(cxs[0], cxs[1]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1148() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static Comparator compound(Comparator a, Comparator b, Comparator... rest) {\n" + + " int i = asList(a, b, rest);\n" + + " int j = compound(asList(a, b, rest));\n" + + " compound(asList(a, b, rest));\n" + + " if (true) return compound(asList(a, b, rest));\n" + + " \n" + + " List> c = null;\n" + + " compound(c);\n" + + " return compound(c);\n" + + " }\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b, E... rest) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int i = asList(a, b, rest);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " if (true) return compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " return compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=198051 +public void test1149() { + String bSource = + "public class B {\n" + + " void b() throws ClassNotFoundException {\n" + + " new A();\n" + + " }\n" + + "}\n"; + runConformTest( + // test directory preparation + new String[] { /* test files */ + "A.java", + "public class A {\n" + + " A() throws T {}\n" + + " void a() throws ClassNotFoundException {\n" + + " new A();\n" + + " }\n" + + "}\n", + "B.java", + bSource + }, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug234815 /* javac test options */); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "B.java", + bSource + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug234815 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=234815 (invalid) +public void test1149b() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " void foo() throws T {}\n" + + " void a() throws ClassNotFoundException {\n" + + " new A().foo();\n" + + " }\n" + + "}\n", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 +public void test1150() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n"+ + "public class X {\n" + + " static class Rather {\n" + + " static class Deeply {\n" + + " static class Inside {\n" + + " }\n" + + " }\n" + + " }\n" + + " Reference x;\n" + + " Reference y; \n" + + " Reference z; \n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"x\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(X.class.getDeclaredField(\"y\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(X.class.getDeclaredField(\"z\").getGenericType());\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference" + ); + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference;\n" + + " java.lang.ref.Reference x;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference;\n" + + " java.lang.ref.Reference y;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference;\n" + + " java.lang.ref.Reference z;\n"; + + 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); + } + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1151() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n"+ + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " Reference.Other.Deeply> t;\n" + + " Reference.Other.Deeply.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + + " //System.out.print(\"##\");\n" + + " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + //"java.lang.ref.Reference.Other.Deeply>##java.lang.ref.Reference.Other.Deeply$Inside>" + "java.lang.ref.Reference.Other.Deeply>" + ); + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply;>;\n" + + " java.lang.ref.Reference t;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply.Inside;>;\n" + + " java.lang.ref.Reference u;\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1152() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n"+ + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " Reference.Other.Deeply.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Reference.Other.Deeply.Inside> u;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The member type X.Other.Deeply.Inside must be parameterized, since it is qualified with a parameterized type\n" + + "----------\n" ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1153() { + // check proper decoding of binary signatures, by compiling against generated binary + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.lang.ref.Reference;\n" + + "public class X {\n" + + " public static class Rather {\n" + + " public static class Deeply {\n" + + " public static class Inside {\n" + + " }\n" + + " }\n" + + " }\n" + + " public class Other {\n" + + " public class Deeply {\n" + + " public class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " public Reference x;\n" + + " public Reference y; \n" + + " public Reference z; \n" + + " public Reference.Other.Deeply> t;\n" + + " public Reference.Other.Deeply.Inside> u;\n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "Y.java", + "import java.lang.ref.Reference;\n" + + "import p.X;\n" + + "public class Y {\n" + + " Reference x;\n" + + " Reference y; \n" + + " Reference z; \n" + + " Reference.Other.Deeply> t;\n" + + " Reference.Other.Deeply.Inside> u;\n" + + " Y(X someX) {\n" + + " this.x = someX.x;\n" + + " this. y = someX.y; \n" + + " this.z = someX.z; \n" + + " this.t = someX.t;\n" + + " this.u = someX.u; \n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(Y.class.getDeclaredField(\"x\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(Y.class.getDeclaredField(\"y\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(Y.class.getDeclaredField(\"z\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(Y.class.getDeclaredField(\"t\").getGenericType());\n" + + " //System.out.print(\"##\");\n" + + " //System.out.print(Y.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference.Other.Deeply>", + null, + false, // do not flush output + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1154() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n" + + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Deeper {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " }\n" + + " Reference.Deeply> t;\n" + + " Reference.Deeply.Deeper.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " //System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " //System.out.print(\"##\");\n" + + " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + ""); + + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Deeply;>;\n" + + " java.lang.ref.Reference t;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Deeply.Deeper.Inside;>;\n" + + " java.lang.ref.Reference u;\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1155() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n" + + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Deeper {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " }\n" + + " Reference.Other.Deeply> t;\n" + + " Reference.Other.Deeply.Deeper.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + + " //System.out.print(\"##\");\n" + + " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "java.lang.ref.Reference.Other.Deeply>" ); + + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply;>;\n" + + " java.lang.ref.Reference t;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply.Deeper.Inside;>;\n" + + " java.lang.ref.Reference u;\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196253 +public void test1156() { + this.runConformTest( + new String[] { + "C.java", + "public class C {\n" + + " R>> xx = D.r;\n" + + "}", + "D.java", + "public class D {\n" + + " public static R>> r;\n" + + "}", + "R.java", + "public class R {}", + "X.java", + "public class X {\n" + + " public static class N {}\n" + + "}" + }, + "" + ); + this.runConformTest( + new String[] { + "C.java", + "public class C {\n" + + " R>> xx = D.r;\n" + + "}", + }, + "", + null, + false, // do not flush output + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202624 +public void test1157() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void func(Class> cls) {}\n" + + " public void func() {\n" + + " func(XX.class);\n" + + " \n" + + " Class> c = XX.class;\n" + + " }\n" + + " class XX {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " func(XX.class);\n" + + " ^^^^\n" + + "The method func(Class>) in the type X is not applicable for the arguments (Class)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Class> c = XX.class;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 +public void test1158() { + this.runNegativeTest( + new String[] { + "X.java", + " class A {}\n" + + " class B extends A {}\n" + + " class C extends A{}\n" + + " \n" + + " class D {}\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " D d1 = null;\n" + + " D d2 = null;\n" + + " D d3 = null;\n" + + " D d4 = null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " D d3 = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter of the type D\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1159() { + this.runConformTest( + new String[] { + "X.java", + "class Y> {}\n" + + "public class X> extends Y{\n" + + " void foo(X x) {}\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1160() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y> {}\n" + + "class Z> {}\n" + + "public class X> extends Z{\n" + + " void foo(X x) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " public class X> extends Z{\r\n" + + " ^\n" + + "Bound mismatch: The type V is not a valid substitute for the bounded parameter > of the type Z\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\r\n" + + " public class X> extends Z{\r\n" + + " ^\n" + + "Bound mismatch: The type V is not a valid substitute for the bounded parameter > of the type Z\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1161() { + this.runConformTest( + new String[] { + "X.java", + "class Y> {}\n" + + "class Z> extends Y {}\n" + + "public class X> extends Z {\n" + + " void foo(X x) {}\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1162() { + this.runConformTest( + new String[] { + "X.java", + "class Y> {}\n" + + "class Z> extends Y {}\n" + + "public class X> extends Z{\n" + + " void foo(Y y) {}\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203061 - variation +public void test1163() { + this.runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " private final Object mObj;\n" + + " private final Object mDependent = new Object() {\n" + + " {\n" + + " Object o1 = mObj;\n" + + " }\n" + + " Object o2 = mObj;\n" + + " void foo() {\n" + + " Object o3 = mObj;\n" + + " }\n" + + " };\n" + + " public X() {\n" + + " mObj = \"\";\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private final Object mDependent = new Object() {\n" + + " ^^^^^^^^^^\n" + + "The field X.mDependent is never read locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Object o2 = mObj;\n" + + " ^^\n" + + "The field new Object(){}.o2 is never read locally\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " Object o2 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " Object o2 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new Object(){} is never used locally\n" + + "----------\n" + + "8. WARNING in X.java (at line 9)\n" + + " Object o3 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203061 - variation +public void test1164() { + this.runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " private final Object mObj;\n" + + " private final Object mDependent = new Object() {\n" + + " {\n" + + " Object o1 = mObj;\n" + + " mObj = \"1\";\n" + + " }\n" + + " Object o2 = mObj = \"2\";\n" + + " void foo() {\n" + + " Object o3 = mObj;\n" + + " mObj = \"3\";\n" + + " }\n" + + " };\n" + + " public X() {\n" + + " mObj = \"\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private final Object mDependent = new Object() {\n" + + " ^^^^^^^^^^\n" + + "The field X.mDependent is never read locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " mObj = \"1\";\n" + + " ^^^^\n" + + "Write access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " mObj = \"1\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " Object o2 = mObj = \"2\";\n" + + " ^^\n" + + "The field new Object(){}.o2 is never read locally\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " Object o2 = mObj = \"2\";\n" + + " ^^^^\n" + + "Write access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "8. ERROR in X.java (at line 8)\n" + + " Object o2 = mObj = \"2\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + + "9. WARNING in X.java (at line 9)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new Object(){} is never used locally\n" + + "----------\n" + + "10. WARNING in X.java (at line 10)\n" + + " Object o3 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "11. WARNING in X.java (at line 11)\n" + + " mObj = \"3\";\n" + + " ^^^^\n" + + "Write access to enclosing field X.mObj is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n" + + "12. ERROR in X.java (at line 11)\n" + + " mObj = \"3\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1165() { + this.runNegativeTest( + new String[] { + "X.java", + " interface A {}\n" + + " class B implements A {}\n" + + " class C implements A{}\n" + + " \n" + + " class D {}\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " D d1 = null;\n" + + " D d2 = null;\n" + + " D d3 = null;\n" + + " D d4 = null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " D d3 = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter of the type D\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203318 +public void test1166() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; };\n" + + " void foo(X x) {\n" + + " x.get().intValue(); \n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179902 +public void test1167() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo> {\n" + + " class Bar {\n" + + " Bar(Foo bar) {}\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 +public void test1168() { + this.runNegativeTest( + new String[] { + "example/Container.java", + "package example;\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public interface Container> {\n" + + " > void f(\n" + + " Container a, \n" + + " Container b, \n" + + " Container c, \n" + + " Container d, \n" + + " Container e, \n" + + " Container> f, \n" + + " Container> g,\n" + + " Container> h);\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in example\\Container.java (at line 12)\n" + + " Container> f, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container\n" + + "----------\n" + + "2. ERROR in example\\Container.java (at line 13)\n" + + " Container> g,\n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation +public void test1169() { + this.runNegativeTest( + new String[] { + "example/Container2.java", + "package example;\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public interface Container2> {\n" + + " > void g(\n" + + " Container2 a, \n" + + " Container2 b, \n" + + " Container2 c, \n" + + " Container2 d, \n" + + " Container2 e, \n" + + " Container2> f, \n" + + " Container2> g, \n" + + " Container2 h);\n" + + "\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in example\\Container2.java (at line 12)\n" + + " Container2> f, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation +public void test1170() { + this.runNegativeTest( + new String[] { + "example/Container3.java", + "package example;\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public interface Container3> {\n" + + " > void g(\n" + + " Container3 a, \n" + + " Container3 b, \n" + + " Container3 c, \n" + + " Container3 d, \n" + + " Container3 e, \n" + + " Container3> f, \n" + + " Container3> g, \n" + + " Container3 h, \n" + + " Container3> i, \n" + + " Container3 j);\n" + + "\n" + + " > void h(\n" + + " Container3 a, \n" + + " Container3 b, \n" + + " Container3 c, \n" + + " Container3 d, \n" + + " Container3 e, \n" + + " Container3> f, \n" + + " Container3> g, \n" + + " Container3 h, \n" + + " Container3> i, \n" + + " Container3 j);\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in example\\Container3.java (at line 12)\n" + + " Container3> f, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "2. ERROR in example\\Container3.java (at line 13)\n" + + " Container3> g, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "3. ERROR in example\\Container3.java (at line 15)\n" + + " Container3> i, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "4. WARNING in example\\Container3.java (at line 16)\n" + + " Container3 j);\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "5. ERROR in example\\Container3.java (at line 16)\n" + + " Container3 j);\n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "6. ERROR in example\\Container3.java (at line 24)\n" + + " Container3> f, \n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "7. ERROR in example\\Container3.java (at line 25)\n" + + " Container3> g, \n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "8. ERROR in example\\Container3.java (at line 27)\n" + + " Container3> i, \n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "9. WARNING in example\\Container3.java (at line 28)\n" + + " Container3 j);\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "10. ERROR in example\\Container3.java (at line 28)\n" + + " Container3 j);\n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203905 +public void test1171() { + this.runConformTest( + new String[] { + "Function.java", + "public abstract class Function {\n" + + " public abstract B apply(A a);\n" + + "\n" + + " /** (f andThen g)(x) = g(f(x)) */\n" + + " public Function andThen(final Function g) {\n" + + " return new Function() {\n" + + " @Override\n" + + " public C1 apply(A a) {\n" + + " return g.apply(Function.this.apply(a));\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " /** (f compose g)(x) = f(g(x)) */\n" + + " public Function compose(final Function g) {\n" + + " return g.andThen(this);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +public void test1172() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X xs, X xn, boolean b) {\n" + + " (b ? xs : xn).field = xs.field;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? xs : xn).field = xs.field;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from String to capture#1-of ? extends Serializable\n" + + "----------\n"); +} +public void test1173() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).field = x1.field;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? x1 : x2).field = x1.field;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from Integer to capture#1-of ? extends Number&Comparable\n" + + "----------\n"); +} +public void test1174() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).field = (b ? x1 : x2).field;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? x1 : x2).field = (b ? x1 : x2).field;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? extends Number&Comparable to capture#1-of ? extends Number&Comparable\n" + + "----------\n"); +} +public void test1175() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).field = new C();\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "interface B {}\n" + + "class C extends A implements B {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? x1 : x2).field = new C();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from C to capture#3-of ? extends C\n" + + "----------\n"); +} +public void test1176() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void method(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).get().foo();\n" + + " (b ? x1 : x2).get().bar();\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " void foo() {/**/}\n" + + "}\n" + + "interface Bar {\n" + + " void bar();\n" + + "}\n" + + "abstract class C extends Foo implements Bar {/**/}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1177() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void method(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).get().foo();\n" + + " (b ? x1 : x2).get().bar();\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " void foo() {/**/}\n" + + "}\n" + + "interface Bar {\n" + + " void bar();\n" + + "}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1178() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void method(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).get().baz();\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " void foo() {/**/}\n" + + "}\n" + + "interface Bar {\n" + + " void bar();\n" + + "}\n" + + "abstract class C extends Foo implements Bar {\n" + + " void baz() {/**/}\n" + + "}\n" + + "abstract class D extends C {/**/}\n" + + "abstract class E extends C {/**/}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1179() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {}\n" + + "\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "The type V is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n"); +} +public void test1180() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static , R extends S & T> R max1(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static , S, R extends S & Comparable> R max2(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static , S, R extends Comparable> R max3(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max1(T arg1, S arg2) {\n" + + " ^\n" + + "Cannot specify any additional bound T when first bound is a type parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public static , S, R extends S & Comparable> R max2(T arg1, S arg2) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204534 +public void test1181() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static , S, R extends Comparable> R max(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " ^\n" + + "Cannot specify any additional bound T when first bound is a type parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Method max(T, S) has the same erasure max(Comparable, Object) as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Method max(T, S) has the same erasure max(Comparable, Object) as another method in type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "7. WARNING in X.java (at line 11)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 +public void test1182() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type Object is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation +public void test1183() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " t.run();\n" + + " }\n" + + " \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation +public void test1184() { + // check that unresolved first bound got erased into Object (and not Runnable) + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void foo(X x) {\n" + + " Runnable r = x.get();\n" + + " }\n" + + " \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Runnable r = x.get();\n" + + " ^^^\n" + + "The method get() from the type X refers to the missing type Zork\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203587 +public void test1185() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Class c) {};\n" + + " void foo(Class> c) {}\n" + + " void foo2(Class> c) {};\n" + + " void foo2(Class> c) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Class c) {};\n" + + " ^^^^^^^^^^^^^^^\n" + + "Method foo(Class) has the same erasure foo(Class) as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " void foo(Class c) {};\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " void foo(Class> c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Method foo(Class>) has the same erasure foo(Class) as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " void foo2(Class> c) {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method foo2(Class>) in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " void foo2(Class> c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method foo2(Class>) in type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1186() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo1(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " }\n" + + " void foo2(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1187() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " void foo3(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " } \n" + + " void foo4(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1188() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void foo(Integer i) {\n" + + " S a = (S) i; // error?\n" + + " }\n" + + " > void bar(Integer i) {\n" + + " U a = (U) i; // unchecked?\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " > void foo(Integer i) {\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 3)\n" + + " S a = (S) i; // error?\n" + + " ^^^^^\n" + + "Cannot cast from Integer to S\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " U a = (U) i; // unchecked?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Integer to U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1189() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void foo(Number n) {\n" + + " S a = (S) n; // unchecked?\n" + + " }\n" + + " > void bar(Number n) {\n" + + " U a = (U) n; // unchecked?\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " > void foo(Number n) {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " S a = (S) n; // unchecked?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Number to S\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " U a = (U) n; // unchecked?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Number to U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1190() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void foo2(Integer i) {\n" + + " S a = (S) i; // unchecked1?\n" + + " Comparable b = (Comparable) i; // unchecked2?\n" + + " } \n" + + " > void foo3(Integer i) {\n" + + " S a = (S) i; // error?\n" + + " Comparable b = (Comparable) i; // error3?\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " > void foo2(Integer i) {\n" + + " ^^^^^^^\n" + + "The type parameter U should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " S a = (S) i; // unchecked1?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Integer to S\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Comparable b = (Comparable) i; // unchecked2?\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Integer to Comparable\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " > void foo3(Integer i) {\n" + + " ^^^^^^\n" + + "The type parameter U should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " S a = (S) i; // error?\n" + + " ^^^^^\n" + + "Cannot cast from Integer to S\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Comparable b = (Comparable) i; // error3?\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Integer to Comparable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1191() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(SomeEnum en) {\n" + + " Enum myvar = en;\n" + + " SomeEnum en2 = (SomeEnum) myvar;\n" + + " if (myvar instanceof SomeEnum) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "enum SomeEnum {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165352 +public void test1192() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(ArrayList a) {\n" + + " Object o = (List) a; // ko\n" + + " }\n" + + " void bar(List a) {\n" + + " Object o = (ArrayList) a; // ko\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Object o = (List) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from ArrayList to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Object o = (List) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Object o = (ArrayList) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to ArrayList\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Object o = (ArrayList) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to ArrayList\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 - variation +public void test1193() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B extends A {}\n" + + "public class X {\n" + + " public void foo(X param) {\n" + + " X bar = (X) param; // unchecked warning vs error\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X bar = (X) param; // unchecked warning vs error\n" + + " ^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=120088 +public void test1194() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X t = new X();\n" + + " if (t.getClass() == Object.class)\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (t.getClass() == Object.class)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); +} +public void test1195() { + this.runConformTest( + new String[] { + "java/lang/Class.java", + "package java.lang;\n" + + "public class Class {\n" + + " Class getSuperclass() { return null; }\n" + + " void foo() {\n" + + " boolean foo = getSuperclass() == Enum.class;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +public void test1196() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " Class getSuperclass() { return null; }\n" + + " void foo() {\n" + + " boolean foo = getSuperclass() == Enum.class;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void bar() {\n" + + " boolean bar = this.getClass().getSuperclass() == Enum.class;\n" + + " } \n" + + "}\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1197() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " B b = new C();\n" + + " Class cb = C.class;\n" + + " YYY y = new XXX();\n" + + " Class> cy = XXX.class;\n" + + " YYY yb = new XXX();\n" + + " Class> ybc = XXX.class;\n" + + " Class ybb = yb.getClass();\n" + + " Class> ybb2 = yb.getClass();\n" + + " Class> ybb3 = yb.getClass();\n" + + " }\n" + + "}\n" + + "\n" + + "class Obj {}\n" + + "class B extends Obj {}\n" + + "class C extends B {}\n" + + "class ZZZ {}\n" + + "class YYY extends ZZZ {}\n" + + "class XXX extends YYY {} \n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class ybb = yb.getClass();\n" + + " ^^^\n" + + "YYY is a raw type. References to generic type YYY should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Class> ybb2 = yb.getClass();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Class> ybb3 = yb.getClass();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation +public void test1198() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {} \n" + + " static Object createParser(Listener l) {\n" + + " System.out.println(\"FAILED\");\n" + + " return null;\n" + + " }\n" + + " static Object createParser(L l) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class A implements Listener, ErrorListener {\n" + + " }\n" + + " createParser(new A()); // error here\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation +public void test1198a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {} \n" + + " static Object createParser(Listener l) {\n" + + " System.out.println(\"FAILED\");\n" + + " return null;\n" + + " }\n" + + " static Object createParser(L l) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class A implements Listener, ErrorListener {\n" + + " }\n" + + " createParser(new A()); // error here\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation +public void test1199() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {} \n" + + " static Object createParser(Listener l) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " static Object createParser(L l) {\n" + + " System.out.println(\"FAILED\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class A implements Listener {\n" + + " }\n" + + " createParser(new A()); // error here\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=205594 +public void test1200() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Map {\n" + + " }\n" + + "\n" + + " public Map make(K key, V value) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Map, X> method1() {\n" + + " X value = new X();\n" + + " Class type = X.class;\n" + + " return make(type, value);//1\n" + + " }\n" + + " public Map, X> method2() {\n" + + " X value = new X();\n" + + " Class type = X.class;\n" + + " return (Map, X>) make(type, value);//2\n" + + " }\n" + + " public Map, X> method3() {\n" + + " X value = new X();\n" + + " return make(X.class, value);//3\n" + + " }\n" + + " public Map, X> method4() {\n" + + " X value = new X();\n" + + " return (Map, X>) make(X.class, value);//4\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\r\n" + + " return make(type, value);//1\r\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Map,X> to X.Map,X>\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\r\n" + + " return (Map, X>) make(type, value);//2\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.Map,X> to X.Map,X>\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\r\n" + + " return make(X.class, value);//3\r\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Map,X> to X.Map,X>\n" + + "----------\n" + + "4. ERROR in X.java (at line 25)\r\n" + + " return (Map, X>) make(X.class, value);//4\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.Map,X> to X.Map,X>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174282 +public void test1201() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public MyClass f() {\n" + + " SuperClass val = null;\n" + + " return (MyClass) val;\n" + + " }\n" + + "}\n" + + "class MyClass extends SuperClass {\n" + + "}\n" + + "class MyDataModel extends SuperDataModel {\n" + + "}\n" + + "class SuperClass {\n" + + "}\n" + + "class SuperDataModel {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230 +public void test1202() { + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 + ? "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.foo();\n" + + " ^^^\n" + + "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^\n" + + "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + : "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X.foo();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo() {}\n" + + " public static void bar() {\n" + + " X.foo();\n" + + " X.foo();\n" + + " }\n" + + "}\n", // ================= + }, + expectedOutput); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230 - variation +// split because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +public void test1203a() { + String[] sources = + new String[] { + "X.java", + "public class X {\n" + + " public static String foo(String one, String two) {\n" + + " return X.foo(one, two);\n" + + " }\n" + + " public String bar(String one, String two) {\n" + + " return this.bar(one, two);\n" + + " }\n" + + "}\n", // ================= + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return X.foo(one, two);\n" + + " ^^^\n" + + "The method foo(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " return this.bar(one, two);\n" + + " ^^^\n" + + "The method bar(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + } else { + runConformTest( + true, + sources, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return X.foo(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return this.bar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method bar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +// this case is not solved as expected in 1.5 and 1.6 mode; keeping the 1.7 mode +// activated +public void test1203b() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + return; + } + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 + ? "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + + "----------\n" + : "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " @Override\n" + + " public String foobar(String one, String two) {\n" + + " return this.foobar(one, two);\n" + + " }\n" + + " @SuppressWarnings(\"unused\")\n" + + " public String foobar2(String one, String two) {\n" + + " return this.foobar2(one, two);// silenced\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public String foobar(String one, String two) {\n" + + " return null;\n" + + " }\n" + + " void test(String one, String two) {\n" + + " this.foobar(one, two);\n" + + " }\n" + + "}\n", // ================= + }, + expectedOutput); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 +public void test1204() { + this.runConformTest( + new String[] { + "ExpressionGraph.java", + "import java.util.*;\n" + + "public class ExpressionGraph, V extends IVertex> {\n" + + " void foo(Set set, Collection col) {\n" + + " if (set == col) return;\n" + + " }\n" + + "}\n" + + "interface IVertex, V extends IVertex> { \n" + + " // empty\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 - variation +public void test1205() { + this.runConformTest( + new String[] { + "ExpressionGraph.java", + "import java.util.*;\n" + + "\n" + + "public class ExpressionGraph, V extends ExpressionVertex, L> extends AbstractGraph {\n" + + " void foo(Set set, Collection col) {\n" + + " if (set == col) return;\n" + + " }\n" + + "\n" + + " interface IVertex, V extends IVertex, L> extends ExpressionVertex { \n" + + " // empty\n" + + " }\n" + + " static abstract class Vertex, V extends IVertex, L> /*extends TaggableVertex*/ implements IVertex { \n" + + " // empty\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class AbstractGraph, V extends Vertex> implements Graph {\n" + + " // empty\n" + + "}\n" + + "interface Graph, V extends Vertex> { \n" + + " // empty\n" + + "}\n" + + "interface Vertex, V extends Vertex> {\n" + + " // empty\n" + + "}\n" + + "interface ExpressionVertex, V extends ExpressionVertex, L> extends Vertex {\n" + + " // empty\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 +public void test1206() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE(E ex, Object... args) throws E {\n" + + " Object[] oar = new Object[0];\n" + + " return throwE(oar, ex, args);\n" + + " }\n" + + "\n" + + " public final E throwE(Object[] oar, E ex, Object... args) throws E {\n" + + " throw ex;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1207() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE (E ex) throws E {\n" + + " throw ex;\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " throwE(objs);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " throwE(objs);\r\n" + + " ^^^^^^\n" + + "Bound mismatch: The generic method throwE(E) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1208() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE2(E ex, Object... args) throws E {\n" + + " Object[] oar = new Object[0];\n" + + " return throwE(oar, ex, args);\n" + + " }\n" + + "\n" + + " public final E throwE(Object[] oar, E ex, Object... args) throws E {\n" + + " throw ex;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1209() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE (E ex, Object ... args) throws E {\n" + + " throw ex;\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " throwE(objs);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " throwE(objs);\r\n" + + " ^^^^^^\n" + + "Bound mismatch: The generic method throwE(E, Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1210() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE (Object ... args) throws E {\n" + + " return null;\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " Object[] o = throwE(objs);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Object[] o = throwE(objs);\n" + + " ^^^^^^\n" + + "Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208030 +public void test1211() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " Zork z;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " new Local(){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " new Local();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor Local() of type Local is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " new Local(){};\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor Local() of type Local is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " Zork z;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " new Local(){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " new Local();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " new Local(){};\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// generic variants +public void test1212() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X implements I {}\n" + + "class Y extends X implements I, J {}\n" + + "class Z {}" + + "interface I {}\n" + + "interface J {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements I, J {}\n" + + " ^\n" + + "Redundant superinterface I for the type Y, already defined by X\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP /* skip javac tests - configured eclipse specific warning as error */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// generic variants - the 'different arguments' error overrides the +// redundant error +public void test1213() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "class Y extends X implements I, J {}\n" + + "class Z {}" + + "interface I {}\n" + + "interface J {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements I, J {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 +public void test1214() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public interface Loader {\n" + + " public T load(final K key);\n" + + " }\n" + + " Loader loader;\n" + + " public T get(final K key) {\n" + + " T data = this.loader.load(key);\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBug5042462 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation +public void test1215() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " return (z? x1: x2);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBug5042462 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 +public void test1216() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " private class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\A.java (at line 18)\n" + + " this.box.set(new P());\n" + + " ^^^^^^^\n" + + "Access to enclosing constructor A.P() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation +public void test1217() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " protected class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation +public void test1218() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209779 +public void test1219() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final List stringList = new ArrayList();\n" + + " stringList.add(\"test1\");\n" + + " stringList.add(\"test2\");\n" + + " ((List) stringList).add(new Integer(1000));\n" + + " try {\n" + + " Object o = stringList.get(2);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException1]\");\n" + + " }\n" + + " try {\n" + + " String s = stringList.get(2);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException2]\");\n" + + " } \n" + + " try {\n" + + " for (Object obj : stringList) {\n" + + " System.out.print(obj);\n" + + " }\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException3]\");\n" + + " } \n" + + " try {\n" + + " for (String str : stringList) {\n" + + " System.out.print(str);\n" + + " }\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException4]\");\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "[ClassCastException2]test1test21000test1test2[ClassCastException4]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6500701 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209152 +public void test1220() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void doIt(List list) {\n" + + " list.add(list.remove(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " list.add(list.remove(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ?) in the type List is not applicable for the arguments (capture#2-of ?)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209071 +public void test1221() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo() {\n" + + " Set listSet = new HashSet();\n" + + " Set otherListSet = new HashSet();\n" + + " otherListSet.add((List) listSet); \n" + + " }\n" + + " void bar() {\n" + + " Set stringSet = new HashSet();\n" + + " Set otherStringSet = new HashSet();\n" + + " otherStringSet.add((String) stringSet); \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " new X().bar();\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Set listSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Set listSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Set otherListSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " Set otherListSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " otherListSet.add((List) listSet); \n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " otherStringSet.add((String) stringSet); \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Set to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207959 +public void test1222() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void foo2(X x2) {\n" + + " Runnable r = x2.get();\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=211718 +public void test1223() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static enum IsABug {\n" + + " TRUE,\n" + + " FALSE;\n" + + " } \n" + + " public List getPossibleBugStates() {\n" + + " String s1 = IsABug.values();\n" + + " String s2 = IsABug.valueOf(s1);\n" + + " return Arrays.asList(IsABug.values());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s1 = IsABug.values();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.IsABug[] to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " String s2 = IsABug.valueOf(s1);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.IsABug to String\n" + + "----------\n"); +} +public void test1224() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "public class X {\n" + + " class Request,V> {}\n" + + " class RequestMap {\n" + + " public ,W> R intersection (Collection c) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " class DeltaRequest extends Request {}\n" + + " public void test () {\n" + + " RequestMap m = new RequestMap ();\n" + + " Collection c = Collections.singleton (new DeltaRequest ());\n" + + " DeltaRequest o = m.intersection (c);\n" + + " }\n" + + "}\n" + }, + ""); +} +public void test1225() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " static void m(List list, Collection coll) {\n" + + " m(list, coll);\n" + + " }\n" + + "}\n" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test1226() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class M {\n" + + " X foo() { return null; }\n" + + " }\n" + + " void bar(M m) {\n" + + " X xt = m.foo();\n" + // no unchecked warning + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\r\n" + + " Zork z;\r\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1227() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " void foo() {\n" + + " Arrays.asList(String.class, Integer.class);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Arrays.asList(String.class, Integer.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Class> is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 +public void test1228() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); + // check $new$ method generic signature + String expectedOutput = + " // Method descriptor #22 ()LX$Binner$BinnerInner;\n" + + " // Signature: ()LX.Binner.BinnerInner;\n" + + " // Stack: 3, Locals: 1\n" + + " public X.Binner.BinnerInner $new$();\n" + + " 0 new X$Binner$BinnerInner [1]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 getfield X$Binner$BinnerInner.this$1 : X.Binner [10]\n" + + " 8 invokespecial X$Binner$BinnerInner(X$Binner) [25]\n" + + " 11 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X.Binner.BinnerInner\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X.Binner.BinnerInner\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X$Binner$BinnerInner.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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation +public void test1229() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " X root() {\n" + + " return X.this;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " String s = binString.$new$().root();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^\n" + + "The type parameter U should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in Z.java (at line 4)\n" + + " String s = binString.$new$().root();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation +public void test1230() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " X root() {\n" + + " return X.this;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " String s = binString.$new$().root();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in Z.java (at line 4)\n" + + " String s = binString.$new$().root();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation +public void test1231() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " X root() {\n" + + " return X.this;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " X.Binner.BinnerInner binNumber = binString.$new$();\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 +public void test1232() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + "}\n", + }, + ""); + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1233() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1234() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " void a3(G x) {} \n" + + " > void a3(T x) {}\n" + + "\n" + + " public static void ambiguousCases() { \n" + + " H hx = null;\n" + + " H hraw = null;\n" + + " new X().a3(hx);\n" + + " new X().a3(hraw);\n" + + " } \n" + + "}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void a3(G x) {} \n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().a3(hx);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " new X().a3(hraw);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1235() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " > void a3(T x) {}\n" + + " > void a3(T x) {}\n" + + "\n" + + " public static void ambiguousCases() { \n" + + " H hx = null;\n" + + " H hraw = null;\n" + + " new X().a3(hx);\n" + + " new X().a3(hraw);\n" + + " } \n" + + "}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1236() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1237() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method and(X.SuperInterface) belongs to the raw type X.OtherSubInterface. References to generic type X.OtherSubInterface should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.OtherSubInterface to X.SubInterface\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "X.OtherSubInterface is a raw type. References to generic type X.OtherSubInterface should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1238() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.OtherSubInterface to X.SubInterface\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1239() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + + " \n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^\n" + + "The method and(X.SuperInterface) is ambiguous for the type X.CombinedSubInterface\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public SubInterface and(SuperInterface s);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with X.OtherSubInterface.and(X.SuperInterface), X.SubInterface.and(X.SuperInterface)\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1240() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + " public interface OtherSubInterface extends SubInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + " public interface CombinedSubInterface extends OtherSubInterface {}\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1241() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + + " CombinedSubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public CombinedSubInterface and(SuperInterface a);\n" + + " }\n" + + " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=164665 +public void test1242() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.LinkedList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public void testCase() {\n" + + " TypedCollection collection = TypedCollectionFactory.createTypedCollection(SubTypeClass.class);\n" + + " collection.add(new SubTypeClass());\n" + + " List list = collection.list();\n" + + " assert (list.size() > 0);\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class SuperTypeAbstractClass {\n" + + "}\n" + + "\n" + + "class SubTypeClass extends SuperTypeAbstractClass {\n" + + "}\n" + + "\n" + + "interface TypedCollection {\n" + + " TypedCollection add(T object);\n" + + " List list();\n" + + "}\n" + + "\n" + + "class TypedCollectionFactory {\n" + + " public static TypedCollection createTypedCollection(Class c) {\n" + + " return new TypedCollectionImpl();\n" + + " }\n" + + "}\n" + + "\n" + + "class TypedCollectionImpl implements TypedCollection {\n" + + " private List list = new LinkedList();\n" + + " public TypedCollection add(T object) {\n" + + " list.add(object);\n" + + " return (this);\n" + + " }\n" + + " public List list() {\n" + + " return list;\n" + + " }\n" + + "}\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 +public void test1243() { + this.runConformTest( + new String[] { + "eclipse/modifier/impl/EclipseModifierBug.java", + "package eclipse.modifier.impl;\n" + + "import eclipse.modifier.Pool;\n" + + "public class EclipseModifierBug {\n" + + " static class MyEntry extends Pool.AbstractEntry { } \n" + + " static final Pool pool=new Pool() {\n" + + " @Override\n" + + " protected MyEntry delegate() {\n" + + " return new MyEntry();\n" + + " } \n" + + " };\n" + + " public static void main(String[] args) {\n" + + " MyEntry entry=pool.m(); \n" + + " }\n" + + "}", // ================= + "eclipse/modifier/Pool.java", + "package eclipse.modifier;\n" + + "public abstract class Pool> {\n" + + " static abstract class Entry> {\n" + + " E next;\n" + + " }\n" + + " static public class AbstractEntry> extends Entry {\n" + + " }\n" + + " public E m() {\n" + + " return delegate();\n" + + " }\n" + + " protected abstract E delegate();\n" + + " }\n" + + "\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation +public void test1244() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static class MyEntry extends Pool.AbstractEntry { } \n" + + " static final Pool pool=new Pool() {\n" + + " @Override\n" + + " protected MyEntry delegate() {\n" + + " return new MyEntry();\n" + + " } \n" + + " };\n" + + " public static void main(String[] args) {\n" + + " MyEntry entry=pool.m();\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Pool> {\n" + + " private static abstract class Entry> {\n" + + " E next;\n" + + " }\n" + + " static public class AbstractEntry> extends Entry {\n" + + " }\n" + + " public E m() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return delegate();\n" + + " }\n" + + " protected abstract E delegate();\n" + + "}\n", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug185422 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation +public void test1245() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + + "class Secondary {\n" + + " static private class Private {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The type Secondary.Private is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation +public void test1246() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static private class Private {}\n" + + " void foo(U u) {}\n" + + "}\n", // ================= + }, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug185422 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 +public void test1247() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void test() {\n" + + " Foo foo = null;\n" + + " eval(foo); // fails\n" + + " X.> eval(foo);\n" + + " }\n" + + "\n" + + " public static > void eval(T x) {\n" + + " }\n" + + " public static interface Foo extends Iterable> {\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " eval(foo); // fails\n" + + " ^^^^\n" + + "Bound mismatch: The generic method eval(T) of type X is not applicable for the arguments (X.Foo). The inferred type X.Foo is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 - variation +public void test1248() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "\n" + + " public static void test() {\n" + + " Foo foo = null;\n" + + " eval(foo); // fails\n" + + " X.> eval(foo);\n" + + " }\n" + + "\n" + + " public static > void eval(T x) {\n" + + " }\n" + + " public static interface Foo extends Iterable> {\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.EclipseHasABug.EclipseBug216558 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 - variation +public void test1249() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void test() {\n" + + " Foo foo = null;\n" + + " eval(foo, foo);\n" + + " X.> eval(foo, foo);\n" + + " }\n" + + " public static > void eval(T t1, T t2) {\n" + + " }\n" + + " public static interface Foo extends Iterable> {\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 +public void test1250() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1251() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static T asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static Sub LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216608 +public void test1252() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public B getB() {\n" + + " return new B();\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void test() {\n" + + " C c = getB().getC();\n" + + " String s = getB().toString();\n" + + " }\n" + + "}\n" + + "class B {\n" + + " public C getC() {\n" + + " return new C();\n" + + " }\n" + + "}\n" + + "class C {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\r\n" + + " Zork z;\r\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\r\n" + + " C c = getB().getC();\r\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type C needs unchecked conversion to conform to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216608 - variation +public void test1253() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public B getB() {\n" + + " return new B();\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void test() {\n" + + " C c = getB().getC();\n" + + " String s = getB().toString();\n" + + " }\n" + + "}\n" + + "class B {\n" + + " public C getC() {\n" + + " return new C();\n" + + " }\n" + + "}\n" + + "class C {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\r\n" + + " Zork z;\r\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1254() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1255() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static XList asList(T x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub ARRAY = new Sub() { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " static Sub ARRAY = new Sub() { };\n" + + " ^^^\n" + + "X.Foo.Sub is a raw type. References to generic type X.Foo.Sub should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1256() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1257() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1258() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1259() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1260() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1261() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\r\n" + + " static XList> LIST = asList(ARRAY); \r\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\r\n" + + " static Sub[] ARRAY = new Sub[] { };\r\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1262() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\r\n" + + " static XList> LIST = asList(ARRAY); \r\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1263() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1264() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static X.Foo.Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1265() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1266() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static Foo.Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216705 +public void test1267() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static interface Foo {\n" + + " }\n" + + " static interface SubFoo extends Foo {\n" + + " }\n" + + " static abstract class AbstractTest {\n" + + " protected static class Bar {\n" + + " }\n" + + " protected abstract List> get();\n" + + " }\n" + + " static class Test extends AbstractTest {\n" + + " @Override\n" + + " protected List> get() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216692 +public void test1268() { + this.runConformTest( + new String[] { + "pkg1/Foo.java", + "package pkg1;\n" + + "import java.util.Map;\n" + + "public class Foo {\n" + + " protected final Map fields = null;\n" + + " protected static class Field { }\n" + + "}\n", + "pkg2/SubFoo.java", + "package pkg2;\n" + + "import pkg1.Foo;\n" + + "public class SubFoo extends Foo {\n" + + " private Field field = null;\n" + + " private void test() {\n" + + " Field field = fields.get(\"test\");\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 +public void test1269() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1270() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#2#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1271() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^\n" + + "The method put(Class, X.TO) in the type X is not applicable for the arguments (Class, X.OO)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1272() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.print(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " put(Integer.class, (TO)combine(FUNC2, FUNC1));\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"#CLASSCAST#\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "#3##CLASSCAST#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1273() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1274() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1275() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1276() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1277() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#2#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1278() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1279() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1280() { + this.runConformTest( + new String[] { + "X.java", + "interface OO {}\n" + + "interface TO extends OO {}\n" + + "interface TT extends TO {}\n" + + "\n" + + "public class X {\n" + + " TO combine(final TO x, final OO y) { return null; }\n" + + " void foo(TT tt, TO too) {\n" + + " combine(tt, too);\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1281() { + this.runConformTest( + new String[] { + "X.java", + "interface OO {}\n" + + "interface TO extends OO {}\n" + + "interface TT extends TO {}\n" + + "\n" + + "public class X {\n" + + " TO combine(final TO x, final OO[] y) { return null; }\n" + + " void foo(TT tt, TO[] too) {\n" + + " combine(tt, too);\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1282() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface OO {}\n" + + " static interface TO extends OO {}\n" + + " static interface TT extends TO {}\n" + + " \n" + + " TO combine(TT x, TO y) { return null; }\n" + + " void foo(TO too, OO oo) {\n" + + " combine(too, oo);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\r\n" + + " combine(too, oo);\r\n" + + " ^^^^^^^\n" + + "The method combine(X.TT, X.TO) in the type X is not applicable for the arguments (X.TO, X.OO)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1283() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface OO {}\n" + + " static interface TO extends OO {}\n" + + " static interface TT extends TO {}\n" + + " \n" + + " TO combine(TT[] x, TO[] y) { return null; }\n" + + " void foo(TO[] too, OO[] oo) {\n" + + " combine(too, oo);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\r\n" + + " combine(too, oo);\r\n" + + " ^^^^^^^\n" + + "The method combine(X.TT[], X.TO[]) in the type X is not applicable for the arguments (X.TO[], X.OO[])\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 +public void test1284() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + "}\n" + + "interface I2 extends I1 {\n" + + " U get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1 to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1285() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup();\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + "}\n" + + "interface I2 extends I1 {\n" + + " U get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " y.foo(z2).get().getThreadGroup();\n" + + " ^^^\n" + + "The method foo(I1) in the type Y is not applicable for the arguments (Z)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1286() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1 {\n" + + " U get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1 to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1287() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1 {\n" + + " G get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1 to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1288() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1> i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1> {\n" + + " G get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1> to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1289() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1> i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1> {\n" + + " G get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " ^^^\n" + + "The method foo(I1>) in the type Y is not applicable for the arguments (Z)\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " ^^^\n" + + "The method foo(I1>) in the type Y is not applicable for the arguments (Z)\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from I1> to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1290() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " K foo(I i) {\n" + + " return (K) i;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "interface I {\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "interface K extends J {\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 +public void test1291() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static List moreGeneric(List list) {\n" + + " List result = new ArrayList();\n" + + " result.addAll( list );\n" + + " return result;\n" + + " }\n" + + " class A {}\n" + + " class B extends A {}\n" + + " class C extends B {}\n" + + " public static void main( String[] args ) {\n" + + " List b = new ArrayList();\n" + + " List a = moreGeneric(b);\n" + + " List c = moreGeneric(b);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " List c = moreGeneric(b);\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The generic method moreGeneric(List) of type X is not applicable for the arguments (List). The inferred type X.B is not a valid substitute for the bounded parameter \n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug218677); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 - variation +public void test1292() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static List moreSpecific(List list) {\n" + + " List result = new ArrayList();\n" + + " result.addAll( (List)list );\n" + + " return result;\n" + + " }\n" + + " class A {}\n" + + " class B extends A {}\n" + + " class C extends B {}\n" + + " public static void main( String[] args ) {\n" + + " List b = new ArrayList();\n" + + " List a = moreSpecific(b);\n" + + " List c = moreSpecific(b);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " result.addAll( (List)list );\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " List a = moreSpecific(b);\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method moreSpecific(List) of type X is not applicable for the arguments (List). The inferred type X.A is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 +public void test1293() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Table {\n" + + " State s;\n" + + " Table() {\n" + + " this.s = new State();\n" + + " }\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1294() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " State s;\n" + + " Table() {\n" + + " this.s = new State();\n" + + " }\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation +public void test1295() { + this.runNegativeTest( + new String[] { + "X.java", + "class Deejay {\n" + + " class Counter {}\n" + + "\n" + + " Deejay.Counter songCounter = new Deejay.Counter();\n" + + " Deejay.Counter genreCounter = new Deejay.Counter();\n" + + "\n" + + " java.util.List> list1 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + " java.util.List> list2 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + " java.util.List> list3 = java.util.Arrays.>asList(songCounter, genreCounter);\n" + + " java.util.List> list4 = java.util.Arrays.asList(new Deejay.Counter[] {songCounter, genreCounter});\n" + + " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + "}\n" + + "class Genre {}\n" + + "class Song {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\r\n" + + " java.util.List> list1 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\r\n" + + " java.util.List> list2 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\r\n" + + " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Deejay.Counter is created for a varargs parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\r\n" + + " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1296() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Table {\n" + + " Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new Table.State();\n" + + " }\n" + + "\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1297() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Table {\n" + + " X.Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new X().new Table().new State();\n" + + " }\n" + + "\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1298() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " X.Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new X.Table().new State();\n" + + " }\n" + + "\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 +public void test1299() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " X.Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new X.Table.State();\n" + + " }\n" + + "\n" + + " static class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation +public void test1300() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new State();\n" + + " }\n" + + "\n" + + " static class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation +public void test1301() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new Table.State();\n" + + " }\n" + + "\n" + + " static class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation +public void test1302() { + runConformTest( + true, + new String[] { + "EMap.java", + "import java.util.ArrayList;\n" + + "import java.util.Map;\n" + + "\n" + + "public abstract class EMap implements Map {\n" + + " public abstract static class Unsettable extends EMap {\n" + + " protected class UnsettableEList> extends EList {\n" + + " }\n" + + " }\n" + + " protected class EList> extends ArrayList{\n" + + " }\n" + + "}\n", // ================= + }, + null, + "", + null, + JavacTestOptions.EclipseHasABug.EclipseBug159851); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 +public void test1303() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Foo {\n" + + " T getValue();\n" + + " void doSomething(T o);\n" + + " }\n" + + " public static abstract class AbstractFoo implements Foo {\n" + + " /**\n" + + " * If this is removed ConcreteFoo no longer compiles.\n" + + " */\n" + + " public void doSomething(final String o) {\n" + + " }\n" + + " }\n" + + " public static final class ConcreteFoo extends AbstractFoo {\n" + + " public String getValue() {\n" + + " return \"I am a string\";\n" + + " }\n" + + " }\n" + + " /**\n" + + " * We lose the type infomation here so try but fail to call the doSomething(Object) method.\n" + + " */\n" + + " private static void feedFoosValueIntoFoo(final Foo foo) {\n" + + " foo.doSomething(foo.getValue());\n" + + " }\n" + + " private static void testTypedString() {\n" + + " final ConcreteFoo foo = new ConcreteFoo();\n" + + " foo.doSomething(foo.getValue());\n" + + " }\n" + + " private static void testGenericString() {\n" + + " feedFoosValueIntoFoo(new ConcreteFoo());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " testTypedString();\n" + + " testGenericString();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 - variation +public void test1304() { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " T get();\n" + + " void doSomething(T t);\n" + + "}\n" + + "abstract class XSuper implements Foo {\n" + + " public void doSomething(String s) { System.out.println(s); }\n" + + "}\n" + + "public class X extends XSuper {\n" + + " public String get() { return \"SUCCESS\"; }\n" + + " static void doIt(Foo f) {\n" + + " f.doSomething(f.get());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " doIt(new X());\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223334 +public void test1305() { + this.runConformTest( + new String[] { + "bug/ConflictManager.java",// ================= + "package bug;\n" + + "import java.util.*;\n" + + "public class ConflictManager {\n" + + " public List>> getConflictsSortedBySize() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "bug/LayoutOrganizable.java",// ================= + "package bug;\n" + + "public class LayoutOrganizable {\n" + + " private T t;\n" + + "\n" + + " public LayoutOrganizable(T t) {\n" + + " this.t = t;\n" + + "\n" + + " }\n" + + "}\n", + "bug/LayoutOrganizer.java", + "package bug;\n" + + "import java.util.*;\n" + + "public class LayoutOrganizer {\n" + + " ConflictManager> conflictManager = new ConflictManager>();\n" + + " private boolean optimizeEqual() {\n" + + " List>>> list;\n" + + " ListIterator>>> i;\n" + + " // create sorted list of pairs\n" + + " // (#conflicts, list of LayoutOrganizable sharing this #conflicts)\n" + + " // Here is the problem...\n" + + " list = conflictManager.getConflictsSortedBySize();\n" + + " return null == list;\n" + + " }\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "bug/LayoutOrganizer.java", + "package bug;\n" + + "import java.util.*;\n" + + "public class LayoutOrganizer {\n" + + " ConflictManager> conflictManager = new ConflictManager>();\n" + + " private boolean optimizeEqual() {\n" + + " List>>> list;\n" + + " ListIterator>>> i;\n" + + " // create sorted list of pairs\n" + + " // (#conflicts, list of LayoutOrganizable sharing this #conflicts)\n" + + " // Here is the problem...\n" + + " list = conflictManager.getConflictsSortedBySize();\n" + + " return null == list;\n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test1306() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.lang.reflect.Constructor;\n" + + "import java.lang.annotation.Documented;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " Constructor c = null;\n" + + " Documented d = c.getAnnotation(Documented.class);\n" + + "}\n", // ================= + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 6)\n" + + " Constructor c = null;\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Documented d = c.getAnnotation(Documented.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Documented d = c.getAnnotation(Documented.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to Documented\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test1307() { + this.runNegativeTest( + new String[] { + "Y.java", + "import java.util.List;\n" + + "public class Y {\n" + + " Zork z;\n" + + " Y itself() { return this; }\n" + + " List list() { return null; }\n" + + " Y someY() { return null; }\n" + + "}\n" + + "class Z {\n" + + " void foo(Y y) {\n" + + " Z z = y.itself(); // Y cannot be converted to Z (itself() return type got erased)\n" + + " List l = y.list(); // unchecked conversion from List to List\n" + + " Y ys = y.someY(); // unchecked conversion from Y to Y\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in Y.java (at line 9)\n" + + " void foo(Y y) {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in Y.java (at line 10)\n" + + " Z z = y.itself(); // Y cannot be converted to Z (itself() return type got erased)\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to Z\n" + + "----------\n" + + "4. WARNING in Y.java (at line 11)\n" + + " List l = y.list(); // unchecked conversion from List to List\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in Y.java (at line 12)\n" + + " Y ys = y.someY(); // unchecked conversion from Y to Y\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test1308() { + this.runNegativeTest( + new String[] { + "Y.java", + "@interface MyAnnotation {\n" + + "}\n" + + "class MyAccessibleObject {\n" + + " Object getAnnotation(Class c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class MyConstructor extends MyAccessibleObject {\n" + + " T getAnnotation(Class c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class X {\n" + + " void bar1(java.lang.reflect.Constructor constr, Class ann) {\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + + " }\n" + + " void bar2(MyConstructor constr, Class ann) {\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in Y.java (at line 9)\n" + + " T getAnnotation(Class c) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method getAnnotation(Class) of type MyConstructor should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. WARNING in Y.java (at line 14)\n" + + " void bar1(java.lang.reflect.Constructor constr, Class ann) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. WARNING in Y.java (at line 15)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "4. ERROR in Y.java (at line 15)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n" + + "5. WARNING in Y.java (at line 17)\n" + + " void bar2(MyConstructor constr, Class ann) {\n" + + " ^^^^^^^^^^^^^\n" + + "MyConstructor is a raw type. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "6. WARNING in Y.java (at line 18)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type MyConstructor. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "7. ERROR in Y.java (at line 18)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=226145 +public void test1309() { + this.runNegativeTest( + new String[] { + "EclipseGenericBug.java", + "public class EclipseGenericBug {\n" + + " static class ParametricClass {\n" + + " static interface NonParametricInterface {\n" + + " static interface ParametricInterface {\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " static class ParametricInstance extends ParametricClass {\n" + + " NonParametricInterface.ParametricInterface instance = null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=224855 +public void test1310() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Set;\n" + + "public class X {\n" + + " public void testCast(){\n" + + " Set classes = (Set)getClasses();\n" + + " }\n" + + " public Set> getClasses() {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Set classes = (Set)getClasses();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Set classes = (Set)getClasses();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Set> to Set\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Set classes = (Set)getClasses();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209149 +public void test1311() { + String[] test = new String[] { + "X.java", + "class X {}\n" + + "class Y {}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + test, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y {}\n" + + " ^\n" + + "Illegal forward reference to type parameter D\n" + + "----------\n"); + } else { + this.runConformTest(test, ""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=226535 +public void test1312() { + this.runConformTest( + new String[] { + "X.java", + " class Tuple3f> {\n" + + " private float x, y, z;\n" + + " float getX() { return this.x; }\n" + + " float getY() { return this.y; }\n" + + " float getZ() { return this.z; }\n" + + " void set(float newX, float newY, float newZ) {\n" + + " this.x = newX;\n" + + " this.y = newY;\n" + + " this.z = newZ;\n" + + " }\n" + + " public T add(Tuple3f t) {\n" + + " this.set(this.getX() + t.getX(), this.getY() + t.getY(), this.getZ() + t.getZ());\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T result = (T) this;\n" + + " return result;\n" + + " }\n" + + "}\n" + + "\n" + + "class Vector3f extends Tuple3f {\n" + + " float magnitude () {\n" + + " float x = this.getX(), y = this.getY(), z = this.getZ();\n" + + " return (float) Math.sqrt((x*x) + (y*y) + (z*z));\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Vector3f v = new Vector3f();\n" + + " float magn = v.add(v).add(v).magnitude();\n" + + " System.out.println((int)magn);\n" + + " }\n" + + "}\n", // ================= + }, + "0"); +} +public void test1313() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List[] l1 = new List[1];\n" + + " List[] l2 = new List[2];\n" + + " List l3 = new List[3];\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " List[] l2 = new List[2];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of List\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " List l3 = new List[3];\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List[] to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=230070 +public void test1314() { + this.runNegativeTest( + new String[] { + "X.java", + "class B {\n" + + "}\n" + + "class Y {\n" + + " Y(K k) {\n" + + " System.out.println(k);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static final B b = new B();\n" + + " Object foo(K toKey) {\n" + + " if (false) return new Y(b);//1\n" + + " if (false) return new Y((K) b);//2\n" + + " return new Y((K) (Object) b);//3\n" + + " }\n" + + " Object bar(K toKey) {\n" + + " if (false) return new Y(b);//4\n" + + " if (false) return new Y((K) b);//5\n" + + " return new Y((K) (Object) b);//6\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from B to K\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^\n" + + "Unnecessary cast from B to K\n" + + "----------\n" + + "7. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to K\n" + + "----------\n" + + "10. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to K\n" + + "----------\n" + + "11. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from B to Object\n" + + "----------\n" + + "12. ERROR in X.java (at line 16)\n" + + " if (false) return new Y(b);//4\n" + + " ^^^^^^^^^^^\n" + + "The constructor Y(B) is undefined\n" + + "----------\n" + + "13. WARNING in X.java (at line 17)\n" + + " if (false) return new Y((K) b);//5\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from B to K\n" + + "----------\n" + + "14. WARNING in X.java (at line 18)\n" + + " return new Y((K) (Object) b);//6\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to K\n" + + "----------\n" + + "15. WARNING in X.java (at line 18)\n" + + " return new Y((K) (Object) b);//6\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from B to Object\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228291 +public void test1315() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X extends Vector> {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public Vector cast(List in) {\n" + + " return (Vector) in;\n" + + " }\n" + + " public X castSilly(Vector> in) {\n" + + " return (X) in;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=230466 +public void test1316() { + this.runConformTest( + new String[] { + "e/AbstractClass.java", // ================= + "package e;\n" + + "public abstract class AbstractClass {\n" + + " protected abstract void method1();\n" + + "}\n", + "q/AbstractTest.java", // ================= + "package q;\n" + + "import java.util.Map;\n" + + "import e.AbstractClass;\n" + + "public abstract class AbstractTest {\n" + + " protected class InnerClass extends AbstractClass{\n" + + " public void innerMethod() {\n" + + " System.out.println(\"innerMethod\");\n" + + " }\n" + + " @Override\n" + + " protected void method1() {\n" + + " System.out.println(\"method1\");\n" + + " }\n" + + " }\n" + + " protected Map records;\n" + + " public abstract void method(); \n" + + "}\n", + "w/Test.java", // ================= + "package w;\n" + + "import q.AbstractTest;\n" + + "public class Test extends AbstractTest {\n" + + " @Override\n" + + " public void method() {\n" + + " // Error here\n" + + " InnerClass inner = records.get(\"1\");\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 +public void test1317() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(String name, String value) {}\n" + + " void foo(String name, T value) {}\n" + + "\n" + + " void foo2(String name, String value) {}\n" + + " > void foo2(String name, T value) {}\n" + + "\n" + + " > T foo3(String name, T value) {}\n" + + "}\n" + + "class M {}\n" + + "class N {}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo(\"HI\", null); // correctly report error\n" + + " new X().foo2(\"HI\", null); // miss ambiguous error\n" + + " \n" + + " Thread t1 = foo3(\"HI\", null);\n" + + " Thread t2 = (Thread)foo3(\"HI\", null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " > T foo3(String name, T value) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This method must return a result of type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " new X().foo(\"HI\", null); // correctly report error\n" + + " ^^^\n" + + "The method foo(String, String) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " Thread t1 = foo3(\"HI\", null);\n" + + " ^^^^\n" + + "The method foo3(String, null) is undefined for the type Test\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " Thread t2 = (Thread)foo3(\"HI\", null);\n" + + " ^^^^\n" + + "The method foo3(String, null) is undefined for the type Test\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1318() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " > void foo2(String name, T value) {}\n" + + "}\n" + + "class N {}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null);\n" + + " new X().>foo2(\"HI\", null);\n" + + " new X().>>foo2(\"HI\", null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo2(\"HI\", null);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N> is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " new X().>foo2(\"HI\", null);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " new X().>>foo2(\"HI\", null);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1319() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public class X {\n" + + " , U extends List, W extends List> void foo2(String name, U u, T t, W w) {}\n" + + "}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1320() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public class X {\n" + + " , U extends List, W extends List> void foo2(String name, U u, T t, W w) {}\n" + + "}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1321() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public class X {\n" + + " , W extends List> void foo2(String name, U u, T t, W w) {}\n" + + "}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 +public void _test1322() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + "\n" + + " /** OK: Bob.class is correct. No idea about the Thingy */\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + "\n" + + " /**\n" + + " * This line will fail when compiled with the Java 5 SDK: Test.java:25:\n" + + " * doStuff(java.lang.Class,Thingy) in Test cannot be applied to\n" + + " * (java.lang.Class,Thingy) test.doStuff(Bill.class, new\n" + + " * Thingy()); ^ Note: Test.java uses unchecked or unsafe operations.\n" + + " * Note: Recompile with -Xlint:unchecked for details. 1 error\n" + + " */\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " }\n" + + " void doStuff(Class klass, Thingy thingy) {\n" + + " }\n" + + "}\n" + + "class Jim {}\n" + + "class Bob {}\n" + + "class Bob2 extends Bob {}\n" + + "class Thingy {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " ^^^^^^^\n" + + "Bound mismatch: The generic method doStuff(Class, Thingy) of type X is not applicable for the arguments (Class, Thingy). The inferred type Jim is not a valid substitute for the bounded parameter \n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void _test1323() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.doStuff2(Jim.class, new Thingy());\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " }\n" + + " T doStuff2(Class klass, Thingy thingy) { return null; }\n" + + "}\n" + + "class Jim {}\n" + + "class Bob {}\n" + + "class Bob2 extends Bob {}\n" + + "class Thingy {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x.doStuff2(Jim.class, new Thingy());\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The generic method doStuff2(Class, Thingy) of type X is not applicable for the arguments (Class, Thingy). The inferred type Jim is not a valid substitute for the bounded parameter \n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " x.doStuff2(Jim.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff2(Class, Thingy) of the generic method doStuff2(Class, Thingy) of type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Bob2 to String\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "6. WARNING in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void _test1324() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + "\n" + + " /** OK: Bob.class is correct. No idea about the Thingy */\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " x.doStuff(Bob.class, new Thingy()); // second invocation is NOT unchecked\n" + + " Zork z;\n" + + " }\n" + + " T doStuff(Class klass, Thingy thingy) { return null; }\n" + + "}\n" + + "class Jim {}\n" + + "class Bob {}\n" + + "class Thingy {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1325() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " U foo(X xt) {\n" + + " return null;\n" + + " }\n" + + " void bar(X x) {\n" + + " X xs2 = foo(x);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^^^^^^\n" + + "Type safety: Unchecked invocation foo(X) of the generic method foo(X) of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void _test1326() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(xs, x).identity();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void bar(X x, X xs) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " X xs2 = foo(xs, x).identity();\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(X, X) of type X is not applicable for the arguments (X, X). The inferred type String is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1327() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void bar(X x, X xs) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " X xs2 = foo(x, xs).identity();\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(X, X) of the generic method foo(X, X) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " X xs2 = foo(x, xs).identity();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " X xs2 = foo(x, xs).identity();\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1328() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " void bar(List lb, List lc) {\n" + + " String s = foo(lb, lc);\n" + + " }\n" + + " U foo(List u, List v) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = foo(lb, lc);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from A to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232174 +public void test1329() { + this.runConformTest( + new String[] { + "com/b/p1/A.java", // ================= + "package com.b.p1;\n" + + "public class A {\n" + + " protected final class Inner {}\n" + + "}\n", + "com/b/p1/ADerivedSamePkg.java", // ================= + "package com.b.p1;\n" + + "import java.util.Map;\n" + + "public class ADerivedSamePkg extends A {\n" + + " protected void someMethod() {\n" + + " Map.Entry some = null;\n" + + " Inner x = some.getValue();\n" + + " }\n" + + "}\n", + "com/b/p2/ADerivedDifferentPkg.java", // ================= + "package com.b.p2;\n" + + "import java.util.Map;\n" + + "import com.b.p1.A;\n" + + "public class ADerivedDifferentPkg extends A {\n" + + " protected void someMethod() {\n" + + " Map.Entry some = null;\n" + + " Inner x = some.getValue(); // <-- error in this line\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231861 +public void test1330() { + this.runConformTest( + new String[] { + "p/BaseValue.java", // ================= + "package p;\n" + + "interface Value {}\n" + + "public class BaseValue implements Value {}\n", + "p/Model.java", // ================= + "package p;\n" + + "public class Model {\n" + + " public java.util.Map map = new java.util.LinkedHashMap();\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "p2/Person.java", // ================= + "package p2;\n" + + "public class Person extends p.Model {\n" + + " void test() {\n" + + " this.map.put(\"name\", new p.BaseValue());\n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231861 - variation +public void test1331() { + this.runConformTest( + new String[] { + "p/BaseValue.java", // ================= + "package p;\n" + + "interface Value {}\n" + + "public class BaseValue implements Value {}\n", + "p/Model.java", // ================= + "package p;\n" + + "public class Model {\n" + + " public java.util.Map map = new java.util.LinkedHashMap();\n" + + "}\n", + "p2/Person.java", // ================= + "package p2;\n" + + "public class Person extends p.Model {\n" + + " void test() {\n" + + " this.map.put(\"name\", new p.BaseValue());\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232487 +public void test1332() throws Exception { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X implements Runnable {\n" + + " public void run() {/**/}\n" + + " void foo() {\n" + + " List runnables = new ArrayList();\n" + + " for (Runnable r : runnables) {\n" + + " r.run();\n" + + " }\n" + + " Object o = runnables.get(0);\n" + + " Runnable r = runnables.get(1);\n" + + " }\n" + + "} \n", + }, + // runtime results + "" /* expected output string */); + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo();\n" + + " 0 new java.util.ArrayList [18]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.ArrayList() [20]\n" + + " 7 astore_1 [runnables]\n" + + " 8 aload_1 [runnables]\n" + + " 9 invokeinterface java.util.List.iterator() : java.util.Iterator [21] [nargs: 1]\n" + + " 14 astore_3\n" + + " 15 goto 34\n" + + " 18 aload_3\n" + + " 19 invokeinterface java.util.Iterator.next() : java.lang.Object [27] [nargs: 1]\n" + + " 24 checkcast java.lang.Runnable [5]\n" + + " 27 astore_2 [r]\n" + + " 28 aload_2 [r]\n" + + " 29 invokeinterface java.lang.Runnable.run() : void [33] [nargs: 1]\n" + + " 34 aload_3\n" + + " 35 invokeinterface java.util.Iterator.hasNext() : boolean [35] [nargs: 1]\n" + + " 40 ifne 18\n" + + " 43 aload_1 [runnables]\n" + + " 44 iconst_0\n" + + " 45 invokeinterface java.util.List.get(int) : java.lang.Object [39] [nargs: 2]\n" + + " 50 astore_2 [o]\n" + + " 51 aload_1 [runnables]\n" + + " 52 iconst_1\n" + + " 53 invokeinterface java.util.List.get(int) : java.lang.Object [39] [nargs: 2]\n" + + " 58 checkcast java.lang.Runnable [5]\n" + + " 61 astore_3 [r]\n" + + " 62 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 8, line: 7]\n" + + " [pc: 28, line: 8]\n" + + " [pc: 34, line: 7]\n" + + " [pc: 43, line: 10]\n" + + " [pc: 51, line: 11]\n" + + " [pc: 62, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 63] local: this index: 0 type: X\n" + + " [pc: 8, pc: 63] local: runnables index: 1 type: java.util.List\n" + + " [pc: 28, pc: 34] local: r index: 2 type: java.lang.Runnable\n" + + " [pc: 51, pc: 63] local: o index: 2 type: java.lang.Object\n" + + " [pc: 62, pc: 63] local: r index: 3 type: java.lang.Runnable\n"; + + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225737 +public void test1333() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X extends AbstractProject {\n" + + " public void testBug() {\n" + + " // javac compiles the following line without complaining\n" + + " BuildStepDescriptor.filter(BuildStep.PUBLISHERS, getClass());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().testBug();\n" + + " }\n" + + "}\n" + + "interface BuildStep {\n" + + " public static final PublisherList PUBLISHERS = new PublisherList();\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"serial\")\n" + + "class PublisherList extends ArrayList> {\n" + + "}\n" + + "abstract class Publisher implements BuildStep, Describable {\n" + + "}\n" + + "interface Describable> {\n" + + "}\n" + + "abstract class Descriptor> {\n" + + "}\n" + + "abstract class BuildStepDescriptor> extends Descriptor {\n" + + " \n" + + " public static > List> filter(\n" + + " List> base,\n" + + " Class> type) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "abstract class AbstractProject

, R> {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225737 - variation +public void test1334() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X extends AbstractProject {\n" + + " public void testBug() {\n" + + " filter(getClass());//1\n" + + " filter(this.getClass());//2\n" + + " filter(X.class);//3\n" + + " }\n" + + " public static void filter(Class> type) {\n" + + " }\n" + + "}\n" + + "abstract class AbstractProject

, R> {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 +public void test1335() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public void doesNotCompile(SomeInterface i) {\n" + + " T t = ((SomeDerivedInterface) i).getItem();\n" + + " }\n" + + " static interface SomeInterface {\n" + + " }\n" + + " static interface SomeDerivedInterface extends SomeInterface {\n" + + " T getItem();\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T t = ((SomeDerivedInterface) i).getItem();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.SomeInterface to X.SomeDerivedInterface\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation +public void test1336() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Other2.Member2 om2) {\n" + + " Other.Member m = (Other.Member) om2;\n" + + " }\n" + + "}\n" + + "class Other {\n" + + " class Member {}\n" + + "}\n" + + "class Other2 extends Other {\n" + + " class Member2 extends Other.Member {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " Other.Member m = (Other.Member) om2;\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Other2.Member2 to Other.Member\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation +public void test1337() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Other2.Member2 om2) {\n" + + " Other.Member m = (Other.Member) om2;\n" + + " }\n" + + "}\n" + + "class Other {\n" + + " class Member {}\n" + + "}\n" + + "class Other2 extends Other {\n" + + " class Member2 extends Other.Member {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " Other.Member m = (Other.Member) om2;\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Other2.Member2 to Other.Member\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 +public void test1338() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void m(Object someObject, Integer intObject) {\n" + + " Exception class1 = someObject.getClass();\n" + + " Exception class2 = intObject.getClass();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Exception class1 = someObject.getClass();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Exception class2 = intObject.getClass();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 - variation +public void test1339() { + this.runNegativeTest( + new String[] { + "java/lang/Object.java", // ================= + "package java.lang;\n" + + "\n" + + "public class Object {\n" + + " void foo() {\n" + + " Exception e1 = getClass();\n" + + " Exception e2 = this.getClass();\n" + + " }\n" + + " public Class getClass() { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in java\\lang\\Object.java (at line 5)\n" + + " Exception e1 = getClass();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n" + + "2. ERROR in java\\lang\\Object.java (at line 6)\n" + + " Exception e2 = this.getClass();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235460 +public void test1340() { + this.runConformTest( + new String[] { + "Derived_A.java", // ================= + "import java.util.Map;\n" + + "class Base_A {}\n" + + "public class Derived_A extends Base_A {\n" + + " public Map getMap() {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + "Derived_B.java", // ================= + "class Base_B {\n" + + "}\n" + + "public class Derived_B extends Base_B {\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "InternalCompilerError_Main.java", // ================= + "public class InternalCompilerError_Main {\n" + + " public static void main(String args[]) {\n" + + " Derived_A dummy = new Derived_A();\n" + + " Derived_B propPrice = (Derived_B)dummy.getMap().get(null); \n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235837 +public void test1341() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " Integer i = 0;\n" + + " Double d = 0.0;\n" + + " foo((Collection) Arrays.asList(i, d));\n" + + " }\n" + + " void foo(Collection c) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " foo((Collection) Arrays.asList(i, d));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List> to Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " foo((Collection) Arrays.asList(i, d));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety : A generic array of Number&Comparable is created for a varargs parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1342() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "interface Adapter {\n" + + " interface Setter {}\n" + + " public Setter makeSetter();\n" + + "}\n" + + "\n" + + "public class X implements Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return new X.Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List> l = new ArrayList>();\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // check X$1 + String expectedOutput = + "// Signature: Ljava/lang/Object;LAdapter$Setter;\n" + + "class X$1 implements Adapter$Setter {\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X$1.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); + } + + // check X + expectedOutput = + " // Signature: ()LAdapter$Setter;\n" + + " // Stack: 3, Locals: 1\n" + + " public Adapter.Setter makeSetter();\n"; + + f = new File(OUTPUT_DIR + File.separator + "X.class"); + classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + 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); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1343() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + " public Setter makeSetter() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return new X().new Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List.Setter> l = new ArrayList.Setter>();\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1344() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + " public Setter makeSetter() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return new X().new Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List l = new ArrayList();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " public class X extends Adapter {\n" + + " ^^^^^^^\n" + + "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^^^^^\n" + + "Name clash: The method makeSetter() of type X has the same erasure as makeSetter() of type Adapter but does not override it\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " return new X().new Setter() {};\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " return new X().new Setter() {};\n" + + " ^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1345() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + " public Setter makeSetter() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return (String) new X().new Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List l = new ArrayList();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " public class X extends Adapter {\n" + + " ^^^^^^^\n" + + "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^^^^^\n" + + "Name clash: The method makeSetter() of type X has the same erasure as makeSetter() of type Adapter but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from new Adapter.Setter(){} to String\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from String to Adapter.Setter\n" + + "----------\n" + + "6. WARNING in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1346() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public Adapter.Setter makeSetter() {\n" + + " return (X.Setter) \"a\";\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public class X extends Adapter {\n" + + " ^^^^^^^\n" + + "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public Adapter.Setter makeSetter() {\n" + + " ^^^^^^^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return (X.Setter) \"a\";\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from String to Adapter.Setter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236220 +public void test1347() throws Exception { + this.runNegativeTest( + new String[] { + "DeprecatedType.java", // ================= + "class Base {\n" + + " class Member {\n" + + " }\n" + + "}\n" + + "\n" + + "@Deprecated\n" + + "public class DeprecatedType extends Base {\n" + + "}\n", + "X.java", // ================= + "public class X {\n" + + " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + + " DeprecatedType.Member m2; // DeprecatedType is raw + indirect access to Member\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The type DeprecatedType is deprecated\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Base.Member is a raw type. References to generic type Base.Member should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " DeprecatedType.Member m2; // DeprecatedType is raw + indirect access to Member\n" + + " ^^^^^^^^^^^^^^\n" + + "The type DeprecatedType is deprecated\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174282 - variation +public void test1348() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "abstract class AbstractOBOverlaySettings extends AbstractOverlaySettings implements RefSymbolTypeSettings {/*empty*/}\n" + + "abstract class AbstractOverlaySettings implements SymbolTypeSettings {/*empty*/}\n" + + "interface DAFDataController {/*empty*/}\n" + + "interface ReferenceableData {/*empty*/}\n" + + "enum SymbolTypes {/*empty*/}\n" + + "interface SymbolTypeSettings {/*empty*/}\n" + + "interface AllOverlaySettingsController {/*empty*/}\n" + + "interface DAFDataWithRefController extends DAFDataController {/*empty*/}\n" + + "class OBAreaOverlaySettings extends AbstractOBOverlaySettings {/*empty*/}\n" + + "interface RefSymbolTypeSettings extends SymbolTypeSettings, ReferenceableData {/*empty*/}\n" + + "public class X {\n" + + " public X() {\n" + + " DAFDataController controller00 = null;\n" + + " DAFDataWithRefController controller01 = \n" + + " (DAFDataWithRefController) controller00;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 15)\n" + + " (DAFDataWithRefController) controller00;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from DAFDataController to DAFDataWithRefController\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 +public void test1350() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface TreeVisitor {\n" + + " public T visit(U location);\n" + + "}\n" + + "\n" + + "interface TreeVisitable {\n" + + " public T visit(TreeVisitor visitor) throws IOException;\n" + + "}\n" + + "\n" + + "abstract class Param implements TreeVisitable {\n" + + " public final Param lookforParam(final String name) {\n" + + " TreeVisitor visitor = new TreeVisitor() {\n" + + " public Param visit(Param location) {\n" + + " return null;\n" + + " }\n" + + " };\n" + + " return visit(visitor);\n" + + " }\n" + + "\n" + + " public abstract T visit(TreeVisitor visitor);\n" + + "}\n" + + "\n" + + "class StructParam extends Param {\n" + + " public T visit(TreeVisitor visitor) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " StructParam p = new StructParam();\n" + + " p.lookforParam(\"abc\");\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation +public void test1351() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IFoo {\n" + + " T foo(T t) throws IOException;\n" + + "}\n" + + "interface JFoo {\n" + + " T foo(T t) throws Exception;\n" + + "}\n" + + "abstract class Foo implements IFoo, JFoo {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = createFoo();\n" + + " try {\n" + + " f.foo(null);\n" + + " } catch(IOException e) {\n" + + " }\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " static Foo createFoo() {\n" + + " return new Foo() {\n" + + " public T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation +public void test1352() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IFoo {\n" + + " T foo(T t) throws IOException;\n" + + "}\n" + + "interface JFoo {\n" + + " T foo(T t) throws Exception;\n" + + "}\n" + + "abstract class Foo implements IFoo, JFoo {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = createFoo();\n" + + " try {\n" + + " f.foo(null);\n" + + " } catch(IOException e) {\n" + + " }\n" + + " System.out.println(\"done\"); //dd\n" + + " }\n" + + " static Foo createFoo() {\n" + + " return new Foo() {\n" + + " public T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation +public void test1353() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IFoo {\n" + + " T foo(T t) throws IOException;\n" + + "}\n" + + "interface JFoo {\n" + + " T foo(T t);\n" + + "}\n" + + "abstract class Foo implements IFoo, JFoo {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = createFoo();\n" + + " try {\n" + + " f.foo(null);\n" + + " } catch(IOException e) {\n" + + " }\n" + + " System.out.println(\"done\"); //dd\n" + + " }\n" + + " static Foo createFoo() {\n" + + " return new Foo() {\n" + + " public T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " } catch(IOException e) {\n" + + " ^^^^^^^^^^^\n" + + "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 +public void test1354() { + this.runConformTest( + new String[] { + "X.java", // ================= + "interface Operation extends CheckedOperation {\n" + + " void op(In o);\n" + + "}\n" + + "\n" + + "interface CheckedOperation {\n" + + " void op(In o) throws E;\n" + + "}\n" + + "\n" + + "class ToUpper implements Operation {\n" + + " public void op(String o) {\n" + + " System.out.print(\"[\"+o.toUpperCase()+\"]\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new ToUpper().op(\"hello world 1\"); // Works\n" + + " Operation t = new ToUpper();\n" + + " t.op(\"hello world 2\"); // Doesn\'t work: Exception in thread \"main\" java.lang.NoSuchMethodError: Operation.op(Ljava/lang/String;)V\n" + + " }\n" + + "}\n", // ================= + }, + "[HELLO WORLD 1][HELLO WORLD 2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 - variation +public void test1355() { + this.runConformTest( + new String[] { + "X.java", // ================= + "interface Operation extends CheckedOperation {\n" + + " void op(In o) throws RuntimeException;\n" + + "}\n" + + "\n" + + "interface CheckedOperation {\n" + + " void op(In o) throws E;\n" + + "}\n" + + "\n" + + "class ToUpper implements Operation {\n" + + " public void op(String o) {\n" + + " System.out.print(\"[\"+o.toUpperCase()+\"]\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new ToUpper().op(\"hello world 1\"); // Works\n" + + " Operation t = new ToUpper();\n" + + " t.op(\"hello world 2\"); // Doesn\'t work: Exception in thread \"main\" java.lang.NoSuchMethodError: Operation.op(Ljava/lang/String;)V\n" + + " }\n" + + "}\n", // ================= + }, + "[HELLO WORLD 1][HELLO WORLD 2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 - variation +public void test1356() { + this.runConformTest( + new String[] { + "X.java", // ================= + "class Activator {\n" + + "}\n" + + "interface Child extends Parent {\n" + + " Activator get(T value);\n" + + "}\n" + + "interface Parent {\n" + + " Activator get(T value) throws RuntimeException;\n" + + "}\n" + + "public class X {\n" + + " static class Impl implements Child {\n" + + " public Activator get(T value) {\n" + + " System.out.println(\"done\");\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Child c = new Impl();\n" + + " try {\n" + + " c.get(true);\n" + + " } catch (Throwable t) { \n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 +public void _test1357() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "@interface Ann { Class value(); }\n" + + "\n" + + "/**\n" + + " * @see Private - Private is not visible here\n" + + " */\n" + + "@Ann(X.Private.class) // Private is not visible here\n" + + "public abstract class X implements Map {\n" + + " /**\n" + + " * @see Private - Private is visible here\n" + + " */\n" + + " private static interface Private {}\n" + + " Private field;\n" + + "}\n" + + "class Secondary {\n" + + " private static interface SecondaryPrivate {}\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation +public void _test1358() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public abstract class X implements List {\n" + + " /**\n" + + " * @see Inter.Private - Private is visible here\n" + + " */\n" + + " class Inter {\n" + + " private class Private {}\n" + + " }\n" + + " Inter.Private field;\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation +public void test1359() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " class M1 {\n" + + " private class Private {\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " M1.Private p;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 +public void test1360() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(final Object bean, final String property) {\n" + + " return (T)new Object();\n" + + " }\n" + + " public void testGenerics() {\n" + + " int value = getValue(new Object(), \"\");\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation +public void test1361() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(T t) {\n" + + " return t;\n" + + " }\n" + + " public void testGenerics() {\n" + + " int value = getValue(0);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation +public void test1362() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(T t1, T t2) {\n" + + " return t1;\n" + + " }\n" + + " public void testGenerics() {\n" + + " getValue(0, this);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation +public void test1363() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(T t1, T t2) {\n" + + " return t1;\n" + + " }\n" + + "\n" + + " public void testGenerics(Comparable s) {\n" + + " int i = getValue(0, s);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int i = getValue(0, s);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparable&Serializable> to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 +public void test1364() { + this.runNegativeTest( + new String[] { + "Status.java", // ================= + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public enum Status {\n" + + " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + + "\n" + + " private static Map mapping;\n" + + "\n" + + " private Status(final byte newValue) {\n" + + "\n" + + " if (Status.mapping == null) {\n" + + " Status.mapping = new HashMap();\n" + + " }\n" + + "\n" + + " Status.mapping.put(newValue, this);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Status.java (at line 11)\n" + + " if (Status.mapping == null) {\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "2. ERROR in Status.java (at line 12)\n" + + " Status.mapping = new HashMap();\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "3. ERROR in Status.java (at line 15)\n" + + " Status.mapping.put(newValue, this);\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239203 +public void test1365() { + this.runConformTest( + new String[] { + "C.java", // ================= + "class A {\n" + + "}\n" + + "\n" + + "class B {\n" + + "}\n" + + "\n" + + "public class C {\n" + + " > A foo(Class clazz) {\n" + + " A ret = bar(\"bla\");\n" + + " return ret;\n" + + " }\n" + + "\n" + + " > A bar(String clazzName) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 +public void test1366() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IServiceAction {\n" + + " Response execute(Request parameter) throws Fault;\n" + + "}\n" + + "\n" + + "interface IServiceOperation extends IServiceAction {\n" + + " Response execute(Request parameter) throws Fault;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public String execute(String parameter) throws IOException {\n" + + " return serviceOperation.execute(parameter);\n" + + " }\n" + + "\n" + + " private final IServiceOperation serviceOperation = null;\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239439 +public void test1367() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " private static Map var;\n" + + " static {\n" + + " var= new HashMap();\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private static Map var;\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " var= new HashMap();\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " var= new HashMap();\n" + + " ^^^^^^^\n" + + "HashMap cannot be resolved to a type\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 +public void test1370() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor selfCall() {\n" + + " return this;\n" + + " }\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1371() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public E selfCall() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1372() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public E selfCall() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1373() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor next;\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1374() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor next;\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " NonPublicInterfaceImplementor impl = new NonPublicInterfaceImplementor();\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(impl.next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1375() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor next;\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " NonPublicInterfaceImplementor impl = new NonPublicInterfaceImplementor();\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(impl.next.next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1376() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public NonPublicInterfaceImplementor next;\n" + + " public void foo() {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=241502 +public void test1378() { + this.runConformTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "//the remote-usable interface\n" + + "class RemoteException extends Throwable {}\n" + + " \n" + + "interface RemoteStore {\n" + + " public abstract

P get(Class

c) throws RemoteException;\n" + + "}\n" + + "\n" + + "//the interface for local use\n" + + "interface Store extends RemoteStore{\n" + + " public

P get(Class

c) ;\n" + + "}\n" + + "\n" + + "//the implementation\n" + + "class StoreImpl implements Store {\n" + + " public

P get(Class

c) {\n" + + " System.out.print(\"[get]\");\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class Persistent {\n" + + "}\n" + + "\n" + + "public class X {\n" + + "public static void main(String[] args) {\n" + + " try {\n" + + " RemoteStore t = new StoreImpl();\n" + + " t.get(Object.class); //works\n" + + " t.get(Persistent.class); //works\n" + + " } catch (RemoteException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " Store t = new StoreImpl();\n" + + " t.get(Object.class); //works\n" + + " t.get(Persistent.class); //NoSuchMethodError\n" + + "} \n" + + "}\n",//----------------------------------------------------------------------- + }, + "[get][get][get][get]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 +public void test1418() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Box, V extends U> {\n" + + " V value;\n" + + " Box next;\n" + + " Box(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " Box() {}\n" + + "}\n" + + "class A extends Box {}\n" + + "class B extends Box {}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Box, Box> a = new Box, Box>(new Box(new A()));\n" + + " Box b = a;\n" + + " b.value.next = new Box(new B());\n" + + " A c = a.value.next.value;\n" + + " String s = b.value;\n" + + " b.value.next.next = new Box(new B());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " b.value.next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " String s = b.value;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#6-of ? to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " b.value.next.next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 - variation +public void test1419() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Box, V extends U> {\n" + + " private V value;\n" + + " Box next;\n" + + " Box(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " Box() {}\n" + + " V getValue() { return this.value; }\n" + + "}\n" + + "class A extends Box {}\n" + + "class B extends Box {}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Box, Box> a = new Box, Box>(new Box(new A()));\n" + + " Box b = a;\n" + + " b.getValue().next = new Box(new B());\n" + + " A c = a.getValue().next.getValue();\n" + + " String s = b.getValue();\n" + + " b.getValue().next.next = new Box(new B());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " b.getValue().next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " String s = b.getValue();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#6-of ? to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " b.getValue().next.next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 - variation +public void test1420() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Box, V extends U> {\n" + + " V value;\n" + + " Box next(V v) { return new Box(v); }\n" + + " Box(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " Box() {/**/}\n" + + "}\n" + + "class A extends Box {/**/}\n" + + "class B extends Box {/**/}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Box, Box> a = new Box, Box>(new Box(new A()));\n" + + " Box b = a;\n" + + " b.value.next(new Box(new B()));\n" + + " b.value.next(b.value);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " b.value.next(new Box(new B()));\n" + + " ^^^^\n" + + "The method next(capture#4-of ?) in the type Box is not applicable for the arguments (Box)\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " b.value.next(b.value);\n" + + " ^^^^\n" + + "The method next(capture#10-of ?) in the type Box is not applicable for the arguments (capture#8-of ?)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 +public void test1421() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 - variation +public void test1422() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 +public void test1423() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 - variation +public void test1424() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://github.com/groovy/groovy-eclipse/issues/148 +public void test1425() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + this.runConformTest( + new String[] { + "A.java", + "public interface A> {}", + "B.groovy", + "class B {public void test(A a) {}}" + }); +} } \ No newline at end of file