Skip to content

Commit dc60573

Browse files
authored
Test case for #1528 (#1556)
Fixes #1528 Add a test case to ensure we handle this case correctly. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added regression test to enhance validation of nullability inference with generic method type parameters and method references. The test specifically covers stream operations combined with wildcard type parameters, strengthening test coverage for complex type inference scenarios and improving overall quality assurance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent da3cc0d commit dc60573

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodLambdaOrMethodRefArgTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,48 @@ static Map<String,String> test(Map<String,String> map) {
963963
.doTest();
964964
}
965965

966+
@Test
967+
public void issue1528() {
968+
makeHelperWithInferenceFailureWarning()
969+
.addSourceLines(
970+
"Test.java",
971+
"""
972+
import org.jspecify.annotations.NullMarked;
973+
import org.jspecify.annotations.Nullable;
974+
import java.util.Map;
975+
import java.util.function.Function;
976+
import java.util.stream.Stream;
977+
@NullMarked
978+
class Test {
979+
<T> Test and(Stream<T> stream, Function<T, @Nullable Pair> mapper) {
980+
return this;
981+
}
982+
static class Pair {
983+
private final String name;
984+
private final @Nullable String value;
985+
private Pair(String name, @Nullable String value) {
986+
this.name = name;
987+
this.value = value;
988+
}
989+
static Pair fromMapEntry(Map.Entry<String, @Nullable String> entry) {
990+
return new Pair(entry.getKey(), entry.getValue());
991+
}
992+
static Pair fromMapEntryWildcard(Map.Entry<String, ? extends @Nullable String> entry) {
993+
return new Pair(entry.getKey(), entry.getValue());
994+
}
995+
}
996+
Test and(Map<String, String> map) {
997+
// BUG: Diagnostic contains: parameter type of referenced method is Entry<String, @Nullable String>
998+
return and(map.entrySet().stream(), Pair::fromMapEntry);
999+
}
1000+
Test andWildcard(Map<String, String> map) {
1001+
return and(map.entrySet().stream(), Pair::fromMapEntryWildcard);
1002+
}
1003+
}
1004+
""")
1005+
.doTest();
1006+
}
1007+
9661008
@Test
9671009
public void genericMethodLambdaArgWildCard() {
9681010
makeHelperWithInferenceFailureWarning()

0 commit comments

Comments
 (0)