diff --git a/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java index ce31aebbef..f91b01cd70 100644 --- a/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java @@ -15,6 +15,7 @@ import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.ConditionalExpressionTree; import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MemberReferenceTree; import com.sun.source.tree.MemberSelectTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.MethodTree; @@ -876,9 +877,13 @@ public static Nullness getGenericMethodParameterNullness( int parameterIndex, Symbol.MethodSymbol method, Symbol enclosingSymbol, + @Nullable MemberReferenceTree memberReferenceTree, VisitorState state, Config config) { - Type enclosingType = getTypeForSymbol(enclosingSymbol, state); + Type enclosingType = + (memberReferenceTree != null) + ? ASTHelpers.getType(memberReferenceTree) + : getTypeForSymbol(enclosingSymbol, state); if (enclosingType == null) { // we have no additional information from generics, so return NONNULL (presence of a @Nullable // annotation should have been handled by the caller) @@ -889,8 +894,8 @@ public static Nullness getGenericMethodParameterNullness( /** * Just like {@link #getGenericMethodParameterNullness(int, Symbol.MethodSymbol, Symbol, - * VisitorState, Config)}, but takes the enclosing {@code Type} rather than the enclosing {@code - * Symbol}. + * MemberReferenceTree, VisitorState, Config)}, but takes the enclosing {@code Type} rather than + * the enclosing {@code Symbol}. * * @param parameterIndex index of the parameter * @param method the generic method diff --git a/nullaway/src/main/java/com/uber/nullaway/NullAway.java b/nullaway/src/main/java/com/uber/nullaway/NullAway.java index 79c7c8ca34..8bbe51642e 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullAway.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullAway.java @@ -739,6 +739,7 @@ private Description checkParamOverriding( i, overriddenMethod, overridingParamSymbols.get(i).owner.owner, + memberReferenceTree, state, config) : Nullness.NONNULL); diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java index 7f236cacfd..c6531ab69c 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java @@ -429,8 +429,7 @@ public void testForMethodReferenceInAnAssignment() { " return o.toString();", " }", " static void testPositive() {", - " // TODO: we should report an error here, since Test::foo cannot take", - " // a @Nullable parameter. we don't catch this yet", + " // BUG: Diagnostic contains: referenced method is @NonNull", " A<@Nullable Object> p = Test::foo;", " }", " static void testNegative() {",