Skip to content

Commit

Permalink
java.util.Iterable -> lang
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 573247079
  • Loading branch information
graememorgan authored and Error Prone Team committed Oct 13, 2023
1 parent 1c62a56 commit 53f24d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final class HeldLockAnalyzer {
.onDescendantOf("java.util.Map")
.namedAnyOf("forEach", "replaceAll", "computeIfAbsent", "computeIfPresent", "merge"),
instanceMethod().onDescendantOf("java.util.List").named("replaceAll"),
instanceMethod().onDescendantOf("java.util.Iterable").named("forEach"),
instanceMethod().onDescendantOf("java.lang.Iterable").named("forEach"),
instanceMethod().onDescendantOf("java.util.Iterator").named("forEachRemaining"),
staticMethod()
.onClass("com.google.common.collect.Iterables")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1963,4 +1963,20 @@ public void methodReference_referencedMethodIsFlagged() {
"}")
.doTest();
}

@Test
public void lambdaMethodInvokedImmediately_shouldNotBeFlagged() {
compilationHelper
.addSourceLines(
"Test.java",
"import java.util.List;",
"import javax.annotation.concurrent.GuardedBy;",
"class Test {",
" @GuardedBy(\"this\") private final Object o = new Object();",
" public synchronized void test(List<?> xs) {",
" xs.forEach(x -> o.toString());",
" }",
"}")
.doTest();
}
}

0 comments on commit 53f24d4

Please sign in to comment.