java.util.regex.Matcher.group(int) has misleading spec

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 1.4.0
    • Affects Version/s: 1.4.0
    • Component/s: core-libs
    • None
    • beta
    • sparc
    • solaris_7
    • Verified

      Matcher.group(int) returns a blank string instead of null if the match was successful but the group itself did not match anything.

      So the folling piece of code

         Pattern p = Pattern.compile("ab(c*)");
         Matcher m = p.matcher("abababababa");
         m.find();
         System.out.println(m.group(1));
         
      prints a blank string instead of null.

            Assignee:
            Michael Mccloskey (Inactive)
            Reporter:
            J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: