common: Concurrency fixes in TraceCompassActivator
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 15 Jun 2015 18:33:48 +0000 (14:33 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 29 Jun 2015 23:21:08 +0000 (19:21 -0400)
The TraceCompassActivator class (which can be used as base for any
Activator in every plugin) tracks all the loaded activators in a map.

Add a bit of synchronization to make sure this map cannot be victim
of unexpected concurrent accesses.

Change-Id: Ia94899dfb140a5bf740e3cc6343f6d43579dd777
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/50752
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
common/org.eclipse.tracecompass.common.core/src/org/eclipse/tracecompass/common/core/TraceCompassActivator.java

index 94b2138483f3ba5d0f66582a77000edddc82b7d8..5b494affce2e20ee2210266e9545989a2cd4dff9 100644 (file)
@@ -12,6 +12,9 @@
 
 package org.eclipse.tracecompass.common.core;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,7 +37,7 @@ public abstract class TraceCompassActivator extends Plugin {
 
     /** Map of all the registered activators, indexed by plugin ID */
     private static final Map<String, TraceCompassActivator> ACTIVATORS =
-            new HashMap<>();
+            checkNotNull(Collections.synchronizedMap(new HashMap<String, TraceCompassActivator>()));
 
     /** This instance's plug-in ID */
     private final String fPluginId;
@@ -105,10 +108,12 @@ public abstract class TraceCompassActivator extends Plugin {
     public final void start(@Nullable BundleContext context) throws Exception {
         super.start(context);
         String id = this.getPluginId();
-        if (ACTIVATORS.containsKey(id)) {
-            logError("Duplicate Activator ID : " + id); //$NON-NLS-1$
+        synchronized (ACTIVATORS) {
+            if (ACTIVATORS.containsKey(id)) {
+                logError("Duplicate Activator ID : " + id); //$NON-NLS-1$
+            }
+            ACTIVATORS.put(id, this);
         }
-        ACTIVATORS.put(id, this);
         startActions();
     }
 
This page took 0.0370740000000001 seconds and 5 git commands to generate.