Other cases you mentioned are not directly related:
The last remaining is a dead code . This is not a mistake, and the reasons are also explained in the Unreachable Statementments section:
You can expect the if statement to be processed as follows:
...
This approach is consistent with the processing of other management structures. However, in order for the if statement to be used conveniently for "conditional compilation" purposes, the actual rules are different.
As an example, the following statement results in a compile-time error:
while (false) { x=3; }
because the statement x = 3; not available; but an outwardly similar case:
if (false) { x=3; }
does not result in a compile-time error. The optimizing compiler can understand that the operator x = 3; will never be executed and may omit the code for this statement from the file of the generated class, but statement x = 3; not considered as βunreachableβ in the technical sense indicated here.
Thus, the "dead code" is "unusual" and, of course, deserves attention, but is not necessarily a mistake.
Regarding your actual question (ignoring the fact that Parser and Compiler are two different things - this is clear what this is about): This is a very specific case. This applies only when the declaration of the array and access to the array are in the same area. In addition, indexes must be compile-time constants.
Thus, it is obvious that
void init(String data[]) { data[0] = "OK"; data[1] = "returning data"; data[2] = "data out of bounds"; }
or
int i = 0; data[i++] = "OK"; data[i++] = "returning data"; data[i++] = "data out of bounds";
There is probably no convincing, deep reason why this is not detected by Eclipse, except that the ratio of efforts to detect such errors and benefits is not high enough - perhaps something like this will be added in a future release. Eclipse already has some pretty complex warnings (like automatically detecting "Null pointer access"). But for more detailed static analysis, there are special tools, such as FindBugs or PMD , which put more effort (and more time, by the way) than tests that are performed randomly and on the fly eclipses.
Note: you can avoid this kind of error with
String data[] = { "OK", "returning data", "data out of bounds" };