#126 TaskSeriesCollection index out of bounds

open
nobody
General (896)
5
2012-11-27
2003-03-04
No

From the JFreeChart forum:

I encountered a problem using
TaskSeriesCollection.java. Here is the simplest way I
found to reproduce it:

In DemoDatasetFactory.java, at the end of
createGanttDataset2 right before the "return collection;"
statement , add the 2 lines:
s1.getTasks().clear();
s1.fireSeriesChanged();

After recompiling, if you launch GanttDemo2, you get:

Exception in thread "main"
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at com.jrefinery.data.TaskSeries.get(Unknown
Source)
at
com.jrefinery.data.TaskSeriesCollection.getStartValue(Unknown
Source)
at
com.jrefinery.data.DatasetUtilities.getRangeExtent(Unknown
Source)
at
com.jrefinery.chart.plot.HorizontalCategoryPlot.getHorizontalDataRange(Unk
at
com.jrefinery.chart.axis.HorizontalDateAxis.autoAdjustRange(Unknown
Source
at
com.jrefinery.chart.axis.HorizontalDateAxis.configure(Unknown
Source)
at com.jrefinery.chart.axis.Axis.setPlot(Unknown
Source)
at
com.jrefinery.chart.plot.CategoryPlot.<init>(Unknown
Source)
at
com.jrefinery.chart.plot.HorizontalCategoryPlot.<init>(Unknown
Source)
at
com.jrefinery.chart.ChartFactory.createGanttChart(Unknown
Source)
at
com.waidan.analysis.GanttDemo2.<init>(GanttDemo2.java:68)
at
com.waidan.analysis.GanttDemo2.main(GanttDemo2.java:91)

I tried to investigate a bit: I modified code in
TaskSeriesCollection.java the following way (several
methods should be changed too...)
public Number getStartValue (int row, int column) {
Number result = new Integer(0); // SECOND
POTENTIAL BUG HERE?
TaskSeries series = (TaskSeries) this.data.get(row);
int tasks = series.getItemCount();
if (column < tasks) { // FIRST POTENTIAL BUG
HERE?
com.jrefinery.data.Task task = series.get(column);
result = new
Long(task.getDuration().getStart().getTime());
}
return result;
}

But, I then got a BadPath exception... and I'm lost!

Discussion

  • David Gilbert

    David Gilbert - 2003-03-04

    Logged In: YES
    user_id=112975

    The bug is in the TaskSeriesCollection class which keeps its
    own list of keys. When you modify the TaskSeries, the
    TaskSeriesCollection is not synchronising its key list, so it
    thinks there are more tasks than there really are...which
    causes the array index bounds exception. I'll have to think
    about the best way to fix this...

    Regards,

    Dave Gilbert

     
  • Claudia Plesa

    Claudia Plesa - 2003-04-08

    Logged In: YES
    user_id=615955

    Any chance of getting this bug resolved in the near future?
    I'd like to use the Gantt Chart to display multiple time
    series and I'm running into this bug.

    Thanks for your help.

    Alex

     
  • David Basten

    David Basten - 2003-07-01

    Logged In: YES
    user_id=511814

    Another situation where this can occur:

    If more than 1 series is used and the series don't have the
    same categories. Using the metaphor in the gantt demos, if
    the "actual" series had 1 (or more) tasks (e.g "post
    implementation celebration") that the "scheduled" series did
    not have, this error can occur.

    The TaskSeriesCollection counts the number of unique
    columns (tasks) across ALL series, not per series. In
    getStartValue( int row, int column) it tries to lookup the
    minimum date value. It checks to see if column <= tasks.
    The list containing the tasks is 0-based, so fails with the
    index out of bounds when they are equal.

    This happens in all other similar methods in
    TaskSeriesCollection. The obvious solution is to remove the
    equals sign in the condition check. This moved the error past
    this point and into the actual rendering. The renderer
    expects the column to exist for every series. When it doesn't
    the getStartValue (back in the TaskSeriesCollection) returns
    null and a NullPointerException is generated.

    I haven't pursued the resolution beyond this, due to lack of
    time. I have not read that the Gantt chart implementation
    requires the same number of categories per series.

     
  • David Basten

    David Basten - 2003-10-17

    Logged In: YES
    user_id=511814

    The latest update to TaskSeriesCollection has fixes that I had
    been looking at for TaskSeriesCollection based on this bug.
    The fix notes suggest that it was resolved for bug 800324.
    Not sure if the cause of the bug from the original post is
    solved, but it does solve the situation I described.

     

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

Sign up for the SourceForge newsletter:





No, thanks