Skip to content
Merged
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
Expand Up @@ -65,6 +65,9 @@ private void f(Exception x) {
System.out.println("" + e);
}
}
try {
} catch (Exception _) { // Compliant
}
}

private void g() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void visitLambdaExpression(LambdaExpressionTree lambdaExpressionTree) {

@Override
public void visitCatch(CatchTree tree) {
if (!isExcludedType(tree.parameter().type()) && !excludedCatchTrees.contains(tree)) {
if (!isExcludedType(tree.parameter().type()) && !excludedCatchTrees.contains(tree) && !tree.parameter().simpleName().isUnnamedVariable()) {
Symbol exception = tree.parameter().symbol();
usageStatusStack.addFirst(new UsageStatus(exception.usages()));
super.visitCatch(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ <h3>Exceptions</h3>
LOGGER.warn(message); // Compliant - exception message logged with some contextual information
}
</pre>
<p>Additionally, no issue will be raised if the exception parameter uses the unnamed variable <code>_</code>, which is available starting with Java
21. The unnamed variable makes it explicit that the exception is caught but not needed in the handler (see {rule:java:S7467}).</p>
<pre>
try {
/* ... */
} catch (Exception _) {
// Compliant - unnamed exception parameter is intentionally unused
return defaultValue;
}
</pre>
<h2>Resources</h2>
<ul>
<li> OWASP - <a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">Top 10 2021 Category A9 - Security Logging and
Expand Down
Loading