[java-dfa] Having no unreachable branches doesn't mean that the current branch is the only reachable.

GitOrigin-RevId: 6cd26f5f00467775378d6d52b33f3916dc1eba62
This commit is contained in:
Tagir Valeev
2023-09-06 15:57:45 +02:00
committed by intellij-monorepo-bot
parent 31928210fc
commit 0e37e37009
2 changed files with 13 additions and 5 deletions

View File

@@ -302,10 +302,6 @@ public abstract class DataFlowInspectionBase extends AbstractBaseJavaLocalInspec
PsiSwitchBlock switchBlock = labelStatement.getEnclosingSwitchBlock();
if (switchBlock == null) continue;
if (!canRemoveTheOnlyReachableLabel(label, switchBlock)) continue;
if (SwitchUtils.findRemovableUnreachableBranches(label, switchBlock).isEmpty()) {
holder.registerProblem(label, JavaAnalysisBundle.message("dataflow.message.only.switch.label"));
continue;
}
if (!StreamEx.iterate(labelStatement, Objects::nonNull, l -> PsiTreeUtil.getPrevSiblingOfType(l, PsiSwitchLabelStatementBase.class))
.skip(1).map(PsiSwitchLabelStatementBase::getCaseLabelElementList)
.nonNull().flatArray(PsiCaseLabelElementList::getElements)
@@ -323,7 +319,8 @@ public abstract class DataFlowInspectionBase extends AbstractBaseJavaLocalInspec
}
coveredSwitches.add(switchBlock);
LocalQuickFix unwrapFix;
if (switchBlock instanceof PsiSwitchExpression && !CodeBlockSurrounder.canSurround(((PsiSwitchExpression)switchBlock))) {
if ((switchBlock instanceof PsiSwitchExpression && !CodeBlockSurrounder.canSurround(((PsiSwitchExpression)switchBlock))) ||
SwitchUtils.findRemovableUnreachableBranches(label, switchBlock).isEmpty()) {
unwrapFix = null;
}
else {