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

javadoc for Boolean.valueOf(String) with null argument not clearly specified

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 6u10
    • core-libs
    • b121
    • x86
    • linux_ubuntu

      A DESCRIPTION OF THE REQUEST :
      Latest javadoc (http://java.sun.com/javase/7/docs/api/java/lang/Boolean.html) states:

      Returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".
      Parameters:
      s - a string.
      Returns:
      the Boolean value represented by the string.

      While passing in a non-null and equal to "true" is explicitly mentioned, it is only loosely implying (some would say not implying at all) that passing in null would return false as opposed to throwing an exception

      JUSTIFICATION :
      It is not obvious what Boolean.valueOf(null) would return without looking at the java source or past experience with this topic. Other methods' valueOf throw exceptions if the string does not make sense as a parsable equivalent of those objects, so one might believe null with Boolean would work the same way.

      Also note that the method getBoolean(String) does include this statement:
        If there is no property with the specified name, or if the specified
         name is empty or null, then {@code false} is returned.

      so there should be similar explicit comments in valueOf(String)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Here's one example comment that explicitly addresses the null case:

      Returns a {@code Boolean} with a value represented by the
      specified string. The {@code Boolean} returned represents a
      true value if the string argument is not {@code null}
      and is equal, ignoring case, to the string {@code "true"}; returns
      false in all other cases including if the argument is {code null}.

      ACTUAL -
      Javadoc for valueOf(String) says:

      Returns a {@code Boolean} with a value represented by the
      specified string. The {@code Boolean} returned represents a
      true value if the string argument is not {@code null}
      and is equal, ignoring case, to the string {@code "true"}.

      ---------- BEGIN SOURCE ----------
         /**
           * Returns a {@code Boolean} with a value represented by the
           * specified string. The {@code Boolean} returned represents a
           * true value if the string argument is not {@code null}
           * and is equal, ignoring case, to the string {@code "true"}.
           *
           * @param s a string.
           * @return the {@code Boolean} value represented by the string.
           */
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      n/a: developers can look at the src to see the actual behavior

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: