From b0f319943a986058c80c8001b8693d7bdbc2ac4e Mon Sep 17 00:00:00 2001 From: ghm Date: Fri, 13 Oct 2023 09:15:15 -0700 Subject: [PATCH] java.util.Iterable -> lang PiperOrigin-RevId: 573238377 --- .../threadsafety/HeldLockAnalyzer.java | 2 +- .../threadsafety/GuardedByCheckerTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/HeldLockAnalyzer.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/HeldLockAnalyzer.java index 0ac30e84b6a5..26b04ef9326e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/HeldLockAnalyzer.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/HeldLockAnalyzer.java @@ -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") diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByCheckerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByCheckerTest.java index 28b6653936fa..e402075294fc 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByCheckerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByCheckerTest.java @@ -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(); + } }