Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package checks;

import io.restassured.exception.PathException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;
import java.util.concurrent.*;
import java.util.function.Supplier;

public class ReplaceUnusedExceptionParameterWithUnnamedPatternCheckSample {
Expand Down Expand Up @@ -121,4 +125,22 @@ public void foo(Exception e) {
}

public void e(){}

private final Logger log = LogManager.getLogger();

private void executor_run_compliant() {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(
() -> {
try {
Integer.parseInt("1.2");
} catch (Exception e) {
log.error("SonarQube Cloud reports 'e' should be replaced by _ while it's used", e);
}
},
0,
100_000,
TimeUnit.MILLISECONDS
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void visitNode(Tree tree) {
VariableTree v = catchTree.parameter();
IdentifierTree ident = v.simpleName();

if (!ident.isUnnamedVariable() && v.symbol().usages().isEmpty()) {
// completely ignored for an absent semantic model
if (!ident.isUnnamedVariable() && context.getSemanticModel() != null && v.symbol().usages().isEmpty()) {
QuickFixHelper.newIssue(context)
.forRule(this)
.onTree(ident)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void test_without_semantics() {
.withCheck(new ReplaceUnusedExceptionParameterWithUnnamedPatternCheck())
.withoutSemantic()
.withJavaVersion(22)
.verifyIssues();
.verifyNoIssues();
}

}
Loading