IDEA-106884 Detect that string concatenation produces not-null result

This commit is contained in:
peter
2013-05-22 18:09:00 +02:00
parent ca9680c16c
commit 1d19b2d96f
3 changed files with 21 additions and 0 deletions
@@ -182,6 +182,11 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
generateDefaultBinOp(lExpr, rExpr, type);
}
}
else if (op == JavaTokenType.PLUSEQ && type != null && type.equalsToText(JAVA_LANG_STRING)) {
lExpr.accept(this);
rExpr.accept(this);
addInstruction(new BinopInstruction(JavaTokenType.PLUS, null, lExpr.getProject()));
}
else {
generateDefaultBinOp(lExpr, rExpr, type);
}
@@ -0,0 +1,15 @@
import org.jetbrains.annotations.NotNull;
class X {
@NotNull
String foo() {return "";}
void bar() {
String o = foo();
o += "";
if (<warning descr="Condition 'o != null' is always 'true'">o != null</warning>) {
}
}
}
@@ -68,6 +68,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testIDEA84489() throws Throwable { doTest(); }
public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); }
public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); }
public void testStringConcatAlwaysNotNull() throws Throwable { doTest(); }
public void testNotNullPrimitive() throws Throwable { doTest(); }
public void testBoxing128() throws Throwable { doTest(); }