diff options
author | Till Brychcy | 2019-07-10 18:32:09 +0000 |
---|---|---|
committer | Till Brychcy | 2019-07-13 09:23:48 +0000 |
commit | c39e93d0aacaff957f2885c7bda1cc96ea144b8b (patch) | |
tree | 527e4c83ba2d7b87b631dd7134c148e47800f246 | |
parent | 98197a6e247571eb5aaa4483ec70e8deece6d6e8 (diff) | |
download | eclipse.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
Change-Id: Id68f5a075fbfc40024c8ef345dcd4e95419d31f0
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); |