mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-106884 Detect that string concatenation produces not-null result
This commit is contained in:
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user