Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove now unnecessary calls to String.intern() in PreferencesService #462

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,8 @@ public IStatus applyPreferences(IExportedPreferences preferences) throws CoreExc
List<String> propsToRemove = new ArrayList<>(Arrays.asList(globalNode.keys()));
if (keys.length > 0) {
for (String key : keys) {
// preferences that are not in the applied node
// will be removed
// preferences that are not in the applied node will be removed
propsToRemove.remove(key);
// intern strings we import because some people
// in their property change listeners use identity
// instead of equals. See bug 20193 and 20534.
key = key.intern();
String value = node.get(key, null);
if (value != null) {
if (EclipsePreferences.DEBUG_PREFERENCE_SET) {
Expand All @@ -149,8 +144,12 @@ public IStatus applyPreferences(IExportedPreferences preferences) throws CoreExc
}
}
}
if (!propsToRemove.isEmpty() && !(globalNode instanceof EclipsePreferences)) {
// intern strings we import because some people in their property change
// listeners use identity instead of equals. See bug 20193 and 20534.
propsToRemove.replaceAll(String::intern);
}
Comment on lines +147 to +151
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elements in the keys array above are obtained from an ExportedPreferences, which is a subclass of EclipsePreference and therefore has its keys already interned (unless somebody extends this internl class and changes the method to store elements, but those that do that should take care of interning themself).

On the other hand globalNode is just a IEclipsePreferences node from the tree and because Clients may implement this interface, it can be an arbitrary implementation. Therefore interning propsToRemove can only be skipped if the node is of a EclipsePreferences subclass.

In general I would call the listeners that rely on string identity comparison badly implemented.

for (String keyToRemove : propsToRemove) {
keyToRemove = keyToRemove.intern();
if (EclipsePreferences.DEBUG_PREFERENCE_SET) {
PrefsMessages.message("Removing: " + globalNode.absolutePath() + '/' + keyToRemove); //$NON-NLS-1$
}
Expand Down
Loading