ADDITIONAL SYSTEM INFORMATION :
OpenJDK 11 and 14 allow to reproduce this bug, GraalVM does not.
A DESCRIPTION OF THE PROBLEM :
The first integer printed is not in the range specified by if-statement.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run the main() method and check the output.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
#1 {integer in the range from 1000 to 9999 (both sides including)}
#2 {integer in the range from 1000 to 9999 (both sides including)}
ACTUAL -
#1 {integer NOT in the range from 1000 to 9999 (both sides including)}
#2 {integer in the range from 1000 to 9999 (both sides including)}
---------- BEGIN SOURCE ----------
public class Bug {
/*
* Why does this code output:
* #1 1746077296
* #2 9296
* ???
* */
public static void main(String[] args) {
for (int i = 0, j = 0; j < 2; i -= 1000) {
if ((i > 999) && (i < 10000)) {
j++;
System.out.println("#" + j + ' ' + i + ' ' + Integer.MAX_VALUE);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use -XX:TieredStopAtLevel=3 option or make counter i and j volatile class fields.
FREQUENCY : always