RFR: 8269753: Misplaced caret in PatternSyntaxException's detail message
Pavel Rappo
prappo at openjdk.java.net
Mon Jul 26 19:49:30 UTC 2021
On Mon, 26 Jul 2021 18:10:03 GMT, Ian Graves <igraves at openjdk.org> wrote:
> Fixes a bug where carets aren't indented correctly in PatternSyntaxException messages because tab characters are converted to spaces in their indentation.
Changes requested by prappo (Reviewer).
src/java.base/share/classes/java/util/regex/PatternSyntaxException.java line 111:
> 109: sb.append(System.lineSeparator());
> 110: for (int i = 0; i < index; i++) {
> 111: sb.append((pattern.charAt(i) == '\t') ? '\t' : ' ');
In contrast with https://github.com/igraves/jdk/blob/2609dd9618dd43ea0de9abe3e3100262d09c079c/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java#L324, this code uses `StringBuilder.append(char)`, which might be even cleaner; good.
test/jdk/java/util/regex/RegExTest.java line 5304:
> 5302: var message = e.getMessage();
> 5303: var sep = System.lineSeparator();
> 5304: if(message.contains(sep + "\t ^")){
Suggestion:
if (message.contains(sep + "\t ^")) {
test/jdk/java/util/regex/RegExTest.java line 5310:
> 5308: failCount++;
> 5309:
> 5310: report("Correct caret indentation for patterns with tabs");
`report` will not be reached on success; this is different from how `report` is used in the rest of the file. Also: `report` seems to be stateful in that it resets the `failCount`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4906
More information about the core-libs-dev
mailing list