Closed nbauma109 closed 3 years ago
The issue is not specific to the array access but rather related to a systematic contraction of expression and variable increment.
Here is another example
public class TestCFR {
public static void main(final String[] args) {
int length = args.length;
--length;
for (int i = 0; i < length; i++) {
System.out.println(args[i]);
}
}
}
And the decompilation result
public class TestCFR {
public static void main(String[] stringArray) {
int n = stringArray.length;
for (int i = 0; i < --n; ++i) {
System.out.println(stringArray[i]);
}
}
}
CFR version
CFR 0.152-SNAPSHOT (bc8d9a2)
Compiler
javac 1.8.0_252
Description
Index variables can be incremented while accessing an array but if that happens in a loop expression, the variable is incremented at each iteration instead of once.
Example
The following program prints character 'a' from the array in an infinite loop (sorry for a dumb example)
The decompiled output changes the meaning of the program completely. Now the index is incremented at each loop iteration.