suggest the snippet below: Basically, it reads the string One\nTwo completely, piping it through a LineNumberReader. So far, nothing special. Problem: On Java 8, and Java 11, the output is 1. On Java 17, however, the output is 2. (Looks, like the last, unterminated line is counted in the latter case, but isn't in the former cases.
Question: Is this a known incompatibility? Is it documented, and intentional?
Thanks,
Jochen
final StringReader sr = new StringReader("One\nTwo");
final LineNumberReader lnr = new LineNumberReader(sr);
for (;;) {
final int c = lnr.read();
if (c == -1) {
System.out.println("Line number=" + lnr.getLineNumber());
break;
}
}