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

Matcher.group() can return null after usePattern

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Draft
    • Priority: P4
    • Resolution: Unresolved
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None

      Description

      Summary

      We need to update the specification for java.util.regex.Matcher so that group() to account for an undocumented null that is returned if the matcher has been given a new pattern with usePattern() and has yet to attempt a match with the new pattern.

      Problem

      Behavior has been reported in the wild that when calling Matcher.group() after re-assigning the matcher's Pattern with usePattern() returns a null value. This behavior isn't in the specification for Matcher.group().

      Solution

      The null return value is observed when a state bit for a given group is -1. This value is only set in the group state array after usePattern() is invoked on a Matcher. The solution is to update the spec to document this behavior.

      Specification

      The documentation for the return value of Matcher.group() will be appended with:

      in string form or `null` if a matcher with a previous
      match has been changed to a new `java.util.regex.Pattern`
      but no new match has yet been attempted

      The documentation for the return value of Matcher.group(int) will be appended with:

      failed to match part of the input or if the matcher's
      {@link java.util.regex.Pattern} has changed but a new match has
      not been attempted

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              igraves Ian Graves
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated: