mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspection] IDEA-310567 'Constant values' false positive for switch expression
- skip 'constant values' for switch expressions if they contain always failed methods GitOrigin-RevId: 1207911bd11f94f37293254fa609e47b42aa96e1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
708b5271f6
commit
5b7611c45e
+8
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.SimplifyBooleanExpressionFix;
|
||||
@@ -400,6 +400,13 @@ public final class ConstantValueInspection extends AbstractBaseJavaLocalInspecti
|
||||
ref.set(true);
|
||||
return false;
|
||||
}
|
||||
if (element instanceof PsiMethodCallExpression methodCallExpression) {
|
||||
List<? extends MethodContract> contracts = JavaMethodContractUtil.getMethodCallContracts(methodCallExpression);
|
||||
if (ContainerUtil.exists(contracts, contract -> contract.isTrivial() && contract.getReturnValue().isFail())) {
|
||||
ref.set(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return ref.get();
|
||||
|
||||
+18
@@ -1,3 +1,5 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class SkipSwitchExpressionWithThrow {
|
||||
static boolean test(int x) {
|
||||
return switch (x) {
|
||||
@@ -7,4 +9,20 @@ class SkipSwitchExpressionWithThrow {
|
||||
default -> throw new IllegalStateException();
|
||||
};
|
||||
}
|
||||
|
||||
public enum Foo {
|
||||
A, B
|
||||
}
|
||||
|
||||
public static <R> R exception() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object test2(Foo foo) {
|
||||
return switch (foo) {
|
||||
case A -> null;
|
||||
case B -> exception();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user