RFR: 8285452: Add a new test library API to replace a file content using FileUtils.java [v7]
Weijun Wang
weijun at openjdk.java.net
Fri Apr 29 13:05:49 UTC 2022
On Fri, 29 Apr 2022 12:44:26 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> test/lib/jdk/test/lib/util/FileUtils.java line 394:
>>
>>> 392: var removed = "";
>>> 393: for (int i = fromLine; i <= toLine; i++) {
>>> 394: removed += lines.remove(fromLine - 1).trim();
>>
>> shouldn't you insert a "\n" ? otherwise concatenating lines "ab" and "c" will be the same as concatenating lines "a" and "bc".
>
> Also calling trim() assumes that white spaces are not significant. This might not be the case in the general case (for instance - think of markdown files were leading spaces are significant).
The comparison is intentionally made lax so the caller does not need to provide the exact indentation or even new line characters. We think along with `fromLine` and `toLine` this is enough to make sure we are not modifying the wrong lines.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8360
More information about the core-libs-dev
mailing list