Skip to content

Commit

Permalink
NULL_LITERAL expressions may always be null
Browse files Browse the repository at this point in the history
there is no reason to give handlers a chance to override this because we
are also not doing this for other literals that we filter out at the
start of the method
  • Loading branch information
XN137 committed Mar 31, 2023
1 parent abac2ae commit 027a80f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
package com.uber.nullaway;

import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
import static com.sun.source.tree.Tree.Kind.EXPRESSION_STATEMENT;
import static com.sun.source.tree.Tree.Kind.IDENTIFIER;
import static com.sun.source.tree.Tree.Kind.OTHER;
import static com.sun.source.tree.Tree.Kind.PARENTHESIZED;
import static com.sun.source.tree.Tree.Kind.TYPE_CAST;
import static com.sun.source.tree.Tree.Kind.*;
import static com.uber.nullaway.ErrorBuilder.errMsgForInitializer;
import static com.uber.nullaway.NullabilityUtil.castToNonNull;

Expand Down Expand Up @@ -2197,14 +2193,14 @@ private boolean mayBeNullExpr(VisitorState state, ExpressionTree expr) {
// obviously not null
return false;
}
if (expr.getKind() == NULL_LITERAL) {
// obviously null, so same as for above literals we return early without consulting handlers
return true;
}
// the logic here is to avoid doing dataflow analysis whenever possible
Symbol exprSymbol = ASTHelpers.getSymbol(expr);
boolean exprMayBeNull;
switch (expr.getKind()) {
case NULL_LITERAL:
// obviously null
exprMayBeNull = true;
break;
case ARRAY_ACCESS:
// unsound! we cannot check for nullness of array contents yet
exprMayBeNull = false;
Expand Down

0 comments on commit 027a80f

Please sign in to comment.