Skip to content

Commit

Permalink
handle forEach on Iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Apr 25, 2024
1 parent 0b46478 commit beab844
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -33,6 +33,9 @@ public class SynchronousCallbackHandler extends BaseNoOpHandler {
MethodRef.methodRef(
"java.util.Map",
"forEach(java.util.function.BiConsumer<? super K,? super V>)"),
0,
MethodRef.methodRef(
"java.lang.Iterable", "forEach(java.util.function.Consumer<? super T>)"),
0),
"removeIf",
ImmutableMap.of(
Expand Down
24 changes: 24 additions & 0 deletions nullaway/src/test/java/com/uber/nullaway/SyncLambdasTests.java
Expand Up @@ -90,6 +90,30 @@ public void otherForEach() {
.doTest();
}

@Test
public void forEachOnIterable() {
defaultCompilationHelper
.addSourceLines(
"Test.java",
"package com.uber;",
"import java.util.List;",
"import java.util.ArrayList;",
"import org.jspecify.annotations.Nullable;",
"public class Test {",
" private @Nullable Object f;",
" public void test1() {",
" if (this.f == null) {",
" throw new IllegalArgumentException();",
" }",
" List<Object> l = new ArrayList<>();",
" l.forEach(v -> System.out.println(v + this.f.toString()));",
" Iterable<Object> l2 = l;",
" l2.forEach(v -> System.out.println(v + this.f.toString()));",
" }",
"}")
.doTest();
}

@Test
public void removeIf() {
defaultCompilationHelper
Expand Down

0 comments on commit beab844

Please sign in to comment.