RFR 8015594: java.util.Pattern.matcher function throws a NullPointerException

Sergey Ustimenko merkel05 at gmail.com
Tue Apr 26 11:49:39 UTC 2016


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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JDK-8015594.patch
Type: text/x-diff
Size: 670 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20160426/29d03cd6/JDK-8015594.patch>


More information about the core-libs-dev mailing list