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

Calendar.setTime(Date date) throws NPE with Date date = null

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 16
    • core-libs
    • None
    • minimal
    • Long standing behavior is to throw NPE so no compatibility impact.
    • Java API
    • SE

      Summary

      Calendar.setTime(null) throws NullPointerException. This should be specified.

      Problem

      There is no specification in the method description of Calendar.setTime() about a possible NullPointerException.

      Solution

      Add a @throws tag in the method description.

      Specification

      Add the following line in the method description:

      --- a/src/java.base/share/classes/java/util/Calendar.java
      +++ b/src/java.base/share/classes/java/util/Calendar.java
      @@ -1796,8 +1796,10 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
            * @param date the given Date.
            * @see #getTime()
            * @see #setTimeInMillis(long)
      +     * @throws NullPointerException if {@code date} is {@code null}
            */
           public final void setTime(Date date) {

            naoto Naoto Sato
            webbuggrp Webbug Group
            Alan Bateman, Brian Burkhalter, Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: