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)
======================================================================