java.util.ConcurrentModificationException

Pentaho BI Platform Tracking | Giovanni Botta | 3 years ago
  1. 0

    In the constructor of the Log4jBufferAppender class, the buffer is initialized as a synchronized list: {code} buffer = Collections.synchronizedList(new LinkedList<BufferLine>()); {code} The class exposes the following method: {code} public Iterator<BufferLine> getBufferIterator() { return buffer.iterator(); } {code} This method is not thread safe. In fact, the Collections.synchronizedList() doesn't make the iterator thread safe. This is clearly documented in the javadoc: It is imperative that the user manually synchronize on the returned list when iterating over it: {code} List list = Collections.synchronizedList(new ArrayList()); ... synchronized (list) { Iterator i = list.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } {code} Then in the class CentralLogStore.replaceLogCleaner(), the list is traversed unsafely: {code} Iterator<BufferLine> i = appender.getBufferIterator(); while (i.hasNext()) { BufferLine bufferLine = i.next(); if (bufferLine.getEvent().timeStamp < minTimeBoundary) { i.remove(); } else { break; } } {code} And I've seen the following exception being randomly thrown in my jobs: Exception in thread "Timer-1" java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:953) at java.util.LinkedList$ListItr.next(LinkedList.java:886) at org.pentaho.di.core.logging.CentralLogStore$1.run(CentralLogStore.java:70) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505) There is no concurrent list implementation in java, but maybe a linked queue could be used if the list can be replaced with a queue (I haven't looked fully at the code to figure out what the best data structure would be). Hope that helps!

    Pentaho BI Platform Tracking | 3 years ago | Giovanni Botta
    java.util.ConcurrentModificationException
  2. 0

    In the constructor of the Log4jBufferAppender class, the buffer is initialized as a synchronized list: {code} buffer = Collections.synchronizedList(new LinkedList<BufferLine>()); {code} The class exposes the following method: {code} public Iterator<BufferLine> getBufferIterator() { return buffer.iterator(); } {code} This method is not thread safe. In fact, the Collections.synchronizedList() doesn't make the iterator thread safe. This is clearly documented in the javadoc: It is imperative that the user manually synchronize on the returned list when iterating over it: {code} List list = Collections.synchronizedList(new ArrayList()); ... synchronized (list) { Iterator i = list.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } {code} Then in the class CentralLogStore.replaceLogCleaner(), the list is traversed unsafely: {code} Iterator<BufferLine> i = appender.getBufferIterator(); while (i.hasNext()) { BufferLine bufferLine = i.next(); if (bufferLine.getEvent().timeStamp < minTimeBoundary) { i.remove(); } else { break; } } {code} And I've seen the following exception being randomly thrown in my jobs: Exception in thread "Timer-1" java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:953) at java.util.LinkedList$ListItr.next(LinkedList.java:886) at org.pentaho.di.core.logging.CentralLogStore$1.run(CentralLogStore.java:70) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505) There is no concurrent list implementation in java, but maybe a linked queue could be used if the list can be replaced with a queue (I haven't looked fully at the code to figure out what the best data structure would be). Hope that helps!

    Pentaho BI Platform Tracking | 3 years ago | Giovanni Botta
    java.util.ConcurrentModificationException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

    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.LinkedList$ListItr.checkForComodification()
    2. Java RT
      LinkedList$ListItr.next
      1. java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:953)
      2. java.util.LinkedList$ListItr.next(LinkedList.java:886)
      2 frames
    3. org.pentaho.di
      CentralLogStore$1.run
      1. org.pentaho.di.core.logging.CentralLogStore$1.run(CentralLogStore.java:70)
      1 frame
    4. Java RT
      TimerThread.run
      1. java.util.TimerThread.mainLoop(Timer.java:555)
      2. java.util.TimerThread.run(Timer.java:505)
      2 frames