Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8094186

IndexOutOfBoundsException in AreaChart

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7u6
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:

      Description

      I get an IndexOutOfBoundsException in the AreaChart, if I clear the list of items in a series and the chart is animated.

      I tested the same with LineChart and here it works.
      If I setAnimated(false), then there's also no error.

      StackTrace:

      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      at java.util.ArrayList.rangeCheck(ArrayList.java:604)
      at java.util.ArrayList.get(ArrayList.java:382)
      at com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:208)
      at javafx.scene.chart.AreaChart.dataItemRemoved(AreaChart.java:215)
      at javafx.scene.chart.XYChart.dataItemsChanged(XYChart.java:470)
      at javafx.scene.chart.XYChart.access$2500(XYChart.java:72)
      at javafx.scene.chart.XYChart$Series$1.onChanged(XYChart.java:1462)
      at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:134)
      at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
      at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
      at com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:184)
      at com.cgm.sam.link.communicator.TestApp3$1.handle(TestApp3.java:51)


      Sample Code:

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.chart.AreaChart;
      import javafx.scene.chart.NumberAxis;
      import javafx.scene.chart.XYChart;
      import javafx.scene.control.Button;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TestApp3 extends Application {


          @Override
          public void start(Stage stage) throws Exception {

              NumberAxis yAxis = new NumberAxis();
              NumberAxis xAxis = new NumberAxis();

              AreaChart<Number, Number> lineChart = new AreaChart<Number, Number>(xAxis, yAxis);

              final XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
              series.setData(list);

              lineChart.getData().add(series);

              //lineChart.setAnimated(false);

              Button button = new Button("Click me");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      list.clear(); // here the exception is thrown.
                      list.add(new XYChart.Data<Number, Number>(4, 1));
                      list.add(new XYChart.Data<Number, Number>(5, 2));
                  }
              });

              VBox vBox = new VBox();
              vBox.getChildren().addAll(lineChart, button);

              Scene scene = new Scene(vBox);
              stage.setScene(scene);
              stage.show();
          }

          private ObservableList<XYChart.Data<Number, Number>> list = FXCollections.observableArrayList(new XYChart.Data<Number, Number>(2, 0), new XYChart.Data<Number, Number>(4, 1), new XYChart.Data<Number, Number>(7, 3));

          public static void main(String[] args) {
              launch(args);
          }
      }

        Attachments

          Activity

            People

            Assignee:
            msladecek Martin Sládeček
            Reporter:
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: