Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8269753

Misplaced caret in PatternSyntaxException's detail message

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b08
    • Verification:
      Not verified

      Backports

        Description

        If an erroneous regex pattern contains "\t" (horizontal tab HT), the ^ (diagnostic caret) symbol might be misplaced. For example:
        ```
        jshell> Pattern.compile("\t**")
        | Exception java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 2
        **
          ^
        | at Pattern.error (Pattern.java:2028)
        | at Pattern.sequence (Pattern.java:2203)
        | at Pattern.expr (Pattern.java:2069)
        | at Pattern.compile (Pattern.java:1783)
        | at Pattern.<init> (Pattern.java:1430)
        | at Pattern.compile (Pattern.java:1069)
        | at (#2:1)
        ```
        Compare that with this:
        ```
        jshell> Pattern.compile(" **")
        | Exception java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 2
         **
          ^
        | at Pattern.error (Pattern.java:2028)
        | at Pattern.sequence (Pattern.java:2203)
        | at Pattern.expr (Pattern.java:2069)
        | at Pattern.compile (Pattern.java:1783)
        | at Pattern.<init> (Pattern.java:1430)
        | at Pattern.compile (Pattern.java:1069)
        | at (#3:1)
        ```
        This happens because when calculating required indentation, java.util.regex.PatternSyntaxException#getMessage translates "\t" into "\s" unlike, for example, com.sun.tools.javac.util.AbstractDiagnosticFormatter#formatSourceLine, which translates "\t" into "\t".

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                igraves Ian Graves
                Reporter:
                prappo Pavel Rappo
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: