Skip to content

Commit 29e93ed

Browse files
committed
Dataflow: restrict pattern-case flow to unique patterns.
1 parent 00c7dd5 commit 29e93ed

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowUtil.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ predicate simpleAstFlowStep(Expr e1, Expr e2) {
194194
// In the following three cases only record patterns need this flow edge, leading from the bound instanceof
195195
// or switch tested expression to a record pattern that will read its fields. Simple binding patterns are
196196
// handled via VariableAssign.getSource instead.
197+
// We only consider unique patterns because cases that declare multiple patterns are not allowed to declare
198+
// any identifiers, so can't participate in dataflow.
197199
exists(SwitchExpr se |
198-
e1 = se.getExpr() and e2 = se.getACase().(PatternCase).getPattern().asRecordPattern()
200+
e1 = se.getExpr() and e2 = se.getACase().(PatternCase).getUniquePattern().asRecordPattern()
199201
)
200202
or
201203
exists(SwitchStmt ss |
202-
e1 = ss.getExpr() and e2 = ss.getACase().(PatternCase).getPattern().asRecordPattern()
204+
e1 = ss.getExpr() and e2 = ss.getACase().(PatternCase).getUniquePattern().asRecordPattern()
203205
)
204206
or
205207
exists(InstanceOfExpr ioe | e1 = ioe.getExpr() and e2 = ioe.getPattern().asRecordPattern())

0 commit comments

Comments
 (0)