[351599] ConcurrentModificationException on faceted project creation
diff --git a/features/org.eclipse.wst.common_core.feature.patch/buildnotes_org.eclipse.wst.common_core.feature.patch.html b/features/org.eclipse.wst.common_core.feature.patch/buildnotes_org.eclipse.wst.common_core.feature.patch.html
index 5125c14..e7bf638 100644
--- a/features/org.eclipse.wst.common_core.feature.patch/buildnotes_org.eclipse.wst.common_core.feature.patch.html
+++ b/features/org.eclipse.wst.common_core.feature.patch/buildnotes_org.eclipse.wst.common_core.feature.patch.html
@@ -44,6 +44,6 @@
 <p>Bug <a href='https://bugs.eclipse.org/322173'>322173</a>. J2EEDeployOperation does not allow callers to get a list of affected projects</p>
 <p>Bug <a href='https://bugs.eclipse.org/328320'>328320</a>. NPE in EarUtilities.getReferencingEARProjects()</p>
 <p>Bug <a href='https://bugs.eclipse.org/329997'>329997</a>. JSP Syntax Validators show error markers even when the build based markers are turned off.</p>
-
+<p>Bug <a href='https://bugs.eclipse.org/351599'>351599</a>. ConcurrentModificationException on faceted project creation.</p>
 </body>
 </html>
\ No newline at end of file
diff --git a/features/org.eclipse.wst.common_core.feature.patch/feature.properties b/features/org.eclipse.wst.common_core.feature.patch/feature.properties
index 2435577..2fd69c3 100644
--- a/features/org.eclipse.wst.common_core.feature.patch/feature.properties
+++ b/features/org.eclipse.wst.common_core.feature.patch/feature.properties
@@ -58,6 +58,7 @@
 Bug https://bugs.eclipse.org/322173 J2EEDeployOperation does not allow callers to get a list of affected projects\n\
 Bug https://bugs.eclipse.org/328320 NPE in EarUtilities.getReferencingEARProjects()\n\
 Bug https://bugs.eclipse.org/329997 JSP Syntax Validators show error markers even when the build based markers are turned off.\n\
+Bug https://bugs.eclipse.org/351599 ConcurrentModificationException on faceted project creation.\n\
 \n\
 # "copyright" property - text of the "Feature Update Copyright"
 copyright=\
diff --git a/features/org.eclipse.wst.common_core.feature.patch/feature.xml b/features/org.eclipse.wst.common_core.feature.patch/feature.xml
index 4e1cc83..181a851 100644
--- a/features/org.eclipse.wst.common_core.feature.patch/feature.xml
+++ b/features/org.eclipse.wst.common_core.feature.patch/feature.xml
@@ -22,6 +22,13 @@
    </requires>
 
    <plugin
+         id="org.eclipse.wst.common.emfworkbench.integration"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
          id="org.eclipse.wst.common.emf"
          download-size="0"
          install-size="0"
diff --git a/plugins/org.eclipse.jem.util/META-INF/MANIFEST.MF b/plugins/org.eclipse.jem.util/META-INF/MANIFEST.MF
index d676f89..aea47f3 100644
--- a/plugins/org.eclipse.jem.util/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jem.util/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jem.util; singleton:=true
-Bundle-Version: 2.0.104.qualifier
+Bundle-Version: 2.0.105.qualifier
 Bundle-Activator: org.eclipse.jem.util.plugin.JEMUtilPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.jem.util/jemutil/org/eclipse/jem/internal/util/emf/workbench/ProjectResourceSetImpl.java b/plugins/org.eclipse.jem.util/jemutil/org/eclipse/jem/internal/util/emf/workbench/ProjectResourceSetImpl.java
index 206e393..6296726 100644
--- a/plugins/org.eclipse.jem.util/jemutil/org/eclipse/jem/internal/util/emf/workbench/ProjectResourceSetImpl.java
+++ b/plugins/org.eclipse.jem.util/jemutil/org/eclipse/jem/internal/util/emf/workbench/ProjectResourceSetImpl.java
@@ -10,7 +10,7 @@
  *******************************************************************************/
 /*
  *  $$RCSfile: ProjectResourceSetImpl.java,v $$
- *  $$Revision: 1.21.2.1.2.4 $$  $$Date: 2010/02/18 04:36:00 $$ 
+ *  $$Revision: 1.21.2.1.2.5 $$  $$Date: 2011/07/21 20:45:23 $$ 
  */
 package org.eclipse.jem.internal.util.emf.workbench;
 
@@ -22,8 +22,7 @@
 import org.eclipse.core.runtime.content.IContentDescription;
 import org.eclipse.core.runtime.jobs.ILock;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.*;
 import org.eclipse.emf.common.notify.impl.NotificationImpl;
 import org.eclipse.emf.common.util.*;
 import org.eclipse.emf.ecore.EObject;
@@ -45,6 +44,247 @@
 		public static final int MODULE_NAME_INDX = 2;
 		public static final int CONTENT_TYPE_INDX = 3;
 	}
+	public class ImmutableEList<E extends Object & Resource> extends ResourcesEList<E> implements EList<E> {
+		
+		
+		private SynchronizedResourcesEList delegate;
+
+		public ImmutableEList(Collection<? extends E> collection) {
+
+		    size = collection.size();
+
+		    // Conditionally create the data.
+		    //
+		    if (size > 0)
+		    { 
+		      // Allow for a bit-shift of growth.
+		      //
+		      data = newData(size + size / 8 + 1); 
+		      collection.toArray(data);
+		    
+		    }
+			delegate = (SynchronizedResourcesEList)collection;
+			
+		}
+
+		@Override
+		public void setData(int size, Object[] data) {
+			super.setData(size, data);
+			delegate.lock.acquire();
+			delegate.setData(size, data);
+			delegate.lock.release();
+		}
+
+		@Override
+		public E setUnique(int index, E object) {
+			Object temp;
+			super.setUnique(index, object);
+			delegate.lock.acquire();
+			temp = delegate.setUnique(index, object);
+			delegate.lock.release();
+			return (E) temp;
+		}
+
+		@Override
+		public void addUnique(E object) {
+			super.addUnique(object);
+			delegate.lock.acquire();
+			delegate.addUnique(object);
+			delegate.lock.release();
+		}
+
+		@Override
+		public void addUnique(int index, E object) {
+			super.addUnique(index, object);
+			delegate.lock.acquire();
+			delegate.addUnique(index, object);
+			delegate.lock.release();
+		}
+
+		@Override
+		public boolean addAllUnique(Collection<? extends E> collection) {
+			boolean temp;
+			super.addAllUnique(collection);
+			delegate.lock.acquire();
+			temp = delegate.addAllUnique(collection);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean addAllUnique(int index, Collection<? extends E> collection) {
+			boolean temp;
+			super.addAllUnique(index, collection);
+			delegate.lock.acquire();
+			temp = delegate.addAllUnique(index, collection);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean addAllUnique(Object[] objects, int start, int end) {
+			boolean temp;
+			super.addAllUnique(objects, start, end);
+			delegate.lock.acquire();
+			temp = delegate.addAllUnique(objects, start, end);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean addAllUnique(int index, Object[] objects, int start, int end) {
+			boolean temp;
+			super.addAllUnique(index, objects, start, end);
+			delegate.lock.acquire();
+			temp = delegate.addAllUnique(index, objects, start, end);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public E remove(int index) {
+			Object temp;
+			super.remove(index);
+			delegate.lock.acquire();
+			temp = delegate.remove(index);
+			delegate.lock.release();
+			return (E)temp;
+		}
+
+		@Override
+		public E move(int targetIndex, int sourceIndex) {
+			Object temp;
+			super.move(targetIndex, sourceIndex);
+			delegate.lock.acquire();
+			temp = delegate.move(targetIndex, sourceIndex);
+			delegate.lock.release();
+			return (E) temp;
+		}
+
+		@Override
+		public E set(int index, E object) {
+			Object temp;
+			super.set(index, object);
+			delegate.lock.acquire();
+			temp = delegate.set(index, object);
+			delegate.lock.release();
+			return (E) temp;
+		}
+
+		@Override
+		public boolean add(E object) {
+			boolean temp;
+			super.add(object);
+			delegate.lock.acquire();
+			temp = delegate.add(object);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public void add(int index, E object) {
+			super.add(index, object);
+			delegate.lock.acquire();
+			delegate.add(index, object);
+			delegate.lock.release();
+		}
+
+		@Override
+		public boolean addAll(Collection<? extends E> collection) {
+			boolean temp;
+			super.addAll(collection);
+			delegate.lock.acquire();
+			temp = delegate.addAll(collection);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean addAll(int index, Collection<? extends E> collection) {
+			boolean temp;
+			super.addAll(index, collection);
+			delegate.lock.acquire();
+			temp = delegate.addAll(index, collection);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean remove(Object object) {
+			boolean temp;
+			super.remove(object);
+			delegate.lock.acquire();
+			temp = delegate.remove(object);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean removeAll(Collection<?> collection) {
+			boolean temp;
+			super.removeAll(collection);
+			delegate.lock.acquire();
+			temp = delegate.removeAll(collection);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public boolean retainAll(Collection<?> collection) {
+			boolean temp;
+			super.retainAll(collection);
+			delegate.lock.acquire();
+			temp = delegate.retainAll(collection);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public void move(int index, E object) {
+			super.move(index, object);
+			delegate.lock.acquire();
+			delegate.move(index, object);
+			delegate.lock.release();
+		}
+
+		private static final long serialVersionUID = 1L;
+
+		@Override
+		public NotificationChain basicAdd(E object, NotificationChain notifications) {
+			NotificationChain temp = super.basicAdd(object, notifications);
+			delegate.lock.acquire();
+			delegate.basicAdd(object, notifications);
+			delegate.lock.release();
+			return temp;
+			
+		}
+
+		@Override
+		public NotificationChain basicRemove(Object object, NotificationChain notifications) {
+			NotificationChain temp = super.basicRemove(object, notifications);
+			delegate.lock.acquire();
+			delegate.basicRemove(object, notifications);
+			delegate.lock.release();
+			return temp;
+		}
+
+		@Override
+		public void clear() {
+			super.clear();
+			delegate.lock.acquire();
+			delegate.clear();
+			delegate.lock.release();
+		}
+
+		@Override
+		public NotificationChain basicSet(int index, E object, NotificationChain notifications) {
+			NotificationChain temp = super.basicSet(index, object, notifications);
+			delegate.lock.acquire();
+			delegate.basicSet(index, object, notifications);
+			delegate.lock.release();
+			return temp;
+		}
+	}
 	
 	public class SynchronizedResourcesEList<E extends Object & Resource> extends ResourcesEList<E> implements EList<E> {
 
@@ -52,7 +292,7 @@
 		 * 
 		 */
 		private static final long serialVersionUID = 1L;
-		private final ILock lock = Job.getJobManager().newLock();
+		protected final ILock lock = Job.getJobManager().newLock();
 
 		public void move(int newPosition, E object) {
 			
@@ -881,12 +1121,23 @@
 	}
 	
 	public EList<Resource> getResources() {
+		 return primGetResources();
+	}
+	private EList<Resource> primGetResources() {
 		 if (resources == null)
 		    {
 		      resources = new SynchronizedResourcesEList<Resource>();
 		    }
 		    return resources;
 	}
+	/**
+	 * Creating a copy of the resources list
+	 * @return
+	 */
+	public EList<Resource> getImmutableResources() {
+		 EList<Resource> resources = primGetResources();
+		 return new ImmutableEList<Resource>(resources);
+	}
 	@Override
 	public void eNotify(Notification notification) {
 	    Adapter[] eAdapters = eBasicAdapterArray();
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.common.emfworkbench.integration/META-INF/MANIFEST.MF
index 6afb47c..9ea08d4 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.wst.common.emfworkbench.integration; singleton:=true
-Bundle-Version: 1.1.202.qualifier
+Bundle-Version: 1.1.203.qualifier
 Bundle-Activator: org.eclipse.wst.common.internal.emfworkbench.integration.EMFWorkbenchEditPlugin
 Bundle-Vendor: %pluginVendor
 Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
index 3718afe..c8e7286 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
@@ -45,6 +45,7 @@
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.jem.internal.util.emf.workbench.EMFWorkbenchContextFactory;
+import org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl;
 import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
 import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
 import org.eclipse.jem.util.logger.proxy.Logger;
@@ -435,11 +436,17 @@
 	protected List getResources(IFile aFile) {
 
 		List resources = new ArrayList();
-		List allResources = resourceSet.getResources();
+		List allResources = null;
+		if (resourceSet instanceof ProjectResourceSetImpl) {
+            ProjectResourceSetImpl projResSet =(ProjectResourceSetImpl)resourceSet;
+            allResources = projResSet.getImmutableResources();
+        } else {
+            allResources = resourceSet.getResources();
+        }
 		for (Iterator iterator = allResources.iterator(); iterator.hasNext();) {
 			Resource res = (Resource) iterator.next();
 			URI resURI = res.getURI();
-			String resURIString = "";
+			String resURIString = ""; //$NON-NLS-1$
 			if (resURI.path() != null) {
 				IPath resURIPath;
 				if (WorkbenchResourceHelper.isPlatformResourceURI(resURI))
@@ -448,7 +455,7 @@
 					resURIPath = new Path(URI.decode(resURI.path())).removeFirstSegments(1);
 				resURIString = resURIPath.toString();
 			}
-			if (!resURIString.equals("") && aFile.getFullPath().toString().indexOf(resURIString) != -1)
+			if (!resURIString.equals("") && aFile.getFullPath().toString().indexOf(resURIString) != -1) //$NON-NLS-1$
 				resources.add(res);
 		}
 		return resources;