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

Inconsistent exception messages for invalid capturing group names

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: 11
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b01
    • Verification:
      Verified

      Description

      Capturing group name can be used in a regular expression in two contexts: When introducing a group (?<name>...) or when referring it
      \k<name>.
      If the name is invalid (i.e. does not start with a Latin letter, or contains wrong chars) then we may see different error messages, some of
      which look confusing.

      Here are examples of the messages produced by the current JDK:
      Unknown look-behind group near index 3
      (?<>)
          ^
      named capturing group is missing trailing '>' near index 4
      \\k<>
           ^
      Unknown look-behind group near index 4
      (?<.>)
           ^
      (named capturing group <.> does not exit near index 4
      \\k<.>
           ^
      named capturing group is missing trailing '>' near index 4
      (?<a.>)
           ^
      named capturing group is missing trailing '>' near index 4
      \\k<a.>
           ^

      In particular, this diversity is caused by that the internal Pattern.groupname() function lacks a check for the very first character
      of the name.
      So that when \k<name> is parsed, the first char is always accepted, no matter what it was.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                igerasim Ivan Gerasimov
                Reporter:
                igerasim Ivan Gerasimov
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: