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 245800 Details for
Bug 441338
[1.8][null] better combine null type annotations on substitution of parameterized type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch under test
Improving-unannotatedZ-impl--use.patch (text/plain), 10.12 KB, created by
Stephan Herrmann
on 2014-08-07 07:51:08 EDT
(
hide
)
Description:
patch under test
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2014-08-07 07:51:08 EDT
Size:
10.12 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java >index 676259a..5258ab4 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java >@@ -5425,6 +5425,133 @@ > "Null type mismatch (type annotations): required \'@NonNull Collection\' but this expression has type \'@Nullable Collection\'\n" + > "----------\n"); > } >+// top-level annotation is overridden at use-site, details remain - parameterized type >+public void testTypeVariable19() { >+ runNegativeTestWithLibs( >+ new String[] { >+ "X.java", >+ "import java.util.ArrayList;\n" + >+ "import java.util.List;\n" + >+ "\n" + >+ "import org.eclipse.jdt.annotation.NonNull;\n" + >+ "import org.eclipse.jdt.annotation.Nullable;\n" + >+ "interface I<T,U extends List<T>> {\n" + >+ " U get0();\n" + >+ " @Nullable U get1();\n" + >+ " @NonNull U get2();\n" + >+ "}\n" + >+ "class X {\n" + >+ " static String test (I<@Nullable String, @NonNull ArrayList<@Nullable String>> i1,\n" + >+ " I<@NonNull String, @Nullable ArrayList<@NonNull String>> i2, int s) {\n" + >+ " switch(s) {\n" + >+ " case 0 : return i1.get0().get(0).toUpperCase(); // problem at detail\n" + >+ " case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + >+ " case 2 : return i1.get2().get(0).toUpperCase(); // problem at detail\n" + >+ " case 3 : return i2.get0().get(0).toUpperCase(); // problem at top\n" + >+ " case 4 : return i2.get1().get(0).toUpperCase(); // problem at top\n" + >+ " case 5 : return i2.get2().get(0).toUpperCase(); // OK\n" + >+ " default : return \"\";" + >+ " }\n" + >+ " }\n" + >+ "}\n" >+ }, >+ getCompilerOptions(), >+ "----------\n" + >+ "1. ERROR in X.java (at line 15)\n" + >+ " case 0 : return i1.get0().get(0).toUpperCase(); // problem at detail\n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "Potential null pointer access: The method get(int) may return null\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 16)\n" + >+ " case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + >+ " ^^^^^^^^^\n" + >+ "Potential null pointer access: The method get1() may return null\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 16)\n" + >+ " case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "Potential null pointer access: The method get(int) may return null\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 17)\n" + >+ " case 2 : return i1.get2().get(0).toUpperCase(); // problem at detail\n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "Potential null pointer access: The method get(int) may return null\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 18)\n" + >+ " case 3 : return i2.get0().get(0).toUpperCase(); // problem at top\n" + >+ " ^^^^^^^^^\n" + >+ "Potential null pointer access: The method get0() may return null\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 19)\n" + >+ " case 4 : return i2.get1().get(0).toUpperCase(); // problem at top\n" + >+ " ^^^^^^^^^\n" + >+ "Potential null pointer access: The method get1() may return null\n" + >+ "----------\n"); >+} >+// top-level annotation is overridden at use-site, array with anotations on dimensions >+public void testTypeVariable19a() { >+ runNegativeTestWithLibs( >+ new String[] { >+ "X.java", >+ "import org.eclipse.jdt.annotation.NonNull;\n" + >+ "import org.eclipse.jdt.annotation.Nullable;\n" + >+ "interface I1<T> {\n" + >+ " T @Nullable[] get0();\n" + >+ " @Nullable T @NonNull[] get1();\n" + >+ " @Nullable T @Nullable[] get2();\n" + >+ "}\n" + >+ "interface I2<T> {\n" + >+ " T @NonNull[] get0();\n" + >+ " @NonNull T @NonNull[] get1();\n" + >+ " @NonNull T @Nullable[] get2();\n" + >+ "}\n" + >+ "class X {\n" + >+ " static String test (I1<@NonNull String> i1, I2<@Nullable String> i2, int s) {\n" + >+ " switch (s) {\n" + >+ " case 0: return i1.get0()[0].toUpperCase(); // problem on array\n" + >+ " case 1: return i1.get1()[0].toUpperCase(); // problem on element\n" + >+ " case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + >+ " case 3: return i2.get0()[0].toUpperCase(); // problem on element\n" + >+ " case 4: return i2.get1()[0].toUpperCase(); // OK\n" + >+ " case 5: return i2.get2()[0].toUpperCase(); // problem on array\n" + >+ " default: return \"\";\n" + >+ " }\n" + >+ " }\n" + >+ "}\n" >+ }, >+ getCompilerOptions(), >+ "----------\n" + >+ "1. ERROR in X.java (at line 16)\n" + >+ " case 0: return i1.get0()[0].toUpperCase(); // problem on array\n" + >+ " ^^^^^^^^^\n" + >+ "Potential null pointer access: The method get0() may return null\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 17)\n" + >+ " case 1: return i1.get1()[0].toUpperCase(); // problem on element\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Potential null pointer access: array element may be null\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 18)\n" + >+ " case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + >+ " ^^^^^^^^^\n" + >+ "Potential null pointer access: The method get2() may return null\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 18)\n" + >+ " case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Potential null pointer access: array element may be null\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 19)\n" + >+ " case 3: return i2.get0()[0].toUpperCase(); // problem on element\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Potential null pointer access: array element may be null\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 21)\n" + >+ " case 5: return i2.get2()[0].toUpperCase(); // problem on array\n" + >+ " ^^^^^^^^^\n" + >+ "Potential null pointer access: The method get2() may return null\n" + >+ "----------\n"); >+} > public void testBug434600() { > runConformTestWithLibs( > new String[] { >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java >index 6b68f8d..151ab19 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java >@@ -242,7 +242,7 @@ > if (annot != null) { > // only get here if exactly one of @NonNull or @Nullable was hinted; now apply this hint: > for (int i = 0; i < boundTypes.length; i++) >- boundTypes[i] = environment.createAnnotatedType(boundTypes[i], annot); >+ boundTypes[i] = environment.createAnnotatedType(boundTypes[i].unannotated(true), annot); > } > } > } >@@ -270,7 +270,7 @@ > AnnotationBinding[] annot = environment.nullAnnotationsFromTagBits(nullHints); > if (annot != null) > // only get here if exactly one of @NonNull or @Nullable was hinted; now apply this hint: >- return environment.createAnnotatedType(type, annot); >+ return environment.createAnnotatedType(type.unannotated(true), annot); > return type; > } > public void setInstantiation(TypeBinding type, InferenceVariable variable, LookupEnvironment environment) { >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java >index 8aa7be9..d13a28c 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java >@@ -883,17 +883,7 @@ > if (removeOnlyNullAnnotations) { > ReferenceBinding unannotatedGenericType = (ReferenceBinding) this.environment.getUnannotatedType(this.type); > AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(this.typeAnnotations); >- TypeBinding[] newArguments = null; >- if (this.arguments != null) { >- newArguments = new TypeBinding[this.arguments.length]; >- for (int i = 0; i < this.arguments.length; i++) { >- newArguments[i] = this.arguments[i].unannotated(removeOnlyNullAnnotations); >- } >- } >- ReferenceBinding newEnclosing = null; >- if (this.enclosingType != null) >- newEnclosing = (ReferenceBinding)this.enclosingType.unannotated(removeOnlyNullAnnotations); >- return this.environment.createParameterizedType(unannotatedGenericType, newArguments, newEnclosing, newAnnotations); >+ return this.environment.createParameterizedType(unannotatedGenericType, this.arguments , this.enclosingType, newAnnotations); > } > return this.environment.getUnannotatedType(this); > } >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java >index 259b3c4..b937141 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java >@@ -88,10 +88,7 @@ > if (removeOnlyNullAnnotations) { > ReferenceBinding unannotatedGenericType = (ReferenceBinding) this.environment.getUnannotatedType(this.genericType()); > AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(this.typeAnnotations); >- ReferenceBinding newEnclosing = null; >- if (this.enclosingType() != null) >- newEnclosing = (ReferenceBinding)this.enclosingType().unannotated(removeOnlyNullAnnotations); >- return this.environment.createRawType(unannotatedGenericType, newEnclosing, newAnnotations); >+ return this.environment.createRawType(unannotatedGenericType, this.enclosingType(), newAnnotations); > } > return this.environment.getUnannotatedType(this); > }
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 441338
: 245800