|
22 | 22 |
|
23 | 23 | package com.uber.nullaway; |
24 | 24 |
|
| 25 | +import static com.google.common.base.Verify.verify; |
25 | 26 | import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
26 | 27 | import static com.sun.source.tree.Tree.Kind.OTHER; |
27 | 28 | import static com.uber.nullaway.ASTHelpersBackports.hasDirectAnnotationWithSimpleName; |
|
35 | 36 |
|
36 | 37 | import com.google.auto.service.AutoService; |
37 | 38 | import com.google.auto.value.AutoValue; |
38 | | -import com.google.common.base.Verify; |
39 | 39 | import com.google.common.collect.ImmutableList; |
40 | 40 | import com.google.common.collect.ImmutableMultimap; |
41 | 41 | import com.google.common.collect.ImmutableSet; |
@@ -446,7 +446,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState |
446 | 446 |
|
447 | 447 | private static Symbol.MethodSymbol getSymbolForMethodInvocation(MethodInvocationTree tree) { |
448 | 448 | 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"); |
450 | 450 | // In certain cases, we need to get the base symbol for the method rather than the symbol |
451 | 451 | // attached to the call. |
452 | 452 | // For interface methods, if the method is an implicit method corresponding to a method from |
@@ -2723,11 +2723,20 @@ private boolean mayBeNullMethodCall( |
2723 | 2723 | // NOTE: we cannot rely on state.getPath() here to get a TreePath to the invocation, since |
2724 | 2724 | // sometimes the invocation is a sub-node of the leaf of the path. So, here if inference runs, |
2725 | 2725 | // 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 | + } |
2731 | 2740 | } |
2732 | 2741 | return false; |
2733 | 2742 | } |
|
0 commit comments