IDEA-129040 Check for the string being not null in switch label.

This commit is contained in:
peter
2014-08-26 14:32:22 +02:00
parent 7c3dcb5778
commit 22058565a7
3 changed files with 18 additions and 5 deletions
@@ -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(); }