Opened 13 minutes ago
#25147 new defect
[PATCH] Default preferences cache is never saved
| Reported by: | wangi | Owned by: | team |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Core | Version: | |
| Keywords: | preferences | Cc: |
Description
The default preferences cache is never saved.
What steps will reproduce the problem?
- Start JOSM, use it for a while, exit
- Look in the cache directory (e.g.
~/.cache/JOSMon Linux)
What is the expected result?
default_preferences.xml is written, so that the next session knows the defaults of all settings, as used by the advanced preferences (#12522) and the colour preferences.
What happens instead?
Only default_preferences.xml_tmp exists, rewritten at every exit. At debug level the log shows:
Invalid preferences file (.../default_preferences.xml_tmp) due to: ParseError at [row,col]:[2,146] Message: Expected element 'preferences', but got 'preferences-defaults'
Please provide any additional information below. Attach a screenshot if possible.
r19179 (#23802) validates a preferences file before it is backed up or moved into place. Preferences.checkFileValidity() always parses it with new PreferencesReader(file, false), which expects a <preferences> root element. The defaults cache file is written with <preferences-defaults>, so the check fails, the failure is only logged at debug level, and the file is never moved from _tmp to default_preferences.xml. An existing defaults file wouldn't be backed up either, for the same reason.
As a result, since r19179 the advanced preferences only list the defaults of settings used in the current session, and Preferences.loadDefaults() never has a file to read.
Attached is a patch against r19718: save() passes its defaults flag to checkFileValidity(), which parses the file accordingly.
Unit test PreferencesTest.testSaveDefaults: the defaults cache file is saved (not left as _tmp), can be loaded again, and is backed up at the next save. It fails without the patch. The test needs the same temporary preferences directories as testObsoleteOAuth10aTokenIsRemoved, so their setup moved to a directories(Path) helper used by both; that test itself is unchanged, although the diff makes its assertions look moved. All tests in org.openstreetmap.josm.data.Preferences*, org.openstreetmap.josm.data.preferences and org.openstreetmap.josm.gui.preferences.advanced pass; checkstyle and PMD are clean.


