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 208637 Details for
Bug 367203
[compiler][null] detect assigning null to nonnull argument
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
tests & fix
Bug_367203.patch (text/plain), 4.59 KB, created by
Stephan Herrmann
on 2011-12-20 13:03:25 EST
(
hide
)
Description:
tests & fix
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2011-12-20 13:03:25 EST
Size:
4.59 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java >index 385b9c2..0a8af6b 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java >@@ -655,6 +655,55 @@ > this.LIBS, > true /* shouldFlush*/); > } >+// Bug 367203 - [compiler][null] detect assigning null to nonnull argument >+public void test_nonnull_argument_001() { >+ runNegativeTestWithLibs( >+ new String[] { >+ "ShowNPE2.java", >+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + >+ "@NonNullByDefault\n" + >+ "public class ShowNPE2 {\n" + >+ " public Object foo(Object o1, final boolean b) {\n" + >+ " o1 = null; // expect NPE error\n" + >+ " System.out.println(o1.toString()); \n" + >+ " return null; // expect NPE error\n" + >+ " }\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in ShowNPE2.java (at line 5)\n" + >+ " o1 = null; // expect NPE error\n" + >+ " ^^^^\n" + >+ "Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + >+ "----------\n" + >+ "2. ERROR in ShowNPE2.java (at line 7)\n" + >+ " return null; // expect NPE error\n" + >+ " ^^^^\n" + >+ "Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + >+ "----------\n"); >+} >+// Bug 367203 - [compiler][null] detect assigning null to nonnull argument >+public void test_nonnull_argument_002() { >+ runNegativeTestWithLibs( >+ new String[] { >+ "ShowNPE2.java", >+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + >+ "@NonNullByDefault\n" + >+ "public class ShowNPE2 {\n" + >+ " public Object foo(Object o1, final boolean b) {\n" + >+ " bar(o1); // expecting no problem\n" + >+ " return null; // expect NPE error\n" + >+ " }\n" + >+ " void bar(Object o2) {}\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in ShowNPE2.java (at line 6)\n" + >+ " return null; // expect NPE error\n" + >+ " ^^^^\n" + >+ "Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + >+ "----------\n"); >+} > // assigning potential null to a nonnull local variable > public void test_nonnull_local_001() { > runNegativeTest( >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java >index f6d98fd..e00530b 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java >@@ -83,8 +83,7 @@ > * Materialize a null parameter annotation that has been added from the current default, > * in order to ensure that this annotation will be generated into the .class file, too. > */ >- public void addParameterNonNullAnnotation(int i, ReferenceBinding annotationBinding) { >- Argument argument = this.arguments[i]; >+ public void addParameterNonNullAnnotation(Argument argument, ReferenceBinding annotationBinding) { > if (argument.type != null) // null happens for constructors of anonymous classes > argument.annotations = addAnnotation(argument.type, argument.annotations, annotationBinding); > } >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java >index 0e1140d..34d41d5 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java >@@ -458,8 +458,11 @@ > if (this.parameterNonNullness[i] == null) { > added = true; > this.parameterNonNullness[i] = Boolean.TRUE; >- if (sourceMethod != null) >- sourceMethod.addParameterNonNullAnnotation(i, (ReferenceBinding)annotationBinding); >+ if (sourceMethod != null) { >+ Argument argument = sourceMethod.arguments[i]; >+ sourceMethod.addParameterNonNullAnnotation(argument, (ReferenceBinding)annotationBinding); >+ argument.binding.tagBits |= TagBits.AnnotationNonNull; >+ } > } else if (this.parameterNonNullness[i].booleanValue()) { > sourceMethod.scope.problemReporter().nullAnnotationIsRedundant(sourceMethod, i); > }
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 367203
: 208637