Modify ↓

#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?

  1. Start JOSM, use it for a while, exit
  2. Look in the cache directory (e.g. ~/.cache/JOSM on 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.

Attachments (1)

defaults-cache-save.patch​ (6.1 KB ) - added by wangi 18 minutes ago.

Download all attachments as: .zip

Change History (1)

by wangi, 18 minutes ago

Attachment: defaults-cache-save.patch​ added

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to wangi.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.