Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/AssignmentFieldAliasing.java
Tagir Valeev 32d68a399f [java-dfa] IDEA-262483 Improve LiveVariableAnalyzer
1. Variables unused after the first statement aren't flushed because LVA doesn't know the initial state
2. Variables unused after the 'if' condition may not flush in 'if' branches
3. Use of variable may imply the use of any dependent variables.
4. Fields from the class initializer should be kept, as they may be needed in constructors
5. Fields should not be flushed in DfaPsiUtil#getBlockNotNullFields

GitOrigin-RevId: 394d7acd693c2d303460cc3bb686145701231e3d
2021-02-20 07:44:46 +00:00

50 lines
1.1 KiB
Java

class App {
void test(A a, A b) {
if(a.field != b.field) {
if(<warning descr="Condition 'a == b' is always 'false'">a == b</warning>) {
System.out.println("Impossible");
}
}
}
public static void main(String[] args) {
A a1 = new A();
assert a1.field == 0;
A a2 = a1;
assert <warning descr="Condition 'a2.field == 0' is always 'true'">a2.field == 0</warning>;
a1.field = 10;
assert <warning descr="Condition 'a2.field == 10' is always 'true'">a2.field == 10</warning>;
}
void testThreeClasses(Node x, Node y, Node z) {
if (x.a == y && x.b == z && x == y.b && x == z.a && x == z) {
assert <warning descr="Condition 'x == x.a' is always 'true'">x == x.a</warning>;
assert <warning descr="Condition 'x == x.b' is always 'true'">x == x.b</warning>;
}
}
class Node {
Node a, b;
}
}
class A {
public int field = 0;
}
class X {
X foo;
void test() {
final X localFoo = foo.getX();
if (localFoo == null) {
boolean nonNull = foo != null;
}
}
native X getX();
}