Skip to content

Commit

Permalink
Remove state from S1181 (#4756)
Browse files Browse the repository at this point in the history
  • Loading branch information
johann-beleites-sonarsource authored Apr 8, 2024
1 parent c2b29aa commit a6890ba
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
public class CatchOfThrowableOrErrorCheck extends IssuableSubscriptionVisitor {

private static final String JAVA_LANG_THROWABLE = "java.lang.Throwable";
private final TryBlockVisitor tryBlockVisitor = new TryBlockVisitor();

@Override
public List<Tree.Kind> nodesToVisit() {
Expand All @@ -52,7 +51,7 @@ public List<Tree.Kind> nodesToVisit() {
@Override
public void visitNode(Tree tree) {
TryStatementTree tryStatement = (TryStatementTree) tree;
tryBlockVisitor.reset();
TryBlockVisitor tryBlockVisitor = new TryBlockVisitor();
tryStatement.block().accept(tryBlockVisitor);
if (tryBlockVisitor.containsExplicitThrowable || tryBlockVisitor.containsUnresolvableCall) {
return;
Expand Down Expand Up @@ -126,13 +125,8 @@ private boolean isGuavaCloserRethrow(MethodInvocationTree mit) {
}

private static class TryBlockVisitor extends BaseTreeVisitor {
private boolean containsExplicitThrowable;
private boolean containsUnresolvableCall;

public void reset() {
containsUnresolvableCall = false;
containsExplicitThrowable = false;
}
private boolean containsExplicitThrowable = false;
private boolean containsUnresolvableCall = false;

@Override
public void visitMethodInvocation(MethodInvocationTree tree) {
Expand Down

0 comments on commit a6890ba

Please sign in to comment.