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

(spec str) String.split() should explain string quoting for literal instead of regex behavior

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • Cause Known
    • generic
    • generic

      Bugs 5061438 and 6253831 show that users sometimes fail to notice that the argument to String.split is a regular expression, not just a plain String. They then expect e.g. "a|b".split("|") to return strings "a" and "b". In fact it returns strings "", "a", "|", and "b", because "|" is a regular expression meaning "empty string or empty string". It would be good to add some text to both String.split methods that points out this pitfall and suggests using Pattern.quote.
      ###@###.### 2005-04-13 12:26:48 GMT

            Unassigned Unassigned
            emcmanus Eamonn McManus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: