This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 242205 - java.util.ConcurrentModificationException at java.util.LinkedHashMap$LinkedHashIterator.nextEntry
Summary: java.util.ConcurrentModificationException at java.util.LinkedHashMap$LinkedHa...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Options&Settings (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: Theofanis Oikonomou
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-21 20:28 UTC by MackSix
Modified: 2014-07-19 10:18 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 207871


Attachments
stacktrace (1.52 KB, text/plain)
2014-02-21 20:29 UTC, MackSix
Details

Note You need to log in before you can comment on or make changes to this bug.
Description MackSix 2014-02-21 20:28:58 UTC
This bug was originally marked as duplicate of bug 227478, that is already resolved. This bug is still valid, so this seems to be another bug, but it might be related.

Build: NetBeans IDE 8.0 RC1 (Build 201402202300)
VM: Java HotSpot(TM) 64-Bit Server VM, 24.51-b03, Java(TM) SE Runtime Environment, 1.7.0_51-b13
OS: Windows 7

User Comments:
eascott: Occurred on activation of C/C++

MackSix: Activated JavaFx and then PHP.

GUEST: java.util.ConcurrentModificationException at java.util.LinkedHashMap$LinkedHashIterator.nextEntry

MackSix: Opened JSPExamples Project after Activating JavaFX, PHP, C++ and Groovy. JavaEE was not activated yet.

rburkhead: After uninstalling JDK6 and a separately installed JFXDK, and then installing JDK7 with the bundled JFXDK, ran NetBeans. Went to Tools|Options, to the Java page, and the JavaFX tab, and clicked on the "Activate" button.

tboudreau: Opening the options dialog

jiriprox: CME when opening PHP project (PHP was not enabled yet)

jiriprox: CME when activation PHP module

MackSix: Activate PHP, C/C++ and JavaFX

tdnorb: importing previous modules from NB 7.3

MackSix: Activating PHP module.

infonaut: clean install
install c /and ejb plugin
open Services
click Servers

MackSix: Delete userdir and cachedir
Activated in this order:
1. JavaFX
2. Groovy
3. C++
4. PHP

Then this happened while PHP was activating.




Stacktrace: 
java.util.ConcurrentModificationException
   at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:394)
   at java.util.LinkedHashMap$KeyIterator.next(LinkedHashMap.java:405)
   at org.netbeans.modules.options.TabbedController.initTabbedPane(TabbedController.java:190)
   at org.netbeans.modules.options.TabbedController.access$100(TabbedController.java:82)
   at org.netbeans.modules.options.TabbedController$1$1.run(TabbedController.java:97)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
Comment 1 MackSix 2014-02-21 20:29:01 UTC
Created attachment 145479 [details]
stacktrace
Comment 2 _ tboudreau 2014-02-21 23:19:40 UTC
It's pretty clear that someone has tried to fix this a few times already.  The code incorrectly uses Collections.synchronizedMap() in what I guess is an earlier attempt to fix this problem:

            Map<String, AdvancedOption> synchronizedMap = Collections.synchronizedMap(tabTitle2Option);
            Set<String> keySet = synchronizedMap.keySet();
            synchronized (synchronizedMap) {
                Iterator<String> i = keySet.iterator();
                while (i.hasNext()) {
                    String tabTitle = i.next();
                    pane.addTab(tabTitle, new JLabel(tabTitle));
                }
            }

Using synchronizedMap here can't possibly help for a number of reasons:
 - The synchronized map is just a wrapper around the real unsynchronized map, which is an instance field of the class and can be (and clearly is) modified while initTabbedPane() is iterating
 - readPanels() uses similar code - which cannot possibly work against modification from initTabbedPane() because they are using two different synchronized map instances, so they are synchronizing on different monitors
 - Synchronization is not a cure for ConcurrentModificationExceptions - you can still call something while iterating, which modifies the collection - no additional thread is required for that

So, first, just make the thing a synchronized map, period as a first step and see if the problem goes away.  If it isn't, then something is firing an event from addTab() that is causing the collection to be modified, despite removing the listener.  Add some logging to print a stack trace and find out what and fix that.
Comment 3 Theofanis Oikonomou 2014-07-14 16:20:27 UTC
Changeset: 84620f9afbd4
Author:    Theofanis Oikonomou <theofanis@netbeans.org>
Date:      2014-07-14 18:23
Message:
Comment 4 Quality Engineering 2014-07-19 10:18:46 UTC
Integrated into 'main-silver', will be available in build *201407190718* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/84620f9afbd4
User: Theofanis Oikonomou <theofanis@netbeans.org>
Log: Task #242205 - java.util.ConcurrentModificationException at java.util.LinkedHashMap$LinkedHashIterator.nextEntry