Skip to content

Commit d00e0b4

Browse files
committed
Java: Fix enhancedForEarlyExit implementation.
1 parent b218577 commit d00e0b4

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

java/ql/lib/semmle/code/java/dataflow/Nullness.qll

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private import NullGuards
1717
private import semmle.code.java.Collections
1818
private import semmle.code.java.controlflow.internal.Preconditions
1919
private import semmle.code.java.controlflow.ControlFlowReachability
20+
private import codeql.controlflow.SuccessorType
2021

2122
/** Gets an expression that may be `null`. */
2223
Expr nullExpr() { result = nullExpr(_) }
@@ -230,14 +231,8 @@ private Expr nonEmptyExpr() {
230231

231232
/** The control flow edge that exits an enhanced for loop if the `Iterable` is empty. */
232233
private predicate enhancedForEarlyExit(EnhancedForStmt for, ControlFlowNode n1, ControlFlowNode n2) {
233-
exists(Expr forExpr |
234-
n1.getANormalSuccessor() = n2 and
235-
for.getExpr() = forExpr and
236-
forExpr.getAChildExpr*() = n1.asExpr() and
237-
not forExpr.getAChildExpr*() = n2.asExpr() and
238-
n1.getANormalSuccessor().asExpr() = for.getVariable() and
239-
not n2.asExpr() = for.getVariable()
240-
)
234+
n1.getASuccessor(any(EmptinessSuccessor t | t.isEmpty())) = n2 and
235+
for.getExpr().getControlFlowNode() = n1
241236
}
242237

243238
/** A control flow edge that cannot be taken. */

0 commit comments

Comments
 (0)