0

I am currently using JFreeChat in order to draw some charts with Java. The actual drawing is part of a quite big project, which does not allow me to easily include more code. To me it seems like the Exception is thrown directly
from a JFreeChart component. I would really appreciate if someone could help out. Is there a way to track down in more detail where exactly the exception was thrown? I read that the exception is generally thrown in cases like the iteration of lists, while removing elements from the same list at the same time (which is not what i am doing right now).

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
    at java.util.ArrayList$Itr.next(ArrayList.java:851)
    at org.jfree.chart.plot.XYPlot.drawAnnotations(XYPlot.java:3972)
    at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:3339)
    at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1229)
    at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1624)
    at javax.swing.JComponent.paint(JComponent.java:1056)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:306)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
    at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Best regards.

Tauling
  • 168
  • 11

3 Answers3

2

The source for drawAnnotations() in version 1.0.19 at line 3972 is seen here; it is unremarkable and normally functions correctly. A problem can arise if you inadvertently make your top-level container visible or update a plot's dataset on the initial thread. The resulting update event will execute on the event dispatch thread, possibly giving rise to a race condition. Swing requires that you construct and manipulate Swing GUI objects only on the event dispatch thread. If the errant code is not apparent, try the approach shown here to detect latent violations.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

I would say you have another thread who is modifying the annotation list. If you can reproduce this in your IDE put a breakpoint when this exception is thrown (suspend all thread in the vm) and inspect other threads when the exception occur.

see Eclipse Conditional-Breakpoint. How to check if exception occurs?

mestachs
  • 1,889
  • 15
  • 17
  • Yes, it looks like the collection used as a data source is being modified by another thread while the chart is iterating through it. – Javier C Sep 13 '17 at 20:23
  • I am using JFreeChart in version 1.0.19 and i wasn't able to identify a collection which changes while iterating it. – Tauling Sep 13 '17 at 21:05
1

Please see this question:

How to avoid "ConcurrentModificationException" while removing elements from `ArrayList` while iterating it?

The issue here is similar; that ArrayList in the stack trace is being concurrently operated upon. The above question is concerned with removing elements, but any concurrent operation by multiple threads will cause this. ArrayList is not thread safe.

Another question worth looking at: How do I make my ArrayList Thread-Safe? Another approach to problem in Java?

If this is not your ArrayList, it may be a bug in whatever code you are calling.

D. Wood
  • 56
  • 4