-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
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.
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.