Skip to content

Commit ef71582

Browse files
committed
fix npe
1 parent ac4673b commit ef71582

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ private void handleMethodRefInGenericMethodInference(
948948
if (!referencedMethod.isStatic()) {
949949
// get the referenced method type as a member of the type of the qualifier expression
950950
qualifierType = getTreeType(memberReferenceTree.getQualifierExpression(), state);
951-
if (qualifierType != null && !qualifierType.isRaw()) {
951+
if (qualifierType != null) {
952952
referencedMethodType =
953953
TypeSubstitutionUtils.memberType(types, qualifierType, referencedMethod, config)
954954
.asMethodType();
@@ -996,8 +996,10 @@ private void handleMethodRefInGenericMethodInference(
996996
!fiParamTypes.isEmpty(),
997997
"Expected receiver parameter for unbound method ref %s",
998998
memberReferenceTree);
999-
Type receiverType = fiParamTypes.get(0);
1000-
solver.addSubtypeConstraint(receiverType, castToNonNull(qualifierType), false);
999+
if (qualifierType != null) {
1000+
Type receiverType = fiParamTypes.get(0);
1001+
solver.addSubtypeConstraint(receiverType, qualifierType, false);
1002+
}
10011003
fiStartIndex = 1;
10021004
}
10031005
if (fiParamTypes.size() - fiStartIndex != referencedParamTypes.size()) {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,30 @@ void testConsumeExplicitTypeArgs(Box<Integer> box, String sNonNull, @Nullable St
573573
.doTest();
574574
}
575575

576+
@Test
577+
public void mapStream() {
578+
makeHelperWithInferenceFailureWarning()
579+
.addSourceLines(
580+
"Test.java",
581+
"""
582+
import org.jspecify.annotations.NullMarked;
583+
import org.jspecify.annotations.Nullable;
584+
import java.util.Map;
585+
import java.util.stream.Collectors;
586+
@NullMarked
587+
class Test {
588+
static Map<String,String> test(Map<String,String> map) {
589+
return map.entrySet().stream()
590+
.collect(
591+
Collectors.toMap(
592+
Map.Entry::getKey,
593+
Map.Entry::getValue));
594+
}
595+
}
596+
""")
597+
.doTest();
598+
}
599+
576600
private CompilationTestHelper makeHelperWithInferenceFailureWarning() {
577601
return makeTestHelperWithArgs(
578602
JSpecifyJavacConfig.withJSpecifyModeArgs(

0 commit comments

Comments
 (0)