Bug #1334 ConcurrentModificationException throw when attempting to close connection.
Submitted: 18 Sep 2003 9:13 Modified: 18 Sep 2003 9:26
Reporter: M Smith Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.0-alpha OS:Windows (Win 2000)
Assigned to: CPU Architecture:Any

[18 Sep 2003 9:13] M Smith
Description:
A ConcurrentModificationException is thrown on some attempts to close the db connection.  The program that generates the error runs without error with connectorj 3.0.8.  The error occurs in 3.1.0-alpha after an xml file is parsed and written to the db.  The parsing code loads the xml values into a hash map.  If code that processes the xml file is not executed the use of hash maps is also skipped and the error does not occur.  This suggests that the problem relates to how 3.1.0-alpha is using hash maps.

Stack trace...

java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:782)
	at java.util.HashMap$KeyIterator.next(HashMap.java:818)
	at com.mysql.jdbc.Connection.closeAllOpenStatements(Connection.java:2538)
	at com.mysql.jdbc.Connection.close(Connection.java:1067)
	at net.amys.datadictionary.SchemaPersistor.close(SchemaPersistor.java:140)
	at net.amys.datadictionary.SchemaPersistor.<init>(SchemaPersistor.java:60)
	at net.amys.dw.util.CreateTables.<init>(CreateTables.java:29)
	at net.amys.dw.util.CreateTables.main(CreateTables.java:34)
Exception in thread "main" 

Code that generates the exception in class java.util.HashMap

        Entry nextEntry() { 
----->>     if (modCount != expectedModCount)
                throw new ConcurrentModificationException();
            Entry e = next;
            if (e == null) 
                throw new NoSuchElementException();
                
            Entry n = e.next;
            Entry[] t = table;
            int i = index;
            while (n == null && i > 0)
                n = t[--i];
            index = i;
            next = n;
            return current = e;
        } 

How to repeat:
Sorry, but I can't be of much help here.
[18 Sep 2003 9:26] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

This is already fixed in Connector/J 3.1.1 (which hasn't been released yet). See http://mmmysql.sourceforge.net/snapshots/dev/ for a nightly build of the 3.1.x tree with the fix applied (some weeks now).
[4 Feb 2005 15:14] Rajesh Radhakrishnan
Do we have a fix for this with a production release of Connector/J. I first got this issue at closing connection with 3.1.0-alpha. I tried different versions as suggested by many, but still getting ConcurrentModificationException.
[4 Feb 2005 16:38] Mark Matthews
Rajesh, this was fixed way back in 3.1.1 (3.1.6 is the current release).