8174950: Gracefully handle null Supplier in Objects.requireNonNull
authorsimonis
Wed, 15 Feb 2017 09:10:24 +0100
changeset 43802 5f95a1b1f73d
parent 43801 b2566397a3c0
child 43803 e1881d258206
8174950: Gracefully handle null Supplier in Objects.requireNonNull Reviewed-by: dholmes, psandoz, alanb, chegar
jdk/src/java.base/share/classes/java/util/Objects.java
--- a/jdk/src/java.base/share/classes/java/util/Objects.java	Wed Feb 15 09:08:25 2017 +0800
+++ b/jdk/src/java.base/share/classes/java/util/Objects.java	Wed Feb 15 09:10:24 2017 +0100
@@ -343,7 +343,8 @@
      */
     public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) {
         if (obj == null)
-            throw new NullPointerException(messageSupplier.get());
+            throw new NullPointerException(messageSupplier == null ?
+                                           null : messageSupplier.get());
         return obj;
     }