java.util.ConcurrentModificationException

Spring JIRA | christophe blin | 2 years ago
  1. 0

    I have a hundred jobs in my application and I test them with the SimpleJobExplorer Sometimes (i.e 1% of test runs I would say), I have a strange exception occuring when I call getJobExecution and the job is executing. I've investigated the code and I think that the problem occurs because despite using a ConcurrentHashMap, the values inside the map are not concurrent aware. The solution I think is to copy the object before putting in the map so that the steps jobexecution is not the same instance as the jobexecution in the jobexlorer map (i.e like with the database where the job exec is fetch from the db so this is a copy). I understand if this bug is not fixed since SImpleJobExplorer is not for production but this is quite an annoyance to me nevertheless ... Here is the stacktrace : java.util.ConcurrentModificationException at java.util.ArrayList.writeObject(ArrayList.java:746) at sun.reflect.GeneratedMethodAccessor181.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at java.util.concurrent.ConcurrentHashMap.writeObject(ConcurrentHashMap.java:1520) at sun.reflect.GeneratedMethodAccessor179.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at org.springframework.batch.support.SerializationUtils.serialize(SerializationUtils.java:48) at org.springframework.batch.core.repository.dao.MapStepExecutionDao.copy(MapStepExecutionDao.java:52) at org.springframework.batch.core.repository.dao.MapStepExecutionDao.addStepExecutions(MapStepExecutionDao.java:130) at org.springframework.batch.core.explore.support.SimpleJobExplorer.getJobExecutionDependencies(SimpleJobExplorer.java:182) at org.springframework.batch.core.explore.support.SimpleJobExplorer.getJobExecution(SimpleJobExplorer.java:120) at my_own_program at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59) at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98) at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79) at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87) at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77) at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42) at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Spring JIRA | 2 years ago | christophe blin
    java.util.ConcurrentModificationException
  2. 0

    I have a hundred jobs in my application and I test them with the SimpleJobExplorer Sometimes (i.e 1% of test runs I would say), I have a strange exception occuring when I call getJobExecution and the job is executing. I've investigated the code and I think that the problem occurs because despite using a ConcurrentHashMap, the values inside the map are not concurrent aware. The solution I think is to copy the object before putting in the map so that the steps jobexecution is not the same instance as the jobexecution in the jobexlorer map (i.e like with the database where the job exec is fetch from the db so this is a copy). I understand if this bug is not fixed since SImpleJobExplorer is not for production but this is quite an annoyance to me nevertheless ... Here is the stacktrace : java.util.ConcurrentModificationException at java.util.ArrayList.writeObject(ArrayList.java:746) at sun.reflect.GeneratedMethodAccessor181.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at java.util.concurrent.ConcurrentHashMap.writeObject(ConcurrentHashMap.java:1520) at sun.reflect.GeneratedMethodAccessor179.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at org.springframework.batch.support.SerializationUtils.serialize(SerializationUtils.java:48) at org.springframework.batch.core.repository.dao.MapStepExecutionDao.copy(MapStepExecutionDao.java:52) at org.springframework.batch.core.repository.dao.MapStepExecutionDao.addStepExecutions(MapStepExecutionDao.java:130) at org.springframework.batch.core.explore.support.SimpleJobExplorer.getJobExecutionDependencies(SimpleJobExplorer.java:182) at org.springframework.batch.core.explore.support.SimpleJobExplorer.getJobExecution(SimpleJobExplorer.java:120) at my_own_program at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59) at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98) at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79) at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87) at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77) at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42) at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Spring JIRA | 2 years ago | christophe blin
    java.util.ConcurrentModificationException
  3. 0

    Concurrent modification when persisting workflows

    GitHub | 4 years ago | aschoneveld
    java.util.ConcurrentModificationException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Accessing variable concurrently from two different threads in java

    Stack Overflow | 2 years ago | Nichos
    java.util.ConcurrentModificationException
  6. 0

    ConcurrentModificationException with writeObject

    Stack Overflow | 5 years ago | Baduel
    java.util.ConcurrentModificationException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.util.ConcurrentModificationException

      No message provided

      at java.util.ArrayList.writeObject()
    2. Java RT
      ObjectOutputStream.writeObject
      1. java.util.ArrayList.writeObject(ArrayList.java:746)
      2. sun.reflect.GeneratedMethodAccessor181.invoke(Unknown Source)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:606)
      5. java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988)
      6. java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495)
      7. java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      8. java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      9. java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
      10. java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
      11. java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      12. java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      13. java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
      14. java.util.concurrent.ConcurrentHashMap.writeObject(ConcurrentHashMap.java:1520)
      15. sun.reflect.GeneratedMethodAccessor179.invoke(Unknown Source)
      16. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      17. java.lang.reflect.Method.invoke(Method.java:606)
      18. java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988)
      19. java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495)
      20. java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      21. java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      22. java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
      23. java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
      24. java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      25. java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      26. java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
      27. java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
      28. java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      29. java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      30. java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
      31. java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
      32. java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      33. java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      34. java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
      34 frames
    3. Spring Batch Infrastructure
      SerializationUtils.serialize
      1. org.springframework.batch.support.SerializationUtils.serialize(SerializationUtils.java:48)
      1 frame
    4. Spring Batch Core
      SimpleJobExplorer.getJobExecution
      1. org.springframework.batch.core.repository.dao.MapStepExecutionDao.copy(MapStepExecutionDao.java:52)
      2. org.springframework.batch.core.repository.dao.MapStepExecutionDao.addStepExecutions(MapStepExecutionDao.java:130)
      3. org.springframework.batch.core.explore.support.SimpleJobExplorer.getJobExecutionDependencies(SimpleJobExplorer.java:182)
      4. org.springframework.batch.core.explore.support.SimpleJobExplorer.getJobExecution(SimpleJobExplorer.java:120)
      4 frames