[
https://issues.apache.org/jira/browse/FELIX-609?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Angelo van der Sijpt updated FELIX-609:
---------------------------------------
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.
was:
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.
Typo.
> PreferencesService might return invalid Preferences object for a user
> ---------------------------------------------------------------------
>
> Key: FELIX-609
> URL: https://issues.apache.org/jira/browse/FELIX-609
> Project: Felix
> Issue Type: Bug
> Components: Preferences Service
> Reporter: Angelo van der Sijpt
>
> 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.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.