#916 NPE in StrokeChooserPanel

Walter Laan

Note that the bug category is None as it is both JFreeChart and JCommon.

The constructor of StrokeChooserPanel allows you to specify the current stroke, but if you pass null and do not select a Stroke, then getSelectedStroke() will throw a NPE.
DefaultPlotEditor creates a StrokeChooserPanel with a null current Stroke.
Additionally, even though the Stroke is null, the combobox shows a Stroke. Opening/Closing the combobox popup fixes this (shows nothing selected).

To reproduce:
-start the JFreeChart demo
-select any chart
-open popup menu -> properties
-select plot tab, then the appearance tab
-press the 'Select...' button for outline stroke
-press the OK button without pressing anything else.

Exception occurred during event dispatching:
at org.jfree.ui.StrokeChooserPanel.getSelectedStroke(StrokeChooserPanel.java:104)
at org.jfree.chart.editor.DefaultPlotEditor.attemptOutlineStrokeSelection(DefaultPlotEditor.java:501)
at org.jfree.chart.editor.DefaultPlotEditor.actionPerformed(DefaultPlotEditor.java:457)

To fix:
In DefaultPlotEditor#attemptOutlineStrokeSelection change the StrokeChooserPanel parameter from null to this.outlineStrokeSample.

In StrokeSample#paintComponent no line should be painted if this.stroke == null.

In StrokeSample#getListCellRendererComponent the stroke should be set to null if the value is not an instance of SampleStroke.

In StrokeChooserPanel#constructor optionally pass the current parameter to the SampleStroke renderer (not really needed if you do the previous fix in getListCellRendererComponent).
Optionally default to the BasicStroke when the current is null, but Plot#setOutlineStroke allows null, so adding null to the combobox as available choice is an option as well.

In StrokeChooserPanel#getSelectedStroke() add a null check for getSelectedItem().

Personally I would just add Strokes to the combobox, not SampleStrokes. You also could change the StrokeChooserPanel constructor to take a Stroke, but that would mean an API change, so better not do that.
I cannot find where the JCommon SVN is, so I could make a patch for DefaultPlotEditor only. But I've never submitted any patch so no idea if I did it right ;).


  • David Gilbert

    David Gilbert - 2009-02-27

    Thanks for the report (especially all the details which were spot on). I've committed the fixes to CVS (for JCommon, to be included in the 1.0.16 release) and SVN (for JFreeChart, to be included in the 1.0.13 release).

    Best regards,

    Dave Gilbert
    JFreeChart Project Leader

  • David Gilbert

    David Gilbert - 2009-02-27
    • assigned_to: nobody --> mungady
    • status: open --> closed-fixed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks