Probably you are affected by this bug:
https://bugs.openjdk.java.net/browse/JDK-8068373
(prefs) FileSystemPreferences writes \0 to XML storage, causing loss
of all preferences
If you call prefs.put(key, "some string with \0 in it")
...
The XML writer happily writes the \0
into the file. I think it escapes
it, but as already mentioned, this is pointless. Then later, when you
try to read it back in, the XML file is invalid. You get a warning on
the logs about the preferences file being invalid and all your
preferences are wiped.
ADDITIONAL OS VERSION INFORMATION:
Occurs on all
flavours of Linux we have tested. Issue is also reproducible on any
platform if you deliberately use this PreferencesFactory.
You also get the following output on stderr:
Dec 29, 2014 9:19:19 AM java.util.prefs.FileSystemPreferences$6 run
WARNING: Invalid preferences format in /Users/daniel/.java/.userPrefs/com/acme/testing/prefs.xml
Dec 29, 2014 9:19:19 AM java.util.prefs.FileSystemPreferences$6 run
WARNING: Prefs file removed in background /Users/daniel/.java/.userPrefs/com/acme/testing/prefs.xml
Solution: update to Java 9+