Bug 178110 - [Contributions] ObjectContributorManager is not thread-safe
Summary: [Contributions] ObjectContributorManager is not thread-safe
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-19 14:23 EDT by Nick Edgar CLA
Modified: 2019-09-06 15:31 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Edgar CLA 2007-03-19 14:23:05 EDT
3.3 M5

ObjectContributorManager is accessed from multiple threads (e.g. the UI thread for object contributions, the decoration thread for decorations, and a runtime notification thread for IExtensionChangeHandler notifications), but does not protect its fields.

I noticed this while looking into the decorator optimizations (see bug 177392 and bug 177592).

For example, getAdaptableContributors does:
	if (adaptableLookup != null) {
		adaptableList = (List) adaptableLookup.get(adapterType);
	}
but if flushLookup() gets called between these two statements due to a registry change, the second statement may fail with an NPE.

Or, if both the decoration thread and UI thread try to update the caches simultaneously, it could fail, or they could get corrupted.

I also noticed that AdapterManager tries to protect itself, but not by using the synchronized keyword.  E.g. AdapterManager.getFactories(Class) has:
    private Map getFactories(Class adaptable) {
	//cache reference to lookup to protect against concurrent flush
	Map lookup = adapterLookup;
	if (lookup == null)
		adapterLookup = lookup = Collections.synchronizedMap(new HashMap(30));
	Map table = (Map) lookup.get(adaptable.getName());
	...
Note the extra local var 'lookup' to avoid a second read on 'adapterLookup', and the use of a synchronized map wrapper.

We could use the same approach in ObjectContributorManager, but I'm not sure this is actually a good workaround.  E.g. in a multi-processor, you could end up with multiple maps hanging around for a while.
For more on this, see:
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Comment 1 Nick Edgar CLA 2007-03-19 14:24:31 EDT
LegacyResourceSupport has the same issue.
Comment 2 Eclipse Webmaster CLA 2019-09-06 15:31:54 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.