Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2012-02-07 16:30:51 +0000
committerStephan Herrmann2012-02-07 16:30:51 +0000
commit1e74708f239861b45ea9c03fb332142e9b5b54a5 (patch)
tree14b93b3d191398e9c1b461be57425d0ccba3f348
parentd06dca3193608aaecf6a0ecc6e783a566d9a941e (diff)
downloadeclipse.jdt.core-sherrmann/NullAnnotationsForFields.tar.gz
eclipse.jdt.core-sherrmann/NullAnnotationsForFields.tar.xz
eclipse.jdt.core-sherrmann/NullAnnotationsForFields.zip
Revert source-range part of commitsherrmann/NullAnnotationsForFields
0b82fa47eb78f9f59638ad9671b3e2a9d9c28ff6 on behalf of https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649#c11
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java35
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Reference.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java12
5 files changed, 52 insertions, 7 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 0377374ec6..8320f62e58 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
@@ -53,7 +53,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[] { "test_default_nullness_017" };
+// TESTS_NAMES = new String[] { "test_nullable_field_3" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
@@ -3891,6 +3891,39 @@ public void test_nullable_field_3() {
"Potential null pointer access: The field o is declared as @Nullable\n" +
"----------\n");
}
+// access to a nullable field - qualified name reference - multiple segments
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649
+public void test_nullable_field_3m() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " @Nullable Object o = new Object();\n" +
+ " @Nullable X other;\n" +
+ " public String oString() {\n" +
+ " return other.other.o.toString();\n" +
+ " }\n" +
+ "}\n"
+ },
+ null /*customOptions*/,
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " return other.other.o.toString();\n" +
+ " ^^^^^\n" +
+ "Potential null pointer access: The field other is declared as @Nullable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " return other.other.o.toString();\n" +
+ " ^^^^^\n" +
+ "Potential null pointer access: The field other is declared as @Nullable\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 6)\n" +
+ " return other.other.o.toString();\n" +
+ " ^\n" +
+ "Potential null pointer access: The field o is declared as @Nullable\n" +
+ "----------\n");
+}
// access to a nullable field - dereference after check
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649
public void test_nullable_field_4() {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
index 99307fdbde..a4c2e6f396 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
@@ -159,7 +159,7 @@ public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flow
if (super.checkNPE(scope, flowContext, flowInfo)) return true;
if (!this.receiver.isThis()) {
// on a non-this field ref @Nullable is all we could possibly report
- return checkNullableDereference(scope, this.binding);
+ return checkNullableDereference(scope, this.binding, this.nameSourcePosition);
}
return false; // not checked
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java
index 786dc1bae4..e5ff6cc4a0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java
@@ -255,12 +255,12 @@ private void checkInternalNPE(BlockScope scope, FlowContext flowContext, FlowInf
if (this.otherBindings != null) {
if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.FIELD) {
// is the first field dereferenced annotated Nullable? If so, report immediately
- checkNullableDereference(scope, (FieldBinding) this.binding);
+ checkNullableDereference(scope, (FieldBinding) this.binding, this.sourcePositions[0]);
}
// look for annotated fields, they do not depend on flow context -> check immediately:
int length = this.otherBindings.length - 1; // don't check the last binding
for (int i = 0; i < length; i++) {
- checkNullableDereference(scope, this.otherBindings[i]);
+ checkNullableDereference(scope, this.otherBindings[i], this.sourcePositions[i+1]);
}
}
}
@@ -281,7 +281,7 @@ public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flow
position = this.sourcePositions[this.sourcePositions.length - 1];
}
if (fieldBinding != null) {
- return checkNullableDereference(scope, fieldBinding);
+ return checkNullableDereference(scope, fieldBinding, position);
}
return false;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Reference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Reference.java
index 6782e1b9f6..3cba3379e3 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Reference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Reference.java
@@ -39,9 +39,9 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
return flowInfo;
}
-protected boolean checkNullableDereference(Scope scope, FieldBinding field) {
+protected boolean checkNullableDereference(Scope scope, FieldBinding field, long sourcePosition) {
if ((field.tagBits & TagBits.AnnotationNullable) != 0) {
- scope.problemReporter().variablePotentialNullReference(field, this);
+ scope.problemReporter().nullableFieldDereference(field, sourcePosition);
return true;
}
return false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 37647b295c..ed8eb0f486 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -5292,6 +5292,18 @@ public void variablePotentialNullReference(VariableBinding variable, ASTNode loc
nodeSourceEnd(variable, location));
}
+public void nullableFieldDereference(VariableBinding variable, long position) {
+ String[] arguments = new String[] {new String(variable.name)};
+ char[][] nullableName = this.options.nullableAnnotationName;
+ arguments = new String[] {new String(variable.name), new String(nullableName[nullableName.length-1])};
+ this.handle(
+ IProblem.NullableFieldReference,
+ arguments,
+ arguments,
+ (int)(position >>> 32),
+ (int)(position));
+}
+
public void variableRedundantCheckOnNonNull(VariableBinding variable, ASTNode location) {
int problem;
if (variable instanceof FieldBinding) {

Back to the top