Skip to content

Commit

Permalink
Handle bad symbols more gracefully
Browse files Browse the repository at this point in the history
This shouldn't be necessary, but it helps with b/31565750.

MOE_MIGRATED_REVID=133491553
  • Loading branch information
cushon committed Sep 21, 2016
1 parent cf45077 commit ed80a08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Expand Up @@ -37,7 +37,6 @@
import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol;
import com.sun.tools.javac.tree.JCTree;
import java.util.Iterator; import java.util.Iterator;


/** /**
Expand Down Expand Up @@ -160,18 +159,19 @@ private Description handleMatch(ExpressionTree actualParam, VisitorState state)


@Override @Override
public Description matchNewClass(NewClassTree tree, VisitorState state) { public Description matchNewClass(NewClassTree tree, VisitorState state) {
JCTree.JCNewClass newClass = (JCTree.JCNewClass) tree; Symbol.MethodSymbol sym = ASTHelpers.getSymbol(tree);
return matchArguments( if (sym == null) {
state, (Symbol.MethodSymbol) newClass.constructor, tree.getArguments().iterator()); return Description.NO_MATCH;
}
return matchArguments(state, sym, tree.getArguments().iterator());
} }


@Override @Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
ExpressionTree methodSelect = tree.getMethodSelect(); Symbol.MethodSymbol sym = ASTHelpers.getSymbol(tree);
Symbol sym = ASTHelpers.getSymbol(methodSelect);
if (sym == null) { if (sym == null) {
return Description.NO_MATCH; return Description.NO_MATCH;
} }
return matchArguments(state, (Symbol.MethodSymbol) sym, tree.getArguments().iterator()); return matchArguments(state, sym, tree.getArguments().iterator());
} }
} }
Expand Up @@ -70,6 +70,9 @@ public class ForOverrideChecker extends BugChecker
@Override @Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
MethodSymbol method = ASTHelpers.getSymbol(tree); MethodSymbol method = ASTHelpers.getSymbol(tree);
if (method == null) {
return Description.NO_MATCH;
}
Type currentClass = getOutermostClass(state); Type currentClass = getOutermostClass(state);


if (method.isStatic() || method.isConstructor() || currentClass == null) { if (method.isStatic() || method.isConstructor() || currentClass == null) {
Expand Down

0 comments on commit ed80a08

Please sign in to comment.