Skip to content

Commit 6b3080a

Browse files
committed
Allow case null, default to be the first switch case
This is consistent with existing treatment of `case null: default:`
1 parent 0b08507 commit 6b3080a

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ private module ControlFlowGraphImpl {
471471
private SwitchCase getASuccessorSwitchCase(PatternCase pred) {
472472
result.getParent() = pred.getParent() and
473473
result.getIndex() > pred.getIndex() and
474+
// Note we do include `case null, default` (as well as plain old `default`) here.
474475
not result.(ConstCase).getValue(_) instanceof NullLiteral and
475476
(
476477
result.getIndex() <= getNextPatternCase(pred).getIndex()
@@ -492,6 +493,8 @@ private module ControlFlowGraphImpl {
492493
(
493494
result.(ConstCase).getValue(_) instanceof NullLiteral
494495
or
496+
result instanceof NullDefaultCase
497+
or
495498
not exists(getPatternCase(switch, _))
496499
or
497500
result.getIndex() <= getPatternCase(switch, 0).getIndex()

java/ql/test/library-tests/pattern-switch/cfg/test.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
| Test.java:55:13:55:25 | (...)... | Test.java:56:8:56:21 | case ... |
145145
| Test.java:55:13:55:25 | (...)... | Test.java:58:8:58:21 | case ... |
146146
| Test.java:55:13:55:25 | (...)... | Test.java:61:8:61:42 | case T t ... |
147+
| Test.java:55:13:55:25 | (...)... | Test.java:69:8:69:26 | case null, default |
147148
| Test.java:55:21:55:25 | thing | Test.java:55:13:55:25 | (...)... |
148149
| Test.java:56:8:56:21 | case ... | Test.java:57:10:57:44 | <Expr>; |
149150
| Test.java:57:10:57:19 | System.out | Test.java:57:29:57:42 | "It's Const1!" |

0 commit comments

Comments
 (0)