8269753: Misplaced caret in PatternSyntaxException's detail message

Reviewed-by: prappo
This commit is contained in:
Ian Graves 2021-07-27 02:25:30 +00:00
parent c3d8e9228d
commit bb508e1303
2 changed files with 24 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -107,7 +107,9 @@ public class PatternSyntaxException
sb.append(pattern); sb.append(pattern);
if (index >= 0 && pattern != null && index < pattern.length()) { if (index >= 0 && pattern != null && index < pattern.length()) {
sb.append(System.lineSeparator()); sb.append(System.lineSeparator());
for (int i = 0; i < index; i++) sb.append(' '); for (int i = 0; i < index; i++) {
sb.append((pattern.charAt(i) == '\t') ? '\t' : ' ');
}
sb.append('^'); sb.append('^');
} }
return sb.toString(); return sb.toString();

View file

@ -36,7 +36,7 @@
* 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895 * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
* 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706 * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
* 8194667 8197462 8184692 8221431 8224789 8228352 8230829 8236034 8235812 * 8194667 8197462 8184692 8221431 8224789 8228352 8230829 8236034 8235812
* 8216332 8214245 8237599 8241055 8247546 8258259 8037397 * 8216332 8214245 8237599 8241055 8247546 8258259 8037397 8269753
* *
* @library /test/lib * @library /test/lib
* @library /lib/testlibrary/java/lang * @library /lib/testlibrary/java/lang
@ -198,6 +198,7 @@ public class RegExTest {
caseInsensitivePMatch(); caseInsensitivePMatch();
surrogatePairOverlapRegion(); surrogatePairOverlapRegion();
droppedClassesWithIntersection(); droppedClassesWithIntersection();
errorMessageCaretIndentation();
if (failure) { if (failure) {
@ -5289,5 +5290,23 @@ public class RegExTest {
System.out.println("Compiling intersection pattern is matching digits where it should not"); System.out.println("Compiling intersection pattern is matching digits where it should not");
} }
report("Dropped classes with intersection.");
}
//This test is for 8269753
private static void errorMessageCaretIndentation() {
String pattern = "\t**";
try {
var res = Pattern.compile(pattern);
} catch (PatternSyntaxException e) {
var message = e.getMessage();
var sep = System.lineSeparator();
if (!message.contains(sep + "\t ^")){
failCount++;
}
}
report("Correct caret indentation for patterns with tabs");
} }
} }