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

JavaFX LineChart IndexOutOfBoundsException when last data point removed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u51
    • javafx
    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X Lion 10.7.5 (11G63b)

      A DESCRIPTION OF THE PROBLEM :
      When you remove the last item in a LineChart Series Observable List, the program reports an IndexOutOfBoundsException. I did not check other chart types, but suspect other charts may also similarly fail.

      ADDITIONAL REGRESSION INFORMATION:
      Probably not a regression. Failed in previous release also.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a LineChart, add data to it, and remove the last data point in a series.

      int lastindex = series.getData().size() - 1;
      series.getData().remove(lastindex);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Chart should rerender without the last data point.
      ACTUAL -
      Exception is reported and data point is not removed.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
      removing point: (12, 25)
      at java.util.ArrayList.rangeCheck(ArrayList.java:653)
      at java.util.ArrayList.get(ArrayList.java:429)
      at javafx.scene.chart.XYChart$Series.getItem(XYChart.java:1628)
      at javafx.scene.chart.LineChart.dataItemRemoved(LineChart.java:305)
      at javafx.scene.chart.XYChart.dataItemsChanged(XYChart.java:497)
      at javafx.scene.chart.XYChart.access$2300(XYChart.java:93)
      at javafx.scene.chart.XYChart$Series$1.onChanged(XYChart.java:1457)
      at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
      at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
      at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
      at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
      at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
      at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
      at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
      at chartissue.ChartIssue.lambda$start$0(ChartIssue.java:67)
      at chartissue.ChartIssue$$Lambda$83/363005179.handle(Unknown Source)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Node.fireEvent(Node.java:8390)
      at javafx.scene.control.Button.fire(Button.java:185)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3758)
      at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$134/1816501179.get(Unknown Source)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
      at com.sun.glass.ui.View.notifyMouse(View.java:927)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package chartissue;

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.chart.LineChart;
      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 ChartIssue extends Application {

          @Override
          public void start(Stage stage) {

              stage.setTitle("Line Chart Issue - Removing Last Data Point in Series");
              //defining the axes
              final NumberAxis xAxis = new NumberAxis();
              final NumberAxis yAxis = new NumberAxis();
              xAxis.setLabel("Number of Month");
              //creating the chart
              final LineChart<Number, Number> lineChart
                      = new LineChart<>(xAxis, yAxis);

              lineChart.setTitle("Stock Monitoring, 2010");
              //defining a series
              XYChart.Series<Number, Number> series = new XYChart.Series<>();
              series.setName("My portfolio");
              //populating the series with data
              series.getData().add(new XYChart.Data(1, 23));
              series.getData().add(new XYChart.Data(2, 14));
              series.getData().add(new XYChart.Data(3, 15));
              series.getData().add(new XYChart.Data(4, 24));
              series.getData().add(new XYChart.Data(5, 34));
              series.getData().add(new XYChart.Data(6, 36));
              series.getData().add(new XYChart.Data(7, 22));
              series.getData().add(new XYChart.Data(8, 45));
              series.getData().add(new XYChart.Data(9, 43));
              series.getData().add(new XYChart.Data(10, 17));
              series.getData().add(new XYChart.Data(11, 29));
              series.getData().add(new XYChart.Data(12, 25));
              lineChart.getData().add(series);
              
              VBox vbox = new VBox();
              Button button = new Button("Remove Last Data Point");
              button.setOnAction((ActionEvent e) -> {
                  // fix: set animated to false
      // lineChart.setAnimated(false);
                  System.out.println("Chart animated property = " + lineChart.getAnimated());
                  int lastindex = series.getData().size() - 1;
                  XYChart.Data<Number, Number> datum = series.getData().get(lastindex);
                  System.out.println("removing point: ("
                          + datum.getXValue() + ", " + datum.getYValue() + ")");
                  series.getData().remove(lastindex);
              });
              vbox.setSpacing(20);
              vbox.setAlignment(Pos.CENTER);
              vbox.getChildren().addAll(lineChart, button);

              Scene scene = new Scene(vbox, 800, 600);

              stage.setScene(scene);
              stage.show();
          }

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      setAnimated(false) for the chart and the problem goes away.

            vadim Vadim Pakhnushev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: