Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
d804e2e
WIP
msridhar Jan 6, 2026
2c9c3f1
tweaks
msridhar Jan 6, 2026
a5ee613
Merge branch 'master' into lambda-poly-expression
msridhar Jan 6, 2026
808fb74
tweak
msridhar Jan 6, 2026
642a623
refactor
msridhar Jan 6, 2026
b6cb584
fix test case
msridhar Jan 6, 2026
cd9a4e3
Merge branch 'master' into lambda-poly-expression
msridhar Jan 7, 2026
3a36420
WIP
msridhar Jan 7, 2026
f528062
bug fix
msridhar Jan 7, 2026
a104dcc
comment and test case for #1307
msridhar Jan 7, 2026
c2c5808
fix nullaway error
msridhar Jan 7, 2026
9cd8239
Merge branch 'master' into method-ref-improve
msridhar Jan 7, 2026
fd64445
improve test
msridhar Jan 7, 2026
cae7447
remove unnecessary code and fix test
msridhar Jan 8, 2026
b84dd93
rename test file and move tests
msridhar Jan 8, 2026
6667ae3
a failing test we will handle in a follow up
msridhar Jan 8, 2026
05ec1ae
tweaks
msridhar Jan 8, 2026
c0031e0
cleanup
msridhar Jan 8, 2026
9a95c56
further cleanup
msridhar Jan 8, 2026
8d47ece
Merge branch 'master' into method-ref-improve
msridhar Jan 11, 2026
1a53741
Merge branch 'master' into method-ref-improve
msridhar Jan 12, 2026
6afc36b
Merge branch 'master' into method-ref-improve
msridhar Jan 13, 2026
468c520
WIP
msridhar Jan 11, 2026
a01a513
Merge branch 'master' into method-ref-generic-inference
msridhar Jan 14, 2026
2d7fa93
failing test
msridhar Jan 14, 2026
d67c661
fix test
msridhar Jan 14, 2026
9091dd1
Merge branch 'master' into method-ref-generic-inference
msridhar Jan 15, 2026
b736fe2
Merge branch 'master' into method-ref-generic-inference
msridhar Jan 15, 2026
fa16569
re-jigger logic
msridhar Jan 18, 2026
741de42
todos
msridhar Jan 18, 2026
fb60aee
WIP
msridhar Jan 19, 2026
ced8cae
WIP
msridhar Jan 19, 2026
029aa72
fix
msridhar Jan 19, 2026
dc1d9aa
complete test
msridhar Jan 19, 2026
659f169
another test
msridhar Jan 19, 2026
2c0cab4
WIP
msridhar Jan 19, 2026
4dfb323
fix test
msridhar Jan 19, 2026
4d50575
more tests
msridhar Jan 20, 2026
93a208d
WIP
msridhar Jan 20, 2026
ac4673b
cleanup and docs
msridhar Jan 20, 2026
ef71582
fix npe
msridhar Jan 20, 2026
6918968
Merge branch 'master' into method-ref-generic-inference
msridhar Jan 23, 2026
c4e25b3
Merge branch 'master' into method-ref-generic-inference
msridhar Jan 25, 2026
a8b1917
Merge branch 'master' into method-ref-generic-inference
msridhar Jan 25, 2026
4abedaf
Merge branch 'master' into method-ref-generic-inference
msridhar Feb 5, 2026
238a3e2
add a test for stream with values mapped to @Nullable; doesn't work yet
msridhar Feb 5, 2026
0e1b7ec
Merge branch 'master' into method-ref-generic-inference
msridhar Feb 5, 2026
1e9ab99
some improvements
msridhar Feb 5, 2026
16942b2
more cleanup
msridhar Feb 5, 2026
28bf098
add issue link
msridhar Feb 5, 2026
c76fbd5
Merge branch 'master' into method-ref-generic-inference
msridhar Feb 9, 2026
b90e54d
Merge branch 'master' into method-ref-generic-inference
msridhar Feb 10, 2026
2f924bb
add comment
msridhar Feb 10, 2026
de6b0ce
cleanup and todos
msridhar Feb 10, 2026
f695f56
test
msridhar Feb 11, 2026
8b4f0d0
another test case
msridhar Feb 12, 2026
3406847
yet another test
msridhar Feb 12, 2026
e2e735c
Add TODO comment
msridhar Feb 12, 2026
23bfde7
another comment
msridhar Feb 12, 2026
9a989da
add issue link
msridhar Feb 12, 2026
839d22c
comment and remove unnecessary check
msridhar Feb 13, 2026
a2d2b5d
test for new bug
msridhar Feb 13, 2026
5ce5c46
initial fix
msridhar Feb 13, 2026
d800190
WIP
msridhar Feb 13, 2026
69914e2
move method
msridhar Feb 14, 2026
5b2b3dd
refactoring and docs
msridhar Feb 14, 2026
93c4820
more cleanup
msridhar Feb 14, 2026
6ecb972
add a contract
msridhar Feb 14, 2026
d7e4772
remove incorrect comment in test
msridhar Feb 14, 2026
724e54c
tweak diagnostic message that is matched on
msridhar Feb 15, 2026
81f844f
Merge branch 'master' into method-ref-generic-inference
msridhar Feb 16, 2026
0fdd94d
review feedback
msridhar Feb 16, 2026
f952e8a
augment tests
msridhar Feb 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename test file and move tests
  • Loading branch information
msridhar committed Jan 8, 2026
commit b84dd931e350d222b68aa13245d6e00be16fb621
2 changes: 1 addition & 1 deletion nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ private Description checkParamOverriding(
functionalInterfaceType = ASTHelpers.getType(memberReferenceTree);
}
} else { // lambdaExpressionTree != null
Objects.requireNonNull(lambdaExpressionTree);
Objects.requireNonNull(lambdaExpressionTree); // to avoid NullAway warning
functionalInterfaceType = genericsChecks.getInferredLambdaType(lambdaExpressionTree);
if (functionalInterfaceType == null) {
functionalInterfaceType = ASTHelpers.getType(lambdaExpressionTree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Arrays;
import org.junit.Test;

public class GenericMethodLambdaArgTests extends NullAwayTestsBase {
public class GenericMethodLambdaOrMethodRefArgTests extends NullAwayTestsBase {

@Test
public void lambdaReturnsGenericMethodCall() {
Expand Down Expand Up @@ -143,104 +143,6 @@ static void test() {
.doTest();
}

@Test
public void genericMethodRefWithNullableReturnTypeArg() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@NullMarked
class Test {
interface Foo {
default @Nullable String get() {
return null;
}
}
@Nullable String createWrapper() {
return create(Foo::get);
}
private <T> @Nullable T create(Function<Foo, @Nullable T> factory) {
return factory.apply(new Foo() {});
}
}
""")
.doTest();
}

@Test
public void genericMethodRefNonNullReturnTypeArgMismatch() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@NullMarked
class Test {
interface Foo {
default String get() {
throw new RuntimeException();
}
default @Nullable String getNullable() {
return null;
}
}
private <T> @Nullable T create(Function<Foo, @Nullable T> factory) {
return factory.apply(new Foo() {});
}
private <T> T createNonNull(Function<Foo, T> factory) {
return factory.apply(new Foo() {});
}
String testPositive() {
// BUG: Diagnostic contains: referenced method returns @Nullable, but functional interface method
return createNonNull(Foo::getNullable);
}
@Nullable String testNegative() {
return create(Foo::get);
}
}
""")
.doTest();
}

@Test
public void methodRefWithArgument() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
class Test {
interface Callback<T extends @Nullable Object> {
void onResult(T thing);
}
void receiver(Callback<@Nullable Object> value) {
}
void target(@Nullable Object thing) {
}
void targetNonNullParam(Object thing) {
}
public <T extends @Nullable Object> Callback<T> makeCancelable(Callback<T> callback) {
return callback;
}
void testNegative() {
receiver(makeCancelable(this::target));
}
void testPositive() {
// BUG: Diagnostic contains: parameter thing of referenced method is @NonNull, but parameter in functional interface method
receiver(makeCancelable(this::targetNonNullParam));
}
}
""")
.doTest();
}

@Test
public void lambdaWithReturnStmtNullable() {
makeHelperWithInferenceFailureWarning()
Expand Down Expand Up @@ -376,6 +278,105 @@ void use() {
.doTest();
}

@Test
public void methodRefWithMatchingReturnNullability() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@NullMarked
class Test {
interface Foo {
default @Nullable String get() {
return null;
}
}
@Nullable String createWrapper() {
return create(Foo::get);
}
private <T> @Nullable T create(Function<Foo, @Nullable T> factory) {
return factory.apply(new Foo() {});
}
}
""")
.doTest();
}

@Test
public void methodRefWithDifferentReturnNullability() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@NullMarked
class Test {
interface Foo {
default String get() {
throw new RuntimeException();
}
default @Nullable String getNullable() {
return null;
}
}
private <T> @Nullable T create(Function<Foo, @Nullable T> factory) {
return factory.apply(new Foo() {});
}
private <T> T createNonNull(Function<Foo, T> factory) {
return factory.apply(new Foo() {});
}
String testPositive() {
// BUG: Diagnostic contains: referenced method returns @Nullable, but functional interface method
return createNonNull(Foo::getNullable);
}
@Nullable String testNegative() {
// Expecting a Function returning @Nullable and Foo::get returns @NonNull, which is safe
return create(Foo::get);
}
}
""")
.doTest();
}

@Test
public void methodRefWithArgument() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
class Test {
interface Callback<T extends @Nullable Object> {
void onResult(T thing);
}
void receiver(Callback<@Nullable Object> value) {
}
void target(@Nullable Object thing) {
}
void targetNonNullParam(Object thing) {
}
public <T extends @Nullable Object> Callback<T> makeCancelable(Callback<T> callback) {
return callback;
}
void testNegative() {
receiver(makeCancelable(this::target));
}
void testPositive() {
// BUG: Diagnostic contains: parameter thing of referenced method is @NonNull, but parameter in functional interface method
receiver(makeCancelable(this::targetNonNullParam));
}
}
""")
.doTest();
}

private CompilationTestHelper makeHelperWithInferenceFailureWarning() {
return makeTestHelperWithArgs(
JSpecifyJavacConfig.withJSpecifyModeArgs(
Expand Down