Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 51397 Details for
Bug 159607
[1.5][compiler] M2: Unnecessary cast is necessary
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
159607.txt (text/plain), 8.44 KB, created by
Philipe Mulet
on 2006-10-04 05:25:37 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2006-10-04 05:25:37 EDT
Size:
8.44 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v >retrieving revision 1.73 >diff -u -r1.73 ASTNode.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 5 Sep 2006 13:50:57 -0000 1.73 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 4 Oct 2006 09:29:22 -0000 >@@ -266,8 +266,10 @@ > if (varargsType.dimensions < dimensions) { > scope.problemReporter().varargsArgumentNeedCast(method, lastArgType, invocationSite); > } else if (varargsType.dimensions == dimensions >- && varargsType.leafComponentType.erasure() != lastArgType.leafComponentType().erasure() >- && lastArgType.isCompatibleWith(varargsType)) { >+ && lastArgType != varargsType >+ && lastArgType.leafComponentType().erasure() != varargsType.leafComponentType.erasure() >+ && lastArgType.isCompatibleWith(varargsType.elementsType()) >+ && lastArgType.isCompatibleWith(varargsType)) { > scope.problemReporter().varargsArgumentNeedCast(method, lastArgType, invocationSite); > } > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java,v >retrieving revision 1.48 >diff -u -r1.48 VarargsTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 29 Sep 2006 10:28:06 -0000 1.48 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 4 Oct 2006 09:29:27 -0000 >@@ -1795,5 +1795,174 @@ > "}", > }, > "12"); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=159607 >+ public void test052() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "class X {\n" + >+ " void addChildren(Widget w) {\n" + >+ " if (w instanceof Composite) {\n" + >+ " Composite composite = (Composite) w;\n" + >+ " addAll((Widget[]) composite.getChildren());\n" + >+ " addAll(composite.getChildren());\n" + >+ " }\n" + >+ " Zork z;\n" + >+ " }\n" + >+ " void addAll(Widget... widgets) {\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "class Widget {}\n" + >+ "class Control extends Widget {}\n" + >+ "class Composite extends Control {\n" + >+ " Control[] getChildren() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}", // =================, >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " addAll((Widget[]) composite.getChildren());\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from Control[] to Widget[]\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=159607 - variation >+ public void test053() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "class X {\n" + >+ " void addChildren(Widget w) {\n" + >+ " if (w instanceof Composite) {\n" + >+ " Composite composite = (Composite) w;\n" + >+ " addAll((Control[]) composite.getChildren());\n" + >+ " addAll(composite.getChildren());\n" + >+ " }\n" + >+ " Zork z;\n" + >+ " }\n" + >+ " void addAll(Control... widgets) {\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "class Widget {}\n" + >+ "class Control extends Widget {}\n" + >+ "class Composite extends Control {\n" + >+ " Control[] getChildren() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}", // =================, >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " addAll((Control[]) composite.getChildren());\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from Control[] to Control[]\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 test054() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " Zork z;\n" + >+ " public static void varargs(Object... args) {\n" + >+ " if (args == null) {\n" + >+ " System.out.println(\"args is null\");\n" + >+ " return;\n" + >+ " }\n" + >+ " if (args.length == 0) {\n" + >+ " System.out.println(\"args is of length 0\");\n" + >+ " return;\n" + >+ " }\n" + >+ "\n" + >+ " System.out.println(args.length + \" \" + args[0]);\n" + >+ " }\n" + >+ "\n" + >+ " public static void main(String[] args) {\n" + >+ " @SuppressWarnings(\"boxing\")\n" + >+ " Integer[] i = { 0, 1, 2, 3, 4 };\n" + >+ " varargs(i);\n" + >+ " varargs((Object[]) i);\n" + >+ " varargs((Object) i);\n" + >+ " varargs(i.clone());\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 19)\n" + >+ " varargs(i);\n" + >+ " ^^^^^^^^^^\n" + >+ "The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 22)\n" + >+ " varargs(i.clone());\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + >+ "----------\n"); >+ } >+ public void test055() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " private static int elementCount(Object... elements) {\n" + >+ " return elements == null ? 0 : elements.length;\n" + >+ " }\n" + >+ " public static void main(String... args) {\n" + >+ " System.out.print(\"null length array: \" + elementCount(null));\n" + >+ " System.out.print(\"/[null] length array: \" + elementCount((Object)null));\n" + >+ " System.out.print(\"/empty length array: \" + elementCount());\n" + >+ " System.out.println(\"/[a,b,c] length array: \" + elementCount(\"a\", \"b\", \"c\"));\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "null length array: 0/[null] length array: 1/empty length array: 0/[a,b,c] length array: 3"); >+ } >+ public void test056() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " Zork z;\n" + >+ " private static int elementCount(Object... elements) {\n" + >+ " return elements == null ? 0 : elements.length;\n" + >+ " }\n" + >+ " public static void main(String... args) {\n" + >+ " System.out.print(\"null length array: \" + elementCount(null));\n" + >+ " System.out.print(\"/[null] length array: \" + elementCount((Object)null));\n" + >+ " System.out.print(\"/empty length array: \" + elementCount());\n" + >+ " System.out.println(\"/[a,b,c] length array: \" + elementCount(\"a\", \"b\", \"c\"));\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 7)\n" + >+ " System.out.print(\"null length array: \" + elementCount(null));\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "The argument of type null should explicitly be cast to Object[] for the invocation of the varargs method elementCount(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + >+ "----------\n"); >+ } >+ }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 159607
: 51397