src/share/classes/java/util/Comparators.java

Print this page
rev 6871 : 8010279: java.util.Stream.min/max((Comparator)null) is not consistent in throwing (unspecified) NPE

@@ -259,10 +259,11 @@
      * @param <T> the type of the elements to be compared
      * @return a {@code BinaryOperator} which returns the lesser of its operands,
      * according to the supplied {@code Comparator}
      */
     public static<T> BinaryOperator<T> lesserOf(Comparator<? super T> comparator) {
+        Objects.requireNonNull(comparator);
         return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
     }
 
     /**
      * Constructs a {@link BinaryOperator} which returns the greater of two elements

@@ -272,8 +273,9 @@
      * @param <T> the type of the elements to be compared
      * @return a {@code BinaryOperator} which returns the greater of its operands,
      * according to the supplied {@code Comparator}
      */
     public static<T> BinaryOperator<T> greaterOf(Comparator<? super T> comparator) {
+        Objects.requireNonNull(comparator);
         return (a, b) -> comparator.compare(a, b) >= 0 ? a : b;
     }
 }