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

flush() throws an IllegalStateException on a removed node

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.2
    • 1.4.1
    • core-libs
    • mantis
    • sparc
    • solaris_7
    • Verified



      Name: ngR10108 Date: 06/17/2002



          According to JDK 1.4 documentation (see Preferences.removeNode() javadocs) :

          "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 removal is not guaranteed to be persistent until the flush method is
          called on this node (or an ancestor)"

          But, according to Preferences.flush() javadocs :

          "...
          Throws :
      IllegalStateException - if this node (or an ancestor) has been removed
                                      with the removeNode() method"

          There is a conflict : I have to call flush() to make my changes persistent
          but I can not call flush() because a node has been removed.

          The implementation does demonstrate the conflict. Test case :

      import java.util.prefs.*;

      public final class Prefs14 {

      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");
      System.out.println("Removing node "+node);
      node.removeNode();
      node.flush();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      }

          Result:

          Node User Preference Node: /1/2/3 has been created
          Removing node User Preference Node: /1/2/3
          java.lang.IllegalStateException: Node has been removed
              at java.util.prefs.AbstractPreferences.sync2(AbstractPreferences.java:1311)
              at java.util.prefs.AbstractPreferences.sync(AbstractPreferences.java:1303)
              at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:740)
              at java.util.prefs.FileSystemPreferences.flush(FileSystemPreferences.java:814)
              at Prefs14.main(Prefs14.java:14)

        
      ======================================================================

            jjb Josh Bloch
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: