aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2012-09-06 12:50:38 (EDT)
committerJayaprakash Arthanareeswaran2012-10-09 02:58:25 (EDT)
commitb604f90cdbfce3d0c990b100eefed2eb9778e66a (patch)
treef1db7c0cef39f796a65ee77aaae53f31dc28ed30
parent789eeb90ee0e4a5b167be3db70baae047d8e7b39 (diff)
downloadeclipse.jdt.core-b604f90cdbfce3d0c990b100eefed2eb9778e66a.zip
eclipse.jdt.core-b604f90cdbfce3d0c990b100eefed2eb9778e66a.tar.gz
eclipse.jdt.core-b604f90cdbfce3d0c990b100eefed2eb9778e66a.tar.bz2
Bug 388630 - @NonNull diagnostics at line 0
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java58
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java10
2 files changed, 66 insertions, 2 deletions
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 b318258..a6a04bb 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
@@ -52,7 +52,7 @@ public NullAnnotationTest(String name) {
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which do not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "testBug385626" };
+// TESTS_NAMES = new String[] { "testBug388630" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
@@ -3706,4 +3706,60 @@ public void testBug385626_2() {
null,//options
"");
}
+
+// Bug 388630 - @NonNull diagnostics at line 0
+// synthetic constructor must repeat null annotations of its super
+public void testBug388630_1() {
+ runConformTestWithLibs(
+ new String[] {
+ "C0.java",
+ "import org.eclipse.jdt.annotation.NonNull;\n" +
+ "public class C0 {\n" +
+ " C0 (@NonNull Object o) { }\n" +
+ " void test() { }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " new C0(\"\") { }.test();\n" +
+ " }\n" +
+ "}\n"
+ },
+ null,
+ "");
+}
+
+// Bug 388630 - @NonNull diagnostics at line 0
+// additionally also references to outer variables must share their nullness
+public void testBug388630_2() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "C0.java",
+ "import org.eclipse.jdt.annotation.NonNull;\n" +
+ "public class C0 {\n" +
+ " C0 (@NonNull Object o) { }\n" +
+ " void test() { }\n" +
+ "}\n",
+ "X.java",
+ "import org.eclipse.jdt.annotation.Nullable;\n" +
+ "public class X {\n" +
+ " void foo(final @Nullable Object a) {\n" +
+ " new C0(\"\") {\n" +
+ " @Override\n" +
+ " void test() {\n" +
+ " System.out.println(a.toString());\n" +
+ " super.test();\n" +
+ " }\n" +
+ " }.test();\n" +
+ " }\n" +
+ "}\n"
+ },
+ null,
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " System.out.println(a.toString());\n" +
+ " ^\n" +
+ "Potential null pointer access: The variable a may be null at this location\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
index d239691..fa7da68 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
@@ -11,7 +11,9 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann - Contribution for Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop)
+ * Stephan Herrmann - Contributions for
+ * Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop)
+ * Bug 388630 - @NonNull diagnostics at line 0
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -412,6 +414,12 @@ public MethodBinding createDefaultConstructorWithBinding(MethodBinding inherited
sourceType); //declaringClass
constructor.binding.tagBits |= (inheritedConstructorBinding.tagBits & TagBits.HasMissingType);
constructor.binding.modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor;
+ if (inheritedConstructorBinding.parameterNonNullness != null) { // this implies that annotation based null analysis is enabled
+ // copy nullness info from inherited constructor to the new constructor:
+ int len = inheritedConstructorBinding.parameterNonNullness.length;
+ System.arraycopy(inheritedConstructorBinding.parameterNonNullness, 0,
+ constructor.binding.parameterNonNullness = new Boolean[len], 0, len);
+ }
constructor.scope = new MethodScope(this.scope, constructor, true);
constructor.bindArguments();