Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a450b0

Browse files
committed
Account for pattern-cases in more places
1 parent 2b16121 commit 9a450b0

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

java/ql/lib/semmle/code/java/metrics/MetricCallable.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ class MetricCallable extends Callable {
7373
// so there should be a branching point for each non-default switch
7474
// case (ignoring those that just fall through to the next case).
7575
private predicate branchingSwitchCase(ConstCase sc) {
76-
not sc.(ControlFlowNode).getASuccessor() instanceof ConstCase and
77-
not sc.(ControlFlowNode).getASuccessor() instanceof DefaultCase and
76+
not sc.(ControlFlowNode).getASuccessor() instanceof SwitchCase and
7877
not defaultFallThrough(sc)
7978
}
8079

8180
private predicate defaultFallThrough(ConstCase sc) {
82-
exists(DefaultCase default | default.(ControlFlowNode).getASuccessor() = sc) or
81+
exists(SwitchCase default | default.hasDefaultLabel() |
82+
default.(ControlFlowNode).getASuccessor() = sc
83+
)
84+
or
8385
defaultFallThrough(sc.(ControlFlowNode).getAPredecessor())
8486
}
8587

@@ -90,6 +92,7 @@ private predicate branchingStmt(Stmt stmt) {
9092
stmt instanceof DoStmt or
9193
stmt instanceof ForStmt or
9294
stmt instanceof EnhancedForStmt or
95+
stmt instanceof PatternCase or
9396
branchingSwitchCase(stmt) or
9497
stmt instanceof CatchClause
9598
}

java/ql/src/Violations of Best Practice/Declarations/BreakInSwitchCase.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import Common
1717
from SwitchStmt s, Stmt c
1818
where
1919
c = s.getACase() and
20-
not c.(ControlFlowNode).getASuccessor() instanceof ConstCase and
21-
not c.(ControlFlowNode).getASuccessor() instanceof DefaultCase and
20+
not c.(ControlFlowNode).getASuccessor() instanceof SwitchCase and
2221
not s.(Annotatable).suppressesWarningsAbout("fallthrough") and
2322
mayDropThroughWithoutComment(s, c)
2423
select c,

0 commit comments

Comments
 (0)