Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/LongRangeMod.java
Tagir Valeev 14d6ae1b03 [java-dfa] Remove incorrect range-narrowing in ModRange.plus
If we overflow and myMod is not a power of 2, we cannot rotate remainders: overflowed subrange may have different remainders. E.g. floorMod(Integer.MAX_VALUE, 6) = 1 but floorMod(Integer.MAX_VALUE+1, 6) = 4, not 2.
Better algorithm is possible if we initially split our range at overflow point, then perform addition separately but for now let's just produce a correct result
Fixes EA-257681 - IAE: LongRangeSet$Range.<init>

GitOrigin-RevId: 45a3a870ae238800386b6ce739694f8f847e6340
2021-02-25 06:26:23 +00:00

48 lines
1.1 KiB
Java

import java.util.*;
public class LongRangeMod {
void test(int[] arr, int x) {
if(<warning descr="Condition 'arr.length % x < 0' is always 'false'">arr.length % x < 0</warning>) {
System.out.println("Impossible");
}
}
void test(int x) {
for (int i = 0; i < 10; i++) {
if(<warning descr="Condition 'i % x > 10' is always 'false'">i % x > 10</warning>) {
System.out.println("impossible");
}
}
}
// IDEA-113410
void test() {
List<String> someList = new LinkedList<>();
someList.add("foo");
int i = 0;
Object something = null;
for (String s : someList) {
if(i % 2 == 0) {
something = new Object();
}
else {
something.toString(); // <== No warning here:
// now we know that i = 0 on the first iteration, thus
// i % 2 == 0 is true, thus something always points to an Object after first iteration
}
i++;
}
}
// EA-257681 - IAE: LongRangeSet$Range.<init>
void test(int a, int b) {
if (a % 2 == 0)
b += a / 2;
else if (a % 3 == 0)
b += a / 3;
else
a++;
}
}