Bug in DefaultXYDataSource

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

Bug in DefaultXYDataSource

Post by Andrzej Porebski » Wed Oct 11, 2000 4:58 pm

The constructor of DefaultXYDataSource incorrectly assumes that all series will have the same extact count of items in them and that causes ArrayOutOfBounds exception in such cases.


public DefaultXYDataSource(List seriesNames, Object[][][] data) {

this.seriesNames = seriesNames;

int seriesCount = data.length;
int maxItemCount = data[0].length;

^^^^
This assignment of data[0].length is at fault.

The fix is here: Since maxItemCount is only used in the loop following, instead of preassigning a value to it before the loop, do the assignment in the loop:

Here is the relevant part of the code:

public DefaultXYDataSource(List seriesNames, Object[][][] data) {

this.seriesNames = seriesNames;

int seriesCount = data.length;

allSeriesData = new ArrayList(seriesCount);

for (int seriesIndex=0; seriesIndex<seriesCount; seriesIndex++)
{
List oneSeriesData = new ArrayList();
int maxItemCount = data[seriesIndex].length;
for (int itemIndex=0; itemIndex<maxItemCount; itemIndex++)

David Gilbert

RE: Bug in DefaultXYDataSource

Post by David Gilbert » Mon Oct 23, 2000 6:24 pm

Andrzej,

Thanks for finding and fixing this bug. The correction has been made and will be in the next release.

Regards,

DG.

Locked