Java: Teach guards that exceptions in catch-clauses are non-null.

This commit is contained in:
Anders Schack-Mulligen
2025-08-22 10:16:42 +02:00
parent 02452704b2
commit f2352f76c0

View File

@@ -141,6 +141,7 @@ private predicate isNonFallThroughPredecessor(SwitchCase sc, ControlFlowNode pre
private module GuardsInput implements SharedGuards::InputSig<Location> {
private import java as J
private import semmle.code.java.dataflow.internal.BaseSSA
private import semmle.code.java.dataflow.NullGuards as NullGuards
import SuccessorType
@@ -216,6 +217,12 @@ private module GuardsInput implements SharedGuards::InputSig<Location> {
f.isFinal() and
f.getInitializer() = NullGuards::baseNotNullExpr()
)
or
exists(CatchClause cc, LocalVariableDeclExpr decl, BaseSsaUpdate v |
decl = cc.getVariable() and
decl = v.getDefiningExpr() and
this = v.getAUse()
)
}
}