Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 348884

Summary: ConcurrentModificationException in StorableCdtVariables
Product: [Tools] CDT Reporter: Sluvy Mising name <SlavyTest>
Component: cdt-coreAssignee: Andrew Gvozdev <angvoz.dev>
Status: RESOLVED FIXED QA Contact: Andrew Gvozdev <angvoz.dev>
Severity: normal    
Priority: P3 CC: marc.khouzam, veaceslav.bacu, yevshif
Version: 8.0Flags: angvoz.dev: review+
Target Milestone: 8.2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Fix for 348884 including unit test
none
Fix for 348884 including unit test veaceslav.bacu: review?

Description Sluvy Mising name CLA 2011-06-09 08:57:39 EDT
Build Identifier: 20100917-0705

Trivial exception encountered trying to remove 2(or more, but not all) variables and then clicking the Apply button

MESSAGE Internal error 
!STACK 0 
java.util.ConcurrentModificationException 
at java.util.HashMap$HashIterator.nextEntry(Unknown Source) 
at java.util.HashMap$ValueIterator.next(Unknown Source) 
at org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables.setMacros(StorableCdtVariables.java:185) 
at org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier.setMacros(UserDefinedVariableSupplier.java:267) 
at org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier.setMacros(UserVarSupplier.java:82) 
at org.eclipse.cdt.managedbuilder.ui.properties.CPropertyVarsTab.performApply(CPropertyVarsTab.java:654) 
at org.eclipse.cdt.ui.newui.AbstractCPropertyTab.handleTabEvent(AbstractCPropertyTab.java:521) 
at org.eclipse.cdt.ui.newui.AbstractPage.forEach(AbstractPage.java:1018) 
at org.eclipse.cdt.ui.newui.AbstractPage$5.run(AbstractPage.java:646) 
at org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation.execute(WorkspaceModifyDelegatingOperation.java:69) 
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106) 
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975) 
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118) 
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464) 
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372) 
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)

Reproducible: Always

Steps to Reproduce:
1. Make sure you have a C or C++ project
2. Open project properties
3. Go to C/C++ Build -> Build Variables -> and add 3 or more variables
4. Click Apply
5. Delete 2 or more variables, but make sure you don't delete all of them
6. Click Apply
7. Notice Internal Error: 
java.util.ConcurrentModificationException
8. Check the log file:
MESSAGE Internal error 
!STACK 0 
java.util.ConcurrentModificationException 
at java.util.HashMap$HashIterator.nextEntry(Unknown Source) 
at java.util.HashMap$ValueIterator.next(Unknown Source) 
at org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables.setMacros(StorableCdtVariables.java:185) 
at org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier.setMacros(UserDefinedVariableSupplier.java:267) 
at org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier.setMacros(UserVarSupplier.java:82) 
at org.eclipse.cdt.managedbuilder.ui.properties.CPropertyVarsTab.performApply(CPropertyVarsTab.java:654) 
at org.eclipse.cdt.ui.newui.AbstractCPropertyTab.handleTabEvent(AbstractCPropertyTab.java:521) 
at org.eclipse.cdt.ui.newui.AbstractPage.forEach(AbstractPage.java:1018) 
at org.eclipse.cdt.ui.newui.AbstractPage$5.run(AbstractPage.java:646) 
at org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation.execute(WorkspaceModifyDelegatingOperation.java:69) 
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106) 
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975) 
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118) 
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464) 
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372) 
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)

9. Check StorableCdtVariables.setMacros
for (ICdtVariable m : getMap().values()){
					int i;
					for(i = 0 ; i < macros.length; i++){
						if(m.getName().equals(macros[i].getName()))
							break;
					}
					if(i == macros.length)
						deleteMacro(m.getName());
				}
Notice the trivial oversight: iterating over a collection which gets modified
Comment 1 Andrew Gvozdev CLA 2011-06-09 09:33:52 EDT
Can you submit a patch fixing the issue? See http://wiki.eclipse.org/CDT/User/FAQ#How_do_I_submit_a_fix_for_a_bug.3F
Comment 2 Veaceslav Bacu CLA 2012-06-12 15:00:53 EDT
Created attachment 217229 [details]
Fix for 348884 including unit test

Fix for 348884 - Linear implementation for the fix.

Added unit test as well.
Comment 3 Veaceslav Bacu CLA 2012-06-17 09:10:13 EDT
Created attachment 217462 [details]
Fix for 348884 including unit test

Attached a fix and a unit test for this bug
Comment 4 Andrew Gvozdev CLA 2012-06-19 17:06:30 EDT
(In reply to comment #3)
> Created attachment 217462 [details]
> Fix for 348884 including unit test
> Attached a fix and a unit test for this bug
Committed to master with minor addition. Thanks for the patch.
Comment 5 CDT Genie CLA 2013-02-27 11:44:21 EST
*** cdt git genie on behalf of Andrew Gvozdev ***

    bug 348884: ConcurrentModificationException in StorableCdtVariables

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=aa4abe428dee9287bacdcd16abad56ddf140e627
Comment 6 CDT Genie CLA 2013-02-27 11:44:25 EST
*** cdt git genie on behalf of Veaceslav Bacu ***

    bug 348884: ConcurrentModificationException in StorableCdtVariables

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=582b358f0fda6d028ee50f92774c1db7cfa33897
Comment 7 CDT Genie CLA 2013-02-27 11:44:43 EST
*** cdt git genie on behalf of Andrew Gvozdev ***

    bug 348884: Fixed unit test

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=c7438e07089a969d8ddb6f69431369d43b5ad4a7