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

match() called on Matcher for empty pattern throws NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • None
    • beta
    • generic
    • generic

      If an empty string is used as the regular expression for a Pattern,
      resulting Matchers throw NullPointerExceptions when match() is called on them:

      $ cat Baz.java
      public class Baz {
          public static void main(String[] args) throws Exception {
              java.util.regex.Pattern.matches("", "foo");
          }
      }
      $ java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)
      $ javac Baz.java
      $ java Baz
      Exception in thread "main" java.lang.NullPointerException
              at java.util.regex.Matcher.match(Matcher.java:621)
              at java.util.regex.Matcher.matches(Matcher.java:375)
              at java.util.regex.Pattern.matches(Pattern.java:758)
              at Baz.main(Baz.java:3)

      I did not see anything in the javadoc for Pattern or Matcher to indicate that
      empty strings constitute illegal regular expressions; even if they do,
      one would expect Pattern.compile() to throw a PatternSyntaxException rather
      than Matcher.match throwing a NullPointerException.

            mmcclosksunw Michael Mccloskey (Inactive)
            mwarressunw Michael Warres (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: