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 148682 Details for
Bug 287607
[1.5][compiler] cast of inner of generic enclosing type are not reported as unsafe
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch and testcase
patch.txt (text/plain), 5.73 KB, created by
Kent Johnson
on 2009-10-02 15:33:32 EDT
(
hide
)
Description:
Proposed patch and testcase
Filename:
MIME Type:
Creator:
Kent Johnson
Created:
2009-10-02 15:33:32 EDT
Size:
5.73 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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.805 >diff -u -r1.805 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 24 Sep 2009 16:21:25 -0000 1.805 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 2 Oct 2009 18:11:36 -0000 >@@ -26744,11 +26744,16 @@ > " 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" + >+ "1. WARNING in X.java (at line 6)\n" + >+ " C1<T>.C11[] ts = (C1<T>.C11[]) new C1<?>.C11[5];\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from C1<?>.C11[] to C1<T>.C11[]\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=111014 >@@ -49821,4 +49826,39 @@ > "true" > ); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=287607 >+public void test1455() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "class Outer<E> {\n" + >+ " Inner inner;\n" + >+ " class Inner {\n" + >+ " E e;\n" + >+ " E getOtherElement(Object other) {\n" + >+ " if (!(other instanceof Outer<?>.Inner))\n" + >+ " throw new IllegalArgumentException(String.valueOf(other));\n" + >+ " Inner that = (Inner) other;\n" + >+ " return that.e;\n" + >+ " }\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " Outer<String> s = new Outer<String>();\n" + >+ " s.inner = s.new Inner();\n" + >+ " s.inner.e = \"hello\";\n" + >+ " Outer<Integer> i = new Outer<Integer>();\n" + >+ " i.inner = i.new Inner();\n" + >+ " i.inner.e = 1234;\n" + >+ " s.inner.getOtherElement(i.inner);\n" + >+ " }\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 8)\n" + >+ " Inner that = (Inner) other;\n" + >+ " ^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to Outer<E>.Inner\n" + >+ "----------\n" >+ ); >+} > } >\ No newline at end of file >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java,v >retrieving revision 1.122 >diff -u -r1.122 Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 27 Aug 2009 15:27:01 -0000 1.122 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 2 Oct 2009 18:11:37 -0000 >@@ -521,7 +521,7 @@ > if (!isNarrowing) tagAsUnnecessaryCast(scope, castType); > return true; > } >- if (match != null && (castType.isBoundParameterizedType() || expressionType.isBoundParameterizedType())) { >+ if (match != null && (castType.isEnclosingTypeBoundParameterizedType() || expressionType.isEnclosingTypeBoundParameterizedType())) { > if(isNarrowing > ? match.isProvablyDistinct(expressionType) > : castType.isProvablyDistinct(match)) { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java,v >retrieving revision 1.127 >diff -u -r1.127 CastExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 25 Sep 2009 17:00:24 -0000 1.127 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 2 Oct 2009 18:11:37 -0000 >@@ -311,7 +311,7 @@ > } > switch (castType.kind()) { > case Binding.PARAMETERIZED_TYPE : >- if (castType.isBoundParameterizedType()) { >+ if (castType.isEnclosingTypeBoundParameterizedType()) { > if (match == null) { // unrelated types > this.bits |= ASTNode.UnsafeCast; > return true; >@@ -379,7 +379,7 @@ > break; > case Binding.ARRAY_TYPE : > TypeBinding leafType = castType.leafComponentType(); >- if (isNarrowing && (leafType.isBoundParameterizedType() || leafType.isTypeVariable())) { >+ if (isNarrowing && (leafType.isEnclosingTypeBoundParameterizedType() || leafType.isTypeVariable())) { > this.bits |= ASTNode.UnsafeCast; > return true; > } >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java,v >retrieving revision 1.104 >diff -u -r1.104 TypeBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java 8 Jan 2009 20:51:04 -0000 1.104 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java 2 Oct 2009 18:11:37 -0000 >@@ -437,6 +437,17 @@ > } > > /** >+ * Returns true if its a nested parameterized type AND its not of the form List<?> or >+ * an enclosing type is not >+ */ >+public boolean isEnclosingTypeBoundParameterizedType() { >+ if ((this.tagBits & TagBits.IsBoundParameterizedType) != 0) return true; >+ >+ TypeBinding enclosing = this.enclosingType(); >+ return enclosing != null && enclosing.isBoundParameterizedType(); >+} >+ >+/** > * Returns true if the type is the capture of some wildcard > */ > public boolean isCapture() {
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 287607
:
148682
|
148685