### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java,v retrieving revision 1.154 diff -u -r1.154 TypeDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 29 Jan 2009 17:00:08 -0000 1.154 +++ compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 3 Feb 2009 09:33:22 -0000 @@ -345,7 +345,7 @@ } // anonymous type constructor creation: rank is important since bindings already got sorted -public MethodBinding createDefaultConstructorWithBinding(MethodBinding inheritedConstructorBinding, boolean isUnchecked) { +public MethodBinding createDefaultConstructorWithBinding(MethodBinding inheritedConstructorBinding, boolean eraseThrownExceptions) { //Add to method'set, the default constuctor that just recall the //super constructor with the same arguments String baseName = "$anonymous"; //$NON-NLS-1$ @@ -393,7 +393,7 @@ } //============BINDING UPDATE========================== - ReferenceBinding[] thrownExceptions = isUnchecked + ReferenceBinding[] thrownExceptions = eraseThrownExceptions ? this.scope.environment().convertToRawTypes(inheritedConstructorBinding.original().thrownExceptions, true, true) : inheritedConstructorBinding.thrownExceptions; Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java,v retrieving revision 1.92 diff -u -r1.92 QualifiedAllocationExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 8 Jan 2009 20:51:05 -0000 1.92 +++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 3 Feb 2009 09:33:22 -0000 @@ -82,7 +82,7 @@ // record some dependency information for exception types ReferenceBinding[] thrownExceptions; if (((thrownExceptions = this.binding.thrownExceptions).length) != 0) { - if ((this.bits & ASTNode.Unchecked) != 0) { + if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) { thrownExceptions = currentScope.environment().convertToRawTypes(this.binding.original().thrownExceptions, true, true); } // check exception handling @@ -455,7 +455,7 @@ scope.problemReporter().unnecessaryTypeArgumentsForMethodInvocation(inheritedBinding, this.genericTypeArguments, this.typeArguments); } // Update the anonymous inner class : superclass, interface - this.binding = this.anonymousType.createDefaultConstructorWithBinding(inheritedBinding, (this.bits & ASTNode.Unchecked) != 0); + this.binding = this.anonymousType.createDefaultConstructorWithBinding(inheritedBinding, (this.bits & ASTNode.Unchecked) != 0 && genericTypeArguments == null); return this.resolvedType; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java,v retrieving revision 1.77 diff -u -r1.77 AllocationExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 8 Jan 2009 20:51:05 -0000 1.77 +++ compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 3 Feb 2009 09:33:22 -0000 @@ -43,7 +43,7 @@ // record some dependency information for exception types ReferenceBinding[] thrownExceptions; if (((thrownExceptions = this.binding.thrownExceptions).length) != 0) { - if ((this.bits & ASTNode.Unchecked) != 0) { + if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) { thrownExceptions = currentScope.environment().convertToRawTypes(this.binding.original().thrownExceptions, true, true); } // check exception handling Index: compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java,v retrieving revision 1.141 diff -u -r1.141 MessageSend.java --- compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 28 Jan 2009 18:48:47 -0000 1.141 +++ compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 3 Feb 2009 09:33:22 -0000 @@ -69,7 +69,7 @@ } ReferenceBinding[] thrownExceptions; if ((thrownExceptions = this.binding.thrownExceptions) != Binding.NO_EXCEPTIONS) { - if ((this.bits & ASTNode.Unchecked) != 0) { + if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) { thrownExceptions = currentScope.environment().convertToRawTypes(this.binding.original().thrownExceptions, true, true); } // must verify that exceptions potentially thrown by this expression are caught in the method @@ -484,7 +484,7 @@ this.resolvedType = this.actualReceiverType; } else { TypeBinding returnType; - if ((this.bits & ASTNode.Unchecked) != 0) { + if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) { returnType = this.binding.original().returnType; if (returnType != null) { returnType = scope.environment().convertToRawType(returnType.erasure(), true); Index: compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java,v retrieving revision 1.68 diff -u -r1.68 ExplicitConstructorCall.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java 8 Jan 2009 20:51:05 -0000 1.68 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java 3 Feb 2009 09:33:22 -0000 @@ -81,7 +81,7 @@ ReferenceBinding[] thrownExceptions; if ((thrownExceptions = this.binding.thrownExceptions) != Binding.NO_EXCEPTIONS) { - if ((this.bits & ASTNode.Unchecked) != 0) { + if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) { thrownExceptions = currentScope.environment().convertToRawTypes(this.binding.original().thrownExceptions, true, true); } // check exceptions Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetMessageSend.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetMessageSend.java,v retrieving revision 1.61 diff -u -r1.61 CodeSnippetMessageSend.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetMessageSend.java 8 Jan 2009 20:51:06 -0000 1.61 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetMessageSend.java 3 Feb 2009 09:33:22 -0000 @@ -334,7 +334,7 @@ TypeBinding returnType = this.binding.returnType; if (returnType != null) { - if ((this.bits & ASTNode.Unchecked) != 0) { + if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) { returnType = scope.environment().convertToRawType(returnType.erasure(), true); } returnType = returnType.capture(scope, this.sourceEnd); #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.787 diff -u -r1.787 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 22 Jan 2009 09:59:11 -0000 1.787 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 3 Feb 2009 09:33:32 -0000 @@ -48983,4 +48983,210 @@ "List is a raw type. References to generic type List should be parameterized\n" + "----------\n"); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263215 +public void test1444() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.ArrayList;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " @SuppressWarnings(\"all\") public static T[] asArray(Iterator it, Class clazz) {\n" + + " List lst = new ArrayList();\n" + + " while (it.hasNext()) {\n" + + " lst.add(it.next());\n" + + " }\n" + + " return lst.toArray((T[]) java.lang.reflect.Array.newInstance(clazz, lst.size()));\n" + + " }\n" + + " public void test() {\n" + + " String[] asString = null;\n" + + " // eclipse 3.5M4 this worked in build I20090129-1200 it doesnt anymore\n" + + " asString = X. asArray(getIterator(), String.class);\n" + + " // now i have to do this:\n" + + " Iterator iterator = getIterator();\n" + + " asString = X. asArray(iterator, String.class);\n" + + " // this also works except if i have remove unnecessary cast enabled then\n" + + " // the cast is removed and i get a compile error\n" + + " asString = X. asArray((Iterator) getIterator(), String.class);\n" + + " }\n" + + " @SuppressWarnings(\"all\") public Iterator getIterator() {\n" + + " return new Iterator() {\n" + + " public void remove() {\n" + + " }\n" + + " public Object next() {\n" + + " return null;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + " };\n" + + " }\n" + + " Zork z;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " asString = X. asArray(getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation asArray(Iterator, Class) of the generic method asArray(Iterator, Class) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " asString = X. asArray(getIterator(), String.class);\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 18)\n" + + " Iterator iterator = getIterator();\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "4. WARNING in X.java (at line 22)\n" + + " asString = X. asArray((Iterator) getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Iterator to Iterator\n" + + "----------\n" + + "5. WARNING in X.java (at line 22)\n" + + " asString = X. asArray((Iterator) getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Iterator to Iterator\n" + + "----------\n" + + "6. ERROR in X.java (at line 36)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263215 - variation +public void test1445() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.io.IOException;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " X(List lt) throws T { }\n" + + " List foo(List t) throws T { return t; }\n" + + "\n" + + " static void bar(List l) {\n" + + " new X(l).foo(l);\n" + + " }\n" + + " static void baz(List l) throws IOException {\n" + + " new X(l). foo(l);\n" + + " }\n" + + " \n" + + " X(List l, long l2) throws IOException {\n" + + " this(l);\n" + + " }\n" + + "\n" + + " static void baz2(List l) throws IOException {\n" + + " new X(l){}. foo(l);\n" + + " }\n" + + "\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " static void bar(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" + + " new X(l).foo(l);\n" + + " ^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List) of type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + + "----------\n" + + "6. WARNING in X.java (at line 9)\n" + + " new X(l).foo(l);\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 9)\n" + + " new X(l).foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "8. WARNING in X.java (at line 11)\n" + + " static void baz(List l) throws IOException {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "10. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List) of type X\n" + + "----------\n" + + "11. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "12. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "13. WARNING in X.java (at line 15)\n" + + " X(List l, long l2) throws IOException {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 16)\n" + + " this(l);\n" + + " ^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "15. WARNING in X.java (at line 16)\n" + + " this(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "16. WARNING in X.java (at line 19)\n" + + " static void baz2(List l) throws IOException {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "17. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "18. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List) of type X\n" + + "----------\n" + + "19. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "20. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} } \ No newline at end of file