ConcurrentModificationException

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Guest

ConcurrentModificationException

Post by Guest » Tue Jun 14, 2005 8:07 pm

Sorry if this is a known issue but shouldn't the use of

new java.util.ArrayList() in a number of places be

List list = Collections.synchronizedList(new ArrayList(...));

in accordance with http://java.sun.com/j2se/1.4.2/docs/api/index.html in order to be thread-safe (for the publically accessible data. also need to synchronized(data) too.)

I get a number of exceptions at runtime especially with respect to the rendering of the CategoryPlot.


Thanks for listening. And keep up the good work. :)

mhilpert
Posts: 497
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

Post by mhilpert » Wed Jun 15, 2005 12:21 pm

Me too. But interestingly they only appear if I display a chart on a gui. I f I just create a chart and save it, it didn't happen so far.
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jun 15, 2005 3:38 pm

Please post the exceptions and any pointers on how to reproduce the problem.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Guest

Post by Guest » Wed Jun 15, 2005 6:12 pm

This is one exception I got (running 0.9.21)

[java] java.util.ConcurrentModificationException
[java] at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:448)
[java] at java.util.AbstractList$Itr.next(AbstractList.java:419)
[java] at java.util.Collections$1.next(Collections.java:996)
[java] at java.util.Collections$1.next(Collections.java:996)
[java] at org.jfree.chart.axis.CategoryAxis.refreshTicks(CategoryAxis.java:788)
[java] at org.jfree.chart.axis.CategoryAxis.drawCategoryLabels(CategoryAxis.java:653)
[java] at org.jfree.chart.axis.CategoryAxis.draw(CategoryAxis.java:617)
[java] at org.jfree.chart.plot.CategoryPlot.drawAxes(CategoryPlot.java:1996)
[java] at org.jfree.chart.plot.CategoryPlot.draw(CategoryPlot.java:1869)
[java] at org.jfree.chart.plot.Plot.draw(Plot.java:725)
[java] at org.jfree.chart.JFreeChart.draw(JFreeChart.java:904)
[java] at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:999)
[java] at javax.swing.JComponent.paint(JComponent.java:808)
[java] at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
[java] at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
[java] at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
[java] at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
[java] at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
[java] at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
[java] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
[java] at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
[java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
[java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


On 1.0.rc1, I got a different exception:
[java] Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
[java] at org.jfree.chart.renderer.xy.StackedXYAreaRenderer.drawItem(StackedXYAreaRenderer.java:488)
[java] at org.jfree.chart.plot.XYPlot.render(XYPlot.java:2590)
[java] at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:2168)
[java] at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1058)
[java] at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1271)
[java] at javax.swing.JComponent.paint(JComponent.java:1003)
[java] at javax.swing.JComponent.paintChildren(JComponent.java:840)
[java] at javax.swing.JComponent.paint(JComponent.java:1012)
[java] at javax.swing.JComponent.paintChildren(JComponent.java:840)
[java] at javax.swing.JComponent.paint(JComponent.java:1012)
[java] at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4930)
[java] at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4883)
[java] at javax.swing.JComponent._paintImmediately(JComponent.java:4826)
[java] at javax.swing.JComponent.paintImmediately(JComponent.java:4633)
[java] at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)
[java] at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
[java] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
[java] at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
[java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
[java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jun 15, 2005 6:47 pm

The second one is a bug that is fixed in CVS. Do you have any hints on how to reproduce the first? What does your code do leading up to the exception?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Guest

Post by Guest » Wed Jun 15, 2005 11:35 pm

Here's more info.

I noticed that it occurs more often running on Redhat Linux than Windows.
Maybe it's the JVM?

The JVM on Linux is:
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

The JVM on Windows 2000 Professional is:
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)


Anyway, most of the time it's running correctly and my codes don't automatically trigger the exception. From the exception, it looks like that it's triggered by Swing's main rendering thread.

My codes is basically having a ChartPanel inside a Swing panel. Data series continuously streaming in and I just add them one at a time to the dataset (DefaultCategoryDataset).

BTW, It works fine for all the other data types (PieDataset, DefaultTableXYDataset, XYSeriesCollection)... just not CategoryDataset...

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Wed Jun 15, 2005 11:41 pm

My codes is basically having a ChartPanel inside a Swing panel. Data series continuously streaming in and I just add them one at a time to the dataset (DefaultCategoryDataset).
Swing is not thread safe. Are you adding the new data points from the correct thread?

Guest

Post by Guest » Thu Jun 16, 2005 4:48 pm

I guess I don't understand what you meant by "correct thread". Do you mean to say that there are certain restrictions on which thread can add a data series to a dataset?

Could you clarify what you meant. Which threads are the wrong threads to add data and which particular thread is "the correct thread" to add data?

In my codes, there's a separate daemon thread (aside from the ui thread) running in the background that add another data series as they come in... So, are you saying that this thread shouldn't be adding data to the dataset?

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Thu Jun 16, 2005 5:49 pm

Hi,

for all Swing applications it can be said, that operations that might cause updates to GUI components must be executed on the Event-Dispatcher thread. To post update code on that thread, you could wrap your code into a java.lang.Runnable object and use SwingUtilities.invokeAndWait(..) (suspends the caller thread until the runnable has been completly executed) or SwingUtilities.invokeLater(..) (Asynchronous call, order of the calls is guaranteed).

Have mo' fun,
said Thomas

Guest

Post by Guest » Thu Jun 16, 2005 6:45 pm

Ah, ok. thanks.

I did that in other parts of the codes but I never thought I have to do that with respect to JFreeChart. I always thought that it will handle everything for me. :)

I guess I will have to wrap it a bit.
I'll give it a try and see if the exception go away.

Thanks everyone...

tduraipkt
Posts: 6
Joined: Mon Jun 26, 2006 6:17 am

cewolf - Exception

Post by tduraipkt » Wed Aug 16, 2006 6:28 am

java.lang.NullPointerException
at org.jfree.chart.axis.CategoryAxis.createLabel(CategoryAxis.java:821)
at org.jfree.chart.axis.CategoryAxis.refreshTicks(CategoryAxis.java:789)
at org.jfree.chart.axis.CategoryAxis.reserveSpace(CategoryAxis.java:542)
at org.jfree.chart.plot.CategoryPlot.calculateDomainAxisSpace(CategoryPlot.java:1746)
at org.jfree.chart.plot.CategoryPlot.calculateAxisSpace(CategoryPlot.java:1809)
at org.jfree.chart.plot.CategoryPlot.draw(CategoryPlot.java:1853)
at org.jfree.chart.plot.Plot.draw(Plot.java:725)
at org.jfree.chart.JFreeChart.draw(JFreeChart.java:904)
at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1037)
at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1020)
at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:156)
at de.laures.cewolf.util.Renderer.handlePNG(Renderer.java:137)
at de.laures.cewolf.util.Renderer.renderChart(Renderer.java:105)
at de.laures.cewolf.util.Renderer.render(Renderer.java:85)
at de.laures.cewolf.taglib.ChartImageDefinition.ensureRendered(ChartImageDefinition.java:139)
at de.laures.cewolf.taglib.ChartImageDefinition.getBytes(ChartImageDefinition.java:133)
at de.laures.cewolf.storage.SerializableChartImage.(SerializableChartImage.java:49)
at de.laures.cewolf.storage.FileStorage.storeChartImage(FileStorage.java:86)
at de.laures.cewolf.taglib.tags.ChartImgTag.doStartTag(ChartImgTag.java:79)


Hai ,
this is the exception i got when using cewolf........
Give me the solution..........

regards,
Durai.....

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Wed Aug 16, 2006 6:47 am

Hai ,
this is the exception i got when using cewolf........
Give me the solution..........
Hello,

It is going to be a little bit difficult to give you the solution without first understanding what the problem is. I may be able to help 'guide' you to the correct resolution though...

What versions of JFreeChart and cewolf are you using?

If you are using the latest 1.0.1 JFreeChart then the offending line of code is:

Code: Select all

x0 = getCategoryStart(categoryIndex, ticks.size(), 
     dataArea, edge);
I would recommend that you have a look at the 'ticks' object and whether there is a way to set this in cewolf so that it is not null.

Locked