Bug 475656 - Lock access to non-thread-safe ReferenceMap
Signed-off-by: Hermann Czedik-Eysenberg <hermann.czedik-eysenberg@agfa.com>
Change-Id: Id99490fcef63997291651cf0d5c0fab626f7474a
diff --git a/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF
index e7397c4..aa63a05 100644
--- a/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.registry;singleton:=true
-Bundle-Version: 3.8.100.qualifier
+Bundle-Version: 3.8.200.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.core.internal.adapter;x-internal:=true,
org.eclipse.core.internal.registry;x-friends:="org.eclipse.core.runtime",
diff --git a/bundles/org.eclipse.equinox.registry/pom.xml b/bundles/org.eclipse.equinox.registry/pom.xml
index 803983f..8eb6b6b 100644
--- a/bundles/org.eclipse.equinox.registry/pom.xml
+++ b/bundles/org.eclipse.equinox.registry/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.registry</artifactId>
- <version>3.8.100-SNAPSHOT</version>
+ <version>3.8.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java
index 83e9593..4ba193b 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java
@@ -18,6 +18,8 @@
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.core.internal.registry.*;
import org.eclipse.core.internal.runtime.ResourceTranslator;
@@ -136,6 +138,8 @@
*/
private final ReferenceMap bundleMap = new ReferenceMap(ReferenceMap.SOFT, DEFAULT_BUNDLECACHE_SIZE, DEFAULT_BUNDLECACHE_LOADFACTOR);
+ private ReadWriteLock bundleMapLock = new ReentrantReadWriteLock();
+
// String Id to OSGi Bundle conversion
private Bundle getBundle(String id) {
if (id == null)
@@ -149,11 +153,23 @@
// We assume here that OSGI Id will fit into "int". As the number of
// registry elements themselves are expected to fit into "int", this
// is a valid assumption for the time being.
- Bundle bundle = (Bundle) bundleMap.get((int) OSGiId);
+ Bundle bundle;
+ bundleMapLock.readLock().lock();
+ try {
+ bundle = (Bundle) bundleMap.get((int) OSGiId);
+ } finally {
+ bundleMapLock.readLock().unlock();
+ }
if (bundle != null)
return bundle;
+ // note: we accept that two concurrent threads end up here for the same id, because they will anyway resolve the same mapping
bundle = Activator.getContext().getBundle(OSGiId);
- bundleMap.put((int) OSGiId, bundle);
+ bundleMapLock.writeLock().lock();
+ try {
+ bundleMap.put((int) OSGiId, bundle);
+ } finally {
+ bundleMapLock.writeLock().unlock();
+ }
return bundle;
}