[go: up one dir, main page]

Check if preference values stored in preferences.xml are valid

I just realized we don't properly check for invalid preference values in preferences.xml.

While we have a isValid() function, it only checks if the preference has a (read "any") value in preferences.xml (and returns the default otherwise).

If the preference is set, but the value is invalid, behavior depends on implementation details and returns "arbitrary" values (e.g. zero for int/double as that's what the library functions do in case the string is not a valid number) that might not make sense as a preference value.

A better behavior would therefore be to check if the value is valid and fall-back to the default preference value in all other cases (i.e. preference not set / preference set but invalid).

As we don't strictly define the type of a value, we should likely add isValidInt(), isValidDouble(), etc. functions and test those in addition to isValid() (which should probably be renamed to isSet() or similar).

Edited by Patrick Storz