Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8269753: Misplaced caret in PatternSyntaxException's detail message
Reviewed-by: prappo
  • Loading branch information
Ian Graves committed Jul 27, 2021
1 parent c3d8e92 commit bb508e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -107,7 +107,9 @@ public String getMessage() {
sb.append(pattern);
if (index >= 0 && pattern != null && index < pattern.length()) {
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('^');
}
return sb.toString();
Expand Down
21 changes: 20 additions & 1 deletion test/jdk/java/util/regex/RegExTest.java
Expand Up @@ -36,7 +36,7 @@
* 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
* 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
* 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 /lib/testlibrary/java/lang
Expand Down Expand Up @@ -198,6 +198,7 @@ public static void main(String[] args) throws Exception {
caseInsensitivePMatch();
surrogatePairOverlapRegion();
droppedClassesWithIntersection();
errorMessageCaretIndentation();


if (failure) {
Expand Down Expand Up @@ -5289,5 +5290,23 @@ private static void droppedClassesWithIntersection() {
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");
}
}

3 comments on commit bb508e1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on bb508e1 Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on bb508e1 Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-bb508e13 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit bb508e13 from the openjdk/jdk repository.

The commit being backported was authored by Ian Graves on 27 Jul 2021 and was reviewed by Pavel Rappo.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-bb508e13:GoeLin-backport-bb508e13
$ git checkout GoeLin-backport-bb508e13
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-bb508e13

Please sign in to comment.