Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2280

ConcurrentModificationException when accessing iterator variable in nested iterator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-rc-2
    • 1.5.2
    • None
    • None
    • Windows XP, IntelliJ IDEA

    Description

      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)

      Attachments

        Activity

          People

            paulk Paul King
            jongunnip Jon Gunnip
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: