Hi all!

There is a bug described at https://bugs.openjdk.java.net/browse/JDK-8015594

The problem is that if we are using java.util.Pattern.matcher with NULL
argument,
then the NPE will be thrown. As Stuart Marks has noticed in the comments,
that such
behavior have not been specified, so it seems more convenient to update
method's
javadoc, saying that if argument is null, then the NPE will be thrown.

I'm looking for review and sponsor. File with patch attached.

diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java
b/src/java.base/share/classes/java/util/regex/Pattern.java
--- a/src/java.base/share/classes/java/util/regex/Pattern.java
+++ b/src/java.base/share/classes/java/util/regex/Pattern.java
@@ -1097,8 +1097,11 @@
      *         The character sequence to be matched
      *
      * @return  A new matcher for this pattern
+     * @throws NullPointerException if the specified {@code input}
+     * is {@code null}.
      */
     public Matcher matcher(CharSequence input) {
+        Objects.requireNonNull(input);
         if (!compiled) {
             synchronized(this) {
                 if (!compiled)
diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java
--- a/src/java.base/share/classes/java/util/regex/Pattern.java
+++ b/src/java.base/share/classes/java/util/regex/Pattern.java
@@ -1097,8 +1097,11 @@
      *         The character sequence to be matched
      *
      * @return  A new matcher for this pattern
+     * @throws NullPointerException if the specified {@code input}
+     * is {@code null}.
      */
     public Matcher matcher(CharSequence input) {
+        Objects.requireNonNull(input);
         if (!compiled) {
             synchronized(this) {
                 if (!compiled)

Reply via email to