Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/FieldAliasing.java
Tagir Valeev 780bab7ad1 [java-dfa] IDEA-355606 Constant conditions: aliasing between references is not considered
GitOrigin-RevId: b931b945d9bf10c73fae153a5b1d8e7fec560517
2024-07-03 12:47:15 +00:00

45 lines
1.2 KiB
Java

public class FieldAliasing {
static class X {
int a = 1;
}
static void moreSpecificValue(int val, X a, X b) {
if (val < 0 || val > 10) return;
a.a = val;
if (<warning descr="Condition 'a.a == val' is always 'true'">a.a == val</warning>) {
// "quite expected"
}
b.a = 3;
if (<warning descr="Condition 'a.a >= 0 && a.a <= 10' is always 'true'"><warning descr="Condition 'a.a >= 0' is always 'true'">a.a >= 0</warning> && <warning descr="Condition 'a.a <= 10' is always 'true' when reached">a.a <= 10</warning></warning>) {
// "always"
}
if (a.a == val) {
// "not aliased"
}
}
static void test(X a, X b) {
a.a = 2;
b.a = 3;
if (a.a == 3) {
// "aliased"
}
if (<warning descr="Condition 'a.a == 3 || a.a == 2' is always 'true'">a.a == 3 || <warning descr="Condition 'a.a == 2' is always 'true' when reached">a.a == 2</warning></warning>) {
// "no other value possible"
}
}
static void noAliasingPossible(X a, X b) {
if (a == b) return;
a.a = 2;
b.a = 3;
if (<warning descr="Condition 'a.a == 3' is always 'false'">a.a == 3</warning>) {
// "aliased"
}
}
public static void main(String[] args) {
X a = new X();
test(a, a);
}
}