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

Pattern.asPredicate specification is incomplete

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      This is a clarification of behaviour, so there is no compatibility risk
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      The proposed change is to explicitly state that Pattern#asPredicate uses s -> matcher(s).find()

      Problem

      The javadoc of Pattern#asPredicate states that it: "[...]Creates a predicate which can be used to match a string."

      The specification for asPredicate isn't sufficiently specific about its behavior. It refers to matching a string, which is misleading because that makes it sound like it's based on Matcher.matches(), Pattern.matches(), or String.matches(). However, it actually uses Matcher.find() in the predicate implementation.

      Solution

      Make the documentation more explicit about the implemented behavior.

      Specification

      src/java.base/share/classes/java/util/regex/Pattern.java

           /**
      -     * Creates a predicate which can be used to match a string.
      +     * Creates a predicate that tests if this pattern is found in a given input
      +     * string.
            *
      -     * @return  The predicate which can be used for matching on a string
      +     * @apiNote
      +     * This method creates a predicate that behaves as if it creates a matcher
      +     * from the input sequence and then calls {@code find}, for example a
      +     * predicate of the form:
      +     *{@code
      +     *   s -> matcher(s).find();
      +     * }
      +     *
      +     * @return  The predicate which can be used for finding a match on a
      +     * subsequence of a string
            * @since   1.8
      +     * @see Matcher#find
            */
      
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vtheeyarath Vivek Theeyarath (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Reviewed By:
              Paul Sandoz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: