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

Pressing Shift + DOWN in ListView causes Exception to be thrown

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b117
    • Introduced In Version:
      9
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      A ListView has 3 items, of which the second is selected.
      When I press Shift + DOWN the ListChangeListener throws an Exception when accessing change.wasAdded()


      REGRESSION. Last worked in version 8u161

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the sample code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output:
      +[one]
      +[two]

      ACTUAL -
      Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: toIndex = 3
      at java.base/java.util.AbstractList.subListRangeCheck(AbstractList.java:507)
      at java.base/java.util.AbstractList.subList(AbstractList.java:497)
      at javafx.base/javafx.collections.ListChangeListener$Change.getAddedSubList(ListChangeListener.java:242)
      at Main3.lambda$start$0(Main3.java:33)
      at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
      at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
      at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
      at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
      at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
      at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
      at javafx.controls/com.sun.javafx.scene.control.SelectedItemsReadOnlyObservableList.lambda$new$1(SelectedItemsReadOnlyObservableList.java:103)
      at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
      at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
      at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
      at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
      at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
      at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
      at javafx.controls/com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList._endChange(ReadOnlyUnbackedObservableList.java:63)
      at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$SelectedIndicesList._endChange(MultipleSelectionModelBase.java:895)
      at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$SelectedIndicesList.set(MultipleSelectionModelBase.java:755)
      at javafx.controls/javafx.scene.control.MultipleSelectionModelBase.selectIndices(MultipleSelectionModelBase.java:490)
      at javafx.controls/javafx.scene.control.MultipleSelectionModel.selectRange(MultipleSelectionModel.java:180)
      at javafx.controls/com.sun.javafx.scene.control.behavior.ListViewBehavior.alsoSelectNextRow(ListViewBehavior.java:518)
      at javafx.controls/com.sun.javafx.scene.control.behavior.ListViewBehavior.lambda$new$32(ListViewBehavior.java:138)
      at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
      at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4083)
      at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1600(Scene.java:4029)
      at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2146)
      at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2620)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
      at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
      at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
      at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
      at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
      at java.base/java.lang.Thread.run(Thread.java:844)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import static javafx.scene.control.SelectionMode.MULTIPLE;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.collections.FXCollections;
      import javafx.collections.ListChangeListener;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.input.KeyCode;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;


      public class Main3 extends Application {

          final ObservableList<String> listitems = FXCollections.observableArrayList("zero", "one", "two");

          @Override
          public void start(Stage primaryStage) {
              final ListView<String> lv = new ListView<>();
              lv.setItems(listitems);

              final HBox hbox = new HBox();
              hbox.getChildren().add(lv);
              primaryStage.setScene(new Scene(hbox));

              lv.getSelectionModel().setSelectionMode(MULTIPLE);
              lv.getSelectionModel().getSelectedItems().addListener((ListChangeListener<String>) ch -> {
                  while (ch.next()) {
                      if (ch.wasAdded()) {
                          System.out.println("+" + ch.getAddedSubList());
                      }
                  }
              });

              primaryStage.show();
              Platform.runLater(() -> {
                  lv.getSelectionModel().select(1);
                  lv.fireEvent(new KeyEvent(KeyEvent.KEY_PRESSED, "", "", KeyCode.DOWN, true, false, false, false));
              }
              );
          }

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

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              arapte Ambarish Rapte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: