Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-609

PreferencesService might return invalid Preferences object for a user

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • prefs-1.0.2
    • prefs-1.0.4
    • Preferences Service
    • None

    Description

      When a Preferences object has been obtained for a given user, it can be removed using removeNode(). A following call to getUserPreferences(...) will then return the old, now invalid, Preferences object, leading to an IllegalStateException when trying to add new data to the node. From this moment on, it is not possible to obtain a valid Preferences object for this user.

      The spec does not provide a definite answer about this case; 106.4 comes closest with "getUserPreferences(String) - Return a Preferences object associated with the user name that is given as argument. If the user does not exist, a new root is created atomically." Intuitively, one might expect that removeNode() restores the PreferencesService to the same state it was before getUserPreferences(...) was called.

      The invalid Preferences object is caused by caching behavior in PreferencesServicesImpl's getUserPreferences(...), which checks whether a user's root node has already been created; if so, it will be returned, if not, it will be created.

      91 PreferencesImpl result = (PreferencesImpl) this.trees.get(name);
      92 // if the tree does not exist yet, create it
      93 if (result == null)

      { 94 result = new PreferencesImpl(new PreferencesDescription(this.bundleId, name), this.storeManager); 95 this.trees.put(name, result); 96 }

      The most plausible solution is to add an extra clause to the if-statement on line 93, stating something like
      93 if (result == null || !result.isValid()) {
      provided that isValid() will then return the valid field of PreferencesImpl.

      An alternative would be to detect the removal of a node which does not have a parent (is a root node), and then remove it from the PreferencesServiceImpl's trees; this is not that complicated, but requires some extra code.

      Attachments

        Activity

          People

            marrs Marcel Offermans
            angelovds Angelo van der Sijpt
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: