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

(prefs) AbstractPreferences.remove(null) does not throw NPE

XMLWordPrintable

    • b40
    • generic
    • generic
    • Verified

      Specification for the method (spec it is the same for SE8)

      http://docs.oracle.com/javase/7/docs/api/java/util/prefs/AbstractPreferences.html#remove%28java.lang.String%29

      says:

      Implements the remove(String) method as per the specification in Preferences.remove(String).

      While this is not true as

      http://docs.oracle.com/javase/7/docs/api/java/util/prefs/Preferences.html#remove%28java.lang.String%29

      Specifies assertion

       Throws:
           NullPointerException - if key is null.

      Which is not satisfied by java.util.prefs.AbstractPreferences.remove(String)

      The specification or the implementation should be updated.

      Please see below a code sample illustrating the problem:

      ---------------------------------------------------------
      import java.util.prefs.AbstractPreferences;
      import java.util.prefs.BackingStoreException;
      import java.util.prefs.Preferences;

      public class AbstrPrefNoNPE {

          public static void main(String[] args) {
              ABSTR_PREFS.remove(null);
              System.out.println("Test failure: No NPE was thrown");
          }

          static Preferences ABSTR_PREFS = new AbstractPreferences(null, "") {
              @Override
              protected void putSpi(String key, String value) {
              }
              @Override
              protected String getSpi(String key) {
                  return null;
              }
              @Override
              protected void removeSpi(String key) {
              }
              @Override
              protected void removeNodeSpi() throws BackingStoreException {
              }
              @Override
              protected String[] keysSpi() throws BackingStoreException {
                  return new String[0];
              }
              @Override
              protected String[] childrenNamesSpi() throws BackingStoreException {
                  return new String[0];
              }
              @Override
              protected AbstractPreferences childSpi(String name) {
                  return null;
              }
              @Override
              protected void syncSpi() throws BackingStoreException {
              }
              @Override
              protected void flushSpi() throws BackingStoreException {
              }
          };
      }
      ---------------------------------------------------------

      The following conformance test will fail due to this problem:

      api/java_util/prefs/Preferences/index.html#NPETests[remove]

            khazra Kurchi Subhra Hazra
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: