History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2280
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Jon Gunnip
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

ConcurrentModificationException when accessing iterator variable in nested iterator

Created: 07/Nov/07 12:26 PM   Updated: 08/Feb/08 01:26 AM
Component/s: None
Affects Version/s: 1.1-rc-2
Fix Version/s: 1.5.2

Time Tracking:
Not Specified

Environment: Windows XP, IntelliJ IDEA


 Description  « Hide
When accessing an iterator variable in a nested iterator I get a java.util.ConcurrentModificationException. If I pull up the iterator variable reference outside of the nested iterator, I get no exception. The "def serviceId = row.Service_id" is causing the exception in the code below:
package services

import groovy.sql.Sql

public class ServiceFindHTML {

    static void main(String[] args) {
        def sql = Sql.newInstance("jdbc:mysql://localhost/db", user", "pass", "com.mysql.jdbc.Driver")
        sql.rows("select * from service_provider").each {row ->
            row.each {column, value ->
                // no ConcurrentModificationException if def serviceId moved outside of this each
                def serviceId = row.Service_id
                if (value =~ /</) {
                    println "Service $serviceId contains html in column " + column + ": " + value
                }
            }
        }
    }
}

Stacktrace:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:365)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:384)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:383)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:865)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:56)
at org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:54)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:538)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:803)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:643)
at org.codehaus.groovy.runtime.Invoker.invokePogoMethod(Invoker.java:98)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:79)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:69)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
at services.ServiceFindHTML$_main_closure1.doCall(ServiceFindHTML.groovy:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:56)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:538)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:243)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:643)
at groovy.lang.Closure.call(Closure.java:291)
at groovy.lang.Closure.call(Closure.java:304)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:848)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:827)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:56)
at org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:54)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:538)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:803)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:643)
at org.codehaus.groovy.runtime.Invoker.invokePojoMethod(Invoker.java:87)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:75)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:69)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
at services.ServiceFindHTML.main(ServiceFindHTML.groovy:9)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King - 07/Jan/08 04:52 AM
fixed in r10230

Paul King - 08/Feb/08 01:26 AM
close off release 1.5.4