RFR: 8266625: The method DiagnosticSource#findLine returns wrong results when using the boundary values
Guoxiong Li
gli at openjdk.java.net
Thu May 6 14:02:20 UTC 2021
Hi all,
Currently, when the file object has N characters, the method `DiagnosticSource#findLine(N)` returns true, which is a wrong result. Becase the position is zero-based, the max index is `N-1`.
The methods `getLineNumber`, `getColumnNumber` and `getLine`, which use `findLine` internally, would also return wrong results when using the boundary values.
This patch mainly fixes `DiagnosticSource#findLine(N)` by using the following code.
- return bp <= bufLen;
+ return bp < bufLen;
A corresponding test `DiagnosticSourceTest.java` is added. Then, the usages of `getLineNumber`, `getColumnNumber` and `getLine` need to revised. And two existing tests need to be adjusted.
Thank you for taking the time to review.
Best Regards,
--- Guoxiong
-------------
Commit messages:
- 8266625: The method DiagnosticSource#findLine returns wrong results when using the boundary values
Changes: https://git.openjdk.java.net/jdk/pull/3899/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3899&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8266625
Stats: 124 lines in 8 files changed: 117 ins; 0 del; 7 mod
Patch: https://git.openjdk.java.net/jdk/pull/3899.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/3899/head:pull/3899
PR: https://git.openjdk.java.net/jdk/pull/3899
More information about the compiler-dev
mailing list