Skip to content

Commit 059b90b

Browse files
authored
Don't check synchronized blocks within unannotated code (#1185)
Fixes #1184 We forgot to add the standard check for unannotated code to `matchSynchronized`
1 parent 03dc42d commit 059b90b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

nullaway/src/main/java/com/uber/nullaway/NullAway.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,9 @@ public Description matchEnhancedForLoop(EnhancedForLoopTree tree, VisitorState s
17981798

17991799
@Override
18001800
public Description matchSynchronized(SynchronizedTree tree, VisitorState state) {
1801+
if (!withinAnnotatedCode(state)) {
1802+
return Description.NO_MATCH;
1803+
}
18011804
ExpressionTree lockExpr = tree.getExpression();
18021805
// For a synchronized block `synchronized (e) { ... }`, javac returns `(e)` as the expression.
18031806
// We strip the outermost parentheses for a nicer-looking error message.

nullaway/src/test/java/com/uber/nullaway/CoreTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,4 +1118,20 @@ public void synchronizedDeref() {
11181118
"}")
11191119
.doTest();
11201120
}
1121+
1122+
@Test
1123+
public void synchronizedInUnannotatedLambda() {
1124+
defaultCompilationHelper
1125+
.addSourceLines(
1126+
"Foo.java",
1127+
"public class Foo {",
1128+
" void foo() {",
1129+
" Runnable runnable = () -> {",
1130+
" Object lock = new Object();",
1131+
" synchronized (lock) {}",
1132+
" };",
1133+
" }",
1134+
"}")
1135+
.doTest();
1136+
}
11211137
}

0 commit comments

Comments
 (0)