Skip to content

Commit da06267

Browse files
Autofix for empty catch block
1 parent 93bd9b8 commit da06267

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

.codeql/custom-queries/09-cryptographic-security/empt-catch-block-detection.ql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@
88
* @problem.severity warning
99
* @tags maintainability
1010
* error-handling
11+
* @autofix
1112
*/
1213

1314
import java
1415

16+
import semmle.code.java.Autofix
17+
1518
from CatchClause cc
1619
where
17-
// Il blocco catch è vuoto (non contiene statement)
1820
cc.getBlock().getNumStmt() = 0 and
19-
20-
// Oppure contiene solo commenti (blocco con solo whitespace/commenti)
2121
not exists(Stmt s | s.getParent() = cc.getBlock()) and
22-
23-
// Esclude catch di InterruptedException (spesso legittimo lasciarli vuoti)
2422
not cc.getVariable().getType().(RefType).hasQualifiedName("java.lang", "InterruptedException")
25-
26-
select cc, "Blocco catch vuoto - potrebbe nascondere errori importanti"
23+
select cc, "Blocco catch vuoto - potrebbe nascondere errori importanti",
24+
Autofix::insertAfter(cc.getBlock(), "System.err.println(\"Exception caught: \" + " + cc.getVariable().getName() + ");")
2725

0 commit comments

Comments
 (0)