Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2019-07-10 18:32:09 +0000
committerTill Brychcy2019-07-13 09:23:48 +0000
commitc39e93d0aacaff957f2885c7bda1cc96ea144b8b (patch)
tree527e4c83ba2d7b87b631dd7134c148e47800f246
parent98197a6e247571eb5aaa4483ec70e8deece6d6e8 (diff)
downloadeclipse.jdt.core-c39e93d0aacaff957f2885c7bda1cc96ea144b8b.tar.gz
eclipse.jdt.core-c39e93d0aacaff957f2885c7bda1cc96ea144b8b.tar.xz
eclipse.jdt.core-c39e93d0aacaff957f2885c7bda1cc96ea144b8b.zip
Bug 544872 - Enable Null Analysis detection on synchronized statementsI20190713-1105
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java23
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java6
2 files changed, 28 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index 8649fd72dd..df38525833 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -18265,4 +18265,27 @@ public void testBug542707_1() {
"----------\n";
runner.runNegativeTest();
}
+public void testBug544872() {
+ runNegativeNullTest(
+ new String[] {
+ "Test.java",
+ "public class Test {\n" +
+ " static void f(String string) {\n" +
+ " if (string != null)\n" +
+ " string.hashCode();\n" +
+ " synchronized (string) {\n" +
+ " string.hashCode();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ },
+ "----------\n" +
+ "1. ERROR in Test.java (at line 5)\n" +
+ " synchronized (string) {\n" +
+ " ^^^^^^\n" +
+ "Potential null pointer access: The variable string may be null at this location\n" +
+ "----------\n"
+ );
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java
index 0d03db8f04..d6465cb9cf 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java
@@ -59,11 +59,15 @@ public FlowInfo analyseCode(
this.synchroVariable.useFlag = LocalVariableBinding.USED;
// simple propagation to subnodes
+ FlowInfo expressionFlowInfo = this.expression.analyseCode(this.scope, flowContext, flowInfo);
+
+ this.expression.checkNPE(currentScope, flowContext, expressionFlowInfo, 1);
+
flowInfo =
this.block.analyseCode(
this.scope,
new InsideSubRoutineFlowContext(flowContext, this),
- this.expression.analyseCode(this.scope, flowContext, flowInfo));
+ expressionFlowInfo);
this.mergedSynchronizedInitStateIndex =
currentScope.methodScope().recordInitializationStates(flowInfo);

Back to the top