From d91efcae543057148210eb78a776790859f635c2 Mon Sep 17 00:00:00 2001 From: Sarika Sinha Date: Thu, 3 Dec 2015 16:27:00 +0530 Subject: Bug 474006 - ConcurrentModificationException in getLineTrackers (270) Change-Id: I4181f3e41e237b7520e53068f43a0d989ad69081 --- .../ui/views/console/ProcessConsoleManager.java | 45 +++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsoleManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsoleManager.java index e4669a68d..c1cc89c2c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsoleManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsoleManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -63,7 +63,11 @@ public class ProcessConsoleManager implements ILaunchListener { * Map of processes for a launch to compute removed processes */ private Map fProcesses; - + + /** + * Lock for fLineTrackers + */ + private Object fLineTrackersLock = new Object(); /** * @see ILaunchListener#launchRemoved(ILaunch) */ @@ -248,32 +252,37 @@ public class ProcessConsoleManager implements ILaunchListener { String type = process.getAttribute(IProcess.ATTR_PROCESS_TYPE); if (fLineTrackers == null) { - fLineTrackers = new HashMap>(); - IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_CONSOLE_LINE_TRACKERS); - IConfigurationElement[] elements = extensionPoint.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement extension = elements[i]; - String processType = extension.getAttribute("processType"); //$NON-NLS-1$ - List list = fLineTrackers.get(processType); - if (list == null) { - list = new ArrayList(); - fLineTrackers.put(processType, list); - } - list.add(extension); - } + synchronized (fLineTrackersLock) { // can't use fLineTrackers as lock as it is null here + fLineTrackers = new HashMap>(); + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_CONSOLE_LINE_TRACKERS); + IConfigurationElement[] elements = extensionPoint.getConfigurationElements(); + for (int i = 0; i < elements.length; i++) { + IConfigurationElement extension = elements[i]; + String processType = extension.getAttribute("processType"); //$NON-NLS-1$ + List list = fLineTrackers.get(processType); + if (list == null) { + list = new ArrayList(); + fLineTrackers.put(processType, list); + } + list.add(extension); + } + } } ArrayList trackers = new ArrayList(); if (type != null) { - List lineTrackerExtensions = fLineTrackers.get(type); + List lineTrackerExtensions; + synchronized (fLineTrackers) {// need to synchronize as the update to list might be still happening + lineTrackerExtensions = fLineTrackers.get(type); + } if(lineTrackerExtensions != null) { for (IConfigurationElement element : lineTrackerExtensions) { - try { + try { trackers.add((IConsoleLineTracker) element.createExecutableExtension("class")); //$NON-NLS-1$ } catch (CoreException e) { DebugUIPlugin.log(e); } - } + } } } return trackers.toArray(new IConsoleLineTracker[0]); -- cgit v1.2.3