Skip to content

Commit

Permalink
Fix some NPEs in preparation for the next release
Browse files Browse the repository at this point in the history
RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=235216315
  • Loading branch information
cushon committed Feb 22, 2019
1 parent 1f2fed9 commit c1f7363
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.errorprone.matchers.JUnitMatchers.JUNIT4_RUN_WITH_ANNOTATION;
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
import static java.util.Objects.requireNonNull;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -144,6 +145,8 @@ public class ASTHelpers {
* do any complex analysis here, just catch the obvious cases.
*/
public static boolean sameVariable(ExpressionTree expr1, ExpressionTree expr2) {
requireNonNull(expr1);
requireNonNull(expr2);
// Throw up our hands if we're not comparing identifiers and/or field accesses.
if ((expr1.getKind() != Kind.IDENTIFIER && expr1.getKind() != Kind.MEMBER_SELECT)
|| (expr2.getKind() != Kind.IDENTIFIER && expr2.getKind() != Kind.MEMBER_SELECT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ public Description matchClass(ClassTree tree, VisitorState state) {

@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree.getQualifierExpression());
return describeIfObsolete(tree.getQualifierExpression(), ImmutableList.of(sym.asType()), state);
Type type = ASTHelpers.getType(tree.getQualifierExpression());
if (type == null) {
return NO_MATCH;
}
return describeIfObsolete(tree.getQualifierExpression(), ImmutableList.of(type), state);
}

private Description describeIfObsolete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public Boolean visitMethodInvocation(MethodInvocationTree tree, Void unused) {
ExpressionTree getSecondsReceiver = ASTHelpers.getReceiver(tree);
if (getSecondsReceiver != null) {
// if the methods are being invoked directly on the same variable...
if (ASTHelpers.sameVariable(getNanoReceiver, getSecondsReceiver)) {
if (getNanoReceiver != null
&& getSecondsReceiver != null
&& ASTHelpers.sameVariable(getNanoReceiver, getSecondsReceiver)) {
return true;
}
if (!checkProtoChains) {
Expand Down

0 comments on commit c1f7363

Please sign in to comment.