Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8204959

Predicate::not should explicitly mention "NullPointerException - if target is null"

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 11
    • core-libs
    • None
    • minimal
    • Java API

      Summary

      Report that the method throws a NullPointerException and specify that the method calls the negate method of target argument.

      Problem

      The current Javadoc does not indicate that the method explicitly checks for a null target. Also, the method should indicate that the target Predicate's negate method is called to produce the result.

      Solution

      Update the Javadoc.

      Specification

      /**
       * Returns a predicate that is the negation of the supplied predicate.
       * This is accomplished by returning result of the calling
       * {@code target.negate()}.
       *
       * @param <T>     the type of arguments to the specified predicate
       * @param target  predicate to negate
       *
       * @return a predicate that negates the results of the supplied
       *         predicate
       *
       * @throws NullPointerException if target is null
       *
       * @since 11
       */
      @SuppressWarnings("unchecked")
      static <T> Predicate<T> not(Predicate<? super T> target) {
          Objects.requireNonNull(target);
          return (Predicate<T>)target.negate();
      }

            jlaskey Jim Laskey
            dbessono Dmitry Bessonov
            Paul Sandoz, Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: