Name: nt126004 Date: 06/28/2002
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Calling Preferences.remove() on a key that does not exist
or has already been removed results in an error message
being logged from WindowsPreferences that Win32 API
RegDeleteValue has returned error code 2 (which is
ERROR_FILE_NOT_FOUND).
It also resets
java.util.prefs.WindowsPreferences.isBackingStoreAvailable
to false, which means Preferences.flush() will throw an
exception instead of storing the pref changes.
The docs for Preferences.remove() say:
"Removes the value associated with the specified key in
this preference node, if any."
The "if any" implies that it is OK to call remove on a non-
existing key - if there is no value it won't be removed
(because it doesn't exist).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached RemovePref.java testcase
2. Observe the error logged
EXPECTED VERSUS ACTUAL BEHAVIOR :
I expect Preferences.remove() to do nothing if the key does
not exist. Instead it logs a warning and disabled flushing
prefs to the registry.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Jun 21, 2002 4:54:57 PM java.util.prefs.WindowsPreferences removeSpi
WARNING: Could not delete windows registry value
Software\JavaSoft\Prefs\<unnamed>\[B@372a1a at root 0x80000001. Windows
RegDeleteValue(...) returned error code 2.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.prefs.*;
public class RemovePref {
public static void main(String args[]) throws Exception {
Preferences prefs = Preferences.userNodeForPackage
(RemovePref.class);
prefs.put("foo", "value");
prefs.remove("foo");
prefs.remove("foo");
}
}
---------- END SOURCE ----------
(Review ID: 153975)
======================================================================
- duplicates
-
JDK-4772255 Preferences.remove() of non-existing key causes warning
-
- Closed
-