Skip to content

Commit

Permalink
changes for the test case: testForMethodReferenceInAnAssignment
Browse files Browse the repository at this point in the history
  • Loading branch information
akulk022 committed Oct 12, 2023
1 parent 2d2b829 commit 0b49a42
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ private Description checkParamOverriding(
i,
overriddenMethod,
overridingParamSymbols.get(i).owner.owner,
memberReferenceTree,
state,
config)
: Nullness.NONNULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {",
Expand Down

0 comments on commit 0b49a42

Please sign in to comment.