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

java.util.prefs Preferences behavior of removeNode() different with doc

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      In doc :"Removes this preference node and all of its descendants, invalidating any preferences contained in the removed nodes. Once a node has been removed, attempting any method other than name(), absolutePath(), isUserNode(), flush() or nodeExists("") on the corresponding Preferences instance will fail with an IllegalStateException. (The methods defined on Object can still be invoked on a node after it has been removed; they will not throw IllegalStateException.)"

      Actually I can call node.flush() or node.nodeExists("") successfully.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      java ConflictInFlush.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I think the document should be updated.
      ACTUAL -
      AssertionError after second node.flush()

      ---------- BEGIN SOURCE ----------
      /*
       * @test
       * @bug 4703132 7197662
       * @summary flush() throws an IllegalStateException on a removed node
       * @run main/othervm -Djava.util.prefs.userRoot=. ConflictInFlush
       * @author Sucheta Dambalkar
       */

      import java.util.prefs.*;

      public final class ConflictInFlush {

          public static void main(String args[]) {
              Preferences root = Preferences.userRoot();
              try {
                  Preferences node = root.node("1/2/3");
                  node.flush();
                  System.out.println("Node " + node + " has been created");

                  if (!node.nodeExists("")) {
                      throw new AssertionError("Node should exist after creation");
                  }

                  System.out.println("Removing node " + node);
                  node.removeNode();

                  if (node.nodeExists("")) {
                      throw new AssertionError("Node should not exist after removal");
                  }


                  System.out.println("Attempting to flush removed node...");
                  try {
                      node.flush();
                      throw new AssertionError("Expected IllegalStateException was not thrown");
                  } catch (IllegalStateException ise) {

                      System.out.println("IllegalStateException caught as expected: " + ise.getMessage());
                      System.out.println("Test passed successfully");
                      return;
                  }
              } catch (BackingStoreException bse) {
                  bse.printStackTrace();
                  throw new AssertionError("Unexpected BackingStoreException", bse);
              }

          }
      }
      ---------- END SOURCE ----------

            bchristi Brent Christian
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: