Menu

#983 Potential NPE in AbstractCategoryItemRender.getLegendItems()

closed-fixed
General (896)
5
2010-02-09
2010-02-08
No

Setting up a working copy of the current JFreeChart trunk in Eclipse I got a warning about a null pointer access in this bit of code from AbstractCategoryItemRender.java:

public LegendItemCollection getLegendItems() {
LegendItemCollection result = new LegendItemCollection();
if (this.plot == null) {
return result;
}
int index = this.plot.getIndexOf(this);
CategoryDataset dataset = this.plot.getDataset(index);
if (dataset != null) {
return result;
}
int seriesCount = dataset.getRowCount();
...
}

The warning is in the last code line where seriesCount is assigned. The variable dataset is guaranteed to be null in this location, I suppose that the check before that should actually read "if (dataset == null)", not "if (dataset != null)".

This is trunk as of 2010-02-08.

Discussion

  • David Gilbert

    David Gilbert - 2010-02-09

    Good spot. That was the result of a careless commit by me. I've committed the fix.

     
  • David Gilbert

    David Gilbert - 2010-02-09
    • labels: --> General
    • assigned_to: nobody --> mungady
    • status: open --> closed-fixed
     

Log in to post a comment.