From 56a6741a17272f5d950a0399d2d869355011e487 Mon Sep 17 00:00:00 2001 From: ccernat Date: Fri, 6 Jan 2023 13:40:53 +0100 Subject: [PATCH] Check ASTHelpers.getSymbol for nulls --- .../errorprone/bugpatterns/BadStaticImport.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/BadStaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/BadStaticImport.java index 1752d490111..53d0cf69357 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/BadStaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/BadStaticImport.java @@ -119,15 +119,15 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState @Override public Description matchIdentifier(IdentifierTree tree, VisitorState state) { - Symbol symbol = ASTHelpers.getSymbol(tree); - if (isMatch(symbol)) { - return getDescription(tree, state, symbol); + if (isMatch(tree)) { + return getDescription(tree, state); } return Description.NO_MATCH; } - private Description getDescription(IdentifierTree tree, VisitorState state, Symbol symbol) { + private Description getDescription(IdentifierTree tree, VisitorState state) { + Symbol symbol = ASTHelpers.getSymbol(tree); SuggestedFix.Builder builder = SuggestedFix.builder().removeStaticImport(getImportToRemove(symbol)); String replacement = @@ -142,7 +142,12 @@ private static String getImportToRemove(Symbol symbol) { ".", symbol.getEnclosingElement().getQualifiedName(), symbol.getSimpleName()); } - private static boolean isMatch(Symbol symbol) { + private static boolean isMatch(IdentifierTree tree) { + Symbol symbol = ASTHelpers.getSymbol(tree); + if (symbol == null) { + return false; + } + Symbol enclosingSymbol = symbol.getEnclosingElement(); if (enclosingSymbol == null) { return false;