mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-129040 Check for the string being not null in switch label.
This commit is contained in:
+7
-5
@@ -591,12 +591,14 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
|
||||
generateBoxingUnboxingInstructionFor(caseExpression, PsiType.INT);
|
||||
final PsiClass psiClass = PsiUtil.resolveClassInType(caseExpression.getType());
|
||||
if (psiClass != null && psiClass.isEnum()) {
|
||||
if (psiClass != null) {
|
||||
addInstruction(new FieldReferenceInstruction(caseExpression, "switch statement expression"));
|
||||
enumValues = new HashSet<PsiEnumConstant>();
|
||||
for (PsiField f : psiClass.getFields()) {
|
||||
if (f instanceof PsiEnumConstant) {
|
||||
enumValues.add((PsiEnumConstant)f);
|
||||
if (psiClass.isEnum()) {
|
||||
enumValues = new HashSet<PsiEnumConstant>();
|
||||
for (PsiField f : psiClass.getFields()) {
|
||||
if (f instanceof PsiEnumConstant) {
|
||||
enumValues.add((PsiEnumConstant)f);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class BrokenAlignment {
|
||||
|
||||
void test(@Nullable String n) {
|
||||
switch (<warning descr="Dereference of 'n' may produce 'java.lang.NullPointerException'">n</warning>) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testAssigningClassLiteralToNullable() throws Throwable { doTest(); }
|
||||
|
||||
public void testSynchronizingOnNullable() throws Throwable { doTest(); }
|
||||
public void testSwitchOnNullable() { doTest(); }
|
||||
public void testReturningNullFromVoidMethod() throws Throwable { doTest(); }
|
||||
|
||||
public void testCatchRuntimeException() throws Throwable { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user