Skip to content

Commit 541883b

Browse files
committed
more
1 parent 93a80d9 commit 541883b

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

nullaway/src/main/java/com/uber/nullaway/NullAway.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package com.uber.nullaway;
2424

25+
import static com.google.common.base.Verify.verify;
2526
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
2627
import static com.sun.source.tree.Tree.Kind.OTHER;
2728
import static com.uber.nullaway.ASTHelpersBackports.hasDirectAnnotationWithSimpleName;
@@ -35,7 +36,6 @@
3536

3637
import com.google.auto.service.AutoService;
3738
import com.google.auto.value.AutoValue;
38-
import com.google.common.base.Verify;
3939
import com.google.common.collect.ImmutableList;
4040
import com.google.common.collect.ImmutableMultimap;
4141
import com.google.common.collect.ImmutableSet;
@@ -446,7 +446,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
446446

447447
private static Symbol.MethodSymbol getSymbolForMethodInvocation(MethodInvocationTree tree) {
448448
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
449-
Verify.verify(methodSymbol != null, "not expecting unresolved method here");
449+
verify(methodSymbol != null, "not expecting unresolved method here");
450450
// In certain cases, we need to get the base symbol for the method rather than the symbol
451451
// attached to the call.
452452
// For interface methods, if the method is an implicit method corresponding to a method from
@@ -2723,11 +2723,20 @@ private boolean mayBeNullMethodCall(
27232723
// NOTE: we cannot rely on state.getPath() here to get a TreePath to the invocation, since
27242724
// sometimes the invocation is a sub-node of the leaf of the path. So, here if inference runs,
27252725
// it will do so without an assignment context. If this becomes a problem, we can revisit
2726-
if (config.isJSpecifyMode()
2727-
&& genericsChecks
2728-
.getGenericReturnNullnessAtInvocation(exprSymbol, invocationTree, null, state, false)
2729-
.equals(Nullness.NULLABLE)) {
2730-
return true;
2726+
if (config.isJSpecifyMode() && exprSymbol.getReturnType().getKind().equals(TypeKind.TYPEVAR)) {
2727+
TreePath path = state.getPath();
2728+
var invocationPath = TreePath.getPath(path, invocationTree);
2729+
verify(
2730+
invocationPath != null,
2731+
"%s not found as a descendant of %s",
2732+
invocationTree,
2733+
path.getLeaf());
2734+
if (genericsChecks
2735+
.getGenericReturnNullnessAtInvocation(
2736+
exprSymbol, invocationTree, invocationPath, state, false)
2737+
.equals(Nullness.NULLABLE)) {
2738+
return true;
2739+
}
27312740
}
27322741
return false;
27332742
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ public void inferenceFromDataflow() {
12991299
" // to ensure that dataflow runs",
13001300
" Object x = new Object(); x.toString();",
13011301
" Object y = null;",
1302-
" // BUG: Diagnostic contains: returning @Nullable expression from method with @NonNull return type",
1302+
" // BUG: Diagnostic contains: passing @Nullable parameter 'y' where @NonNull is required",
13031303
" return (((id(y))));",
13041304
" }",
13051305
" static Object testReturnNested() {",

0 commit comments

Comments
 (0)