summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeaceslav Bacu2012-06-19 15:44:23 (EDT)
committer Andrew Gvozdev2012-06-19 15:44:23 (EDT)
commit582b358f0fda6d028ee50f92774c1db7cfa33897 (patch)
tree5c49a78bbbe2ee7d9db23478f8d5a02583b3bda6
parent5a964614c4493757f0952d32afc13ae0d79a309e (diff)
downloadorg.eclipse.cdt-582b358f0fda6d028ee50f92774c1db7cfa33897.zip
org.eclipse.cdt-582b358f0fda6d028ee50f92774c1db7cfa33897.tar.gz
org.eclipse.cdt-582b358f0fda6d028ee50f92774c1db7cfa33897.tar.bz2
bug 348884: ConcurrentModificationException in StorableCdtVariables
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/StorableCdtVariablesTest.java74
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java2
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java24
3 files changed, 94 insertions, 6 deletions
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/StorableCdtVariablesTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/StorableCdtVariablesTest.java
new file mode 100644
index 0000000..9fd559e
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/StorableCdtVariablesTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Veaceslav Bacu (Freescale Semiconductor Inc.) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Veaceslav Bacu (Freescale Semiconductor Inc.) - initial API and implementation (bug 348884)
+ *
+ *******************************************************************************/
+
+package org.eclipse.cdt.utils;
+
+import java.util.ConcurrentModificationException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
+import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.testplugin.ResourceHelper;
+import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariable;
+import org.eclipse.core.resources.IProject;
+
+public class StorableCdtVariablesTest extends TestCase {
+
+ public static Test suite() {
+ return new TestSuite(StorableCdtVariablesTest.class);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ ResourceHelper.cleanUp();
+ }
+
+ /*
+ * Unit test for Bugzilla #348884
+ */
+ public void testSetMacros() throws Exception {
+ IProject project = ResourceHelper.createCDTProjectWithConfig("projectWithUserVars"); //$NON-NLS-1$
+
+ ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
+ ICConfigurationDescription desc = prjDesc.getActiveConfiguration();
+
+ StorableCdtVariable varA1 = new StorableCdtVariable("A1", ICdtVariable.VALUE_TEXT, "a1"); //$NON-NLS-1$ //$NON-NLS-2$
+ StorableCdtVariable varA2 = new StorableCdtVariable("A2", ICdtVariable.VALUE_TEXT, "a2"); //$NON-NLS-1$ //$NON-NLS-2$
+ StorableCdtVariable varA3 = new StorableCdtVariable("A3", ICdtVariable.VALUE_TEXT, "a3"); //$NON-NLS-1$ //$NON-NLS-2$
+ StorableCdtVariable varA4 = new StorableCdtVariable("A4", ICdtVariable.VALUE_TEXT, "a4"); //$NON-NLS-1$ //$NON-NLS-2$
+ StorableCdtVariable varA5 = new StorableCdtVariable("A5", ICdtVariable.VALUE_TEXT, "a5"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ IUserVarSupplier supplier = CCorePlugin.getUserVarSupplier();
+
+ try{
+ supplier.setMacros(new ICdtVariable[]{varA1, varA2, varA3, varA4}, desc);
+ }catch(Throwable e){
+ fail("1.0 Cannot set macros"); //$NON-NLS-1$
+ }
+
+ try{
+ supplier.setMacros(new ICdtVariable[]{varA1, varA2, varA5}, desc);
+ }catch(ConcurrentModificationException e){
+ fail("1.1 Bugzilla #348884 unresolved"); //$NON-NLS-1$
+ }catch(Exception e){
+ fail("1.2 Cannot set macros"); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index 1a04ffe..5e7b209 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -36,6 +36,7 @@ import org.eclipse.cdt.utils.ByteUtilsTest;
import org.eclipse.cdt.utils.CdtVariableResolverTest;
import org.eclipse.cdt.utils.CommandLineUtilTest;
import org.eclipse.cdt.utils.FindProgramLocationTest;
+import org.eclipse.cdt.utils.StorableCdtVariablesTest;
import org.eclipse.cdt.utils.WeakHashSetTest;
/**
@@ -76,6 +77,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(AllLanguageTests.suite());
suite.addTest(RewriteTests.suite());
suite.addTest(CdtVariableResolverTest.suite());
+ suite.addTest(StorableCdtVariablesTest.suite());
suite.addTest(CommandLineUtilTest.suite());
suite.addTest(WeakHashSetTest.suite());
suite.addTest(FindProgramLocationTest.suite());
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java
index 956f9f2..15df511 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java
@@ -12,7 +12,9 @@ package org.eclipse.cdt.internal.core.cdtvariables;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
@@ -183,14 +185,24 @@ public class StorableCdtVariables implements IStorableCdtVariables {
deleteAll();
else{
if (getMap().size() != 0) {
+ /*
+ * Fix for Bugzilla #348884
+ */
+ Set<String> existing = new HashSet<String>();
+ Set<String> macroNames = new HashSet<String>();
+
for (ICdtVariable m : getMap().values()){
- int i;
- for(i = 0 ; i < macros.length; i++){
- if(m.getName().equals(macros[i].getName()))
- break;
+ existing.add(m.getName());
+ }
+
+ for (ICdtVariable m : macros){
+ macroNames.add(m.getName());
+ }
+
+ for (String name : existing){
+ if (!macroNames.contains(name)){
+ deleteMacro(name);
}
- if(i == macros.length)
- deleteMacro(m.getName());
}
}
createMacros(macros);