FULL PRODUCT VERSION :
JDK 1.5.0_01
A DESCRIPTION OF THE PROBLEM :
The Preferences.put(String, String) method throws a SecurityException when the documentation does not state so, and the general description of how Preferences are implemented indicates that puts are to an in memory location and only after a sync, which can throw a BackingStoreException, will the values be persisted.
Here the put is apparently followed by an implicit sync, which fails (for obvious reasons of not having the permission to write the HKEY_LOCAL_MACHINE registry hive) not with a BackingStoreException, but with a SecurityException.
At the very least the method should document the possible failure using a SecurityException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to put a value in a System Preferences node when the current user running the process does not have Admin privileges on the machine, and thus cannot write to HKEY_LOCAL_MACHINE.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The put should succeeded, and later on a BackingStoreException should be thrown during an explicit or implicit sync.
ACTUAL -
An unexpected and undocumented exception is thrown by a simple put().
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.SecurityException: Could not open windows registry node Software\JavaSoft\Prefs\com\lgc\buildmagic at root 0x80000002: Access denied
at java.util.prefs.WindowsPreferences.openKey(WindowsPreferences.java:496)
at java.util.prefs.WindowsPreferences.openKey(WindowsPreferences.java:463)
at java.util.prefs.WindowsPreferences.openKey(WindowsPreferences.java:449)
at java.util.prefs.WindowsPreferences.putSpi(WindowsPreferences.java:595)
at java.util.prefs.AbstractPreferences.put(AbstractPreferences.java:234)
at com.lgc.buildmagic.BuildNumber.getPreferences(BuildNumber.java:201)
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Don't write to System Prefs but the User prefs instead.
JDK 1.5.0_01
A DESCRIPTION OF THE PROBLEM :
The Preferences.put(String, String) method throws a SecurityException when the documentation does not state so, and the general description of how Preferences are implemented indicates that puts are to an in memory location and only after a sync, which can throw a BackingStoreException, will the values be persisted.
Here the put is apparently followed by an implicit sync, which fails (for obvious reasons of not having the permission to write the HKEY_LOCAL_MACHINE registry hive) not with a BackingStoreException, but with a SecurityException.
At the very least the method should document the possible failure using a SecurityException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to put a value in a System Preferences node when the current user running the process does not have Admin privileges on the machine, and thus cannot write to HKEY_LOCAL_MACHINE.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The put should succeeded, and later on a BackingStoreException should be thrown during an explicit or implicit sync.
ACTUAL -
An unexpected and undocumented exception is thrown by a simple put().
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.SecurityException: Could not open windows registry node Software\JavaSoft\Prefs\com\lgc\buildmagic at root 0x80000002: Access denied
at java.util.prefs.WindowsPreferences.openKey(WindowsPreferences.java:496)
at java.util.prefs.WindowsPreferences.openKey(WindowsPreferences.java:463)
at java.util.prefs.WindowsPreferences.openKey(WindowsPreferences.java:449)
at java.util.prefs.WindowsPreferences.putSpi(WindowsPreferences.java:595)
at java.util.prefs.AbstractPreferences.put(AbstractPreferences.java:234)
at com.lgc.buildmagic.BuildNumber.getPreferences(BuildNumber.java:201)
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Don't write to System Prefs but the User prefs instead.