Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSpecify: handling the return of a diamond operator anonymous object method caller #858

Merged
11 changes: 7 additions & 4 deletions nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,13 @@ public static Nullness getGenericReturnNullnessAtInvocation(
return Nullness.NONNULL;
}
Type methodReceiverType =
castToNonNull(
getTreeType(((MemberSelectTree) tree.getMethodSelect()).getExpression(), state));
return getGenericMethodReturnTypeNullness(
invokedMethodSymbol, methodReceiverType, state, config);
getTreeType(((MemberSelectTree) tree.getMethodSelect()).getExpression(), state);
if (methodReceiverType == null) {
return Nullness.NONNULL;
} else {
return getGenericMethodReturnTypeNullness(
invokedMethodSymbol, methodReceiverType, state, config);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,24 @@ public void testForStaticMethodCallAsAParam() {
.doTest();
}

@Test
public void testForDiamondOperatorReturnedAsAMethodCaller() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" static class B<T>{",
" String build(){return \"x\";}",
" }",
" static String testNegative() {",
" return new B<>().build();",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down