java.lang.IndexOutOfBoundsException

tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    FULL PRODUCT VERSION : 1.8.0_102 ADDITIONAL OS VERSION INFORMATION : Windows10 (64bit) A DESCRIPTION OF THE PROBLEM : In some cases, MultipleSelectionModelBase produces improper ListChangeListener.Change which have illegal from/to index. So, if getAddedSubList is invoked on such Change, it causes IndexOutOfBoundsException. It seems to me that implementation of MultiSelectionModelBase.selectedIndicesSeq field is the cause of this problem. This field is generated by createListFromBitSet, and provides the ObservableList view of BitMap field 'selectedIndices'. I think the cause of this problem is the internal state (lastGetIndex/lastGetValue) of this instance is not properly maintained when content of 'selectedIndices' is changed. For example, in my code for reproduction, the value of selectedIndices and lastGetIndex/lastGetValue changed as follows: A) Ater selection "a" and "b" selectedIndices = { 0, 1 } lastGetIndex/lastGetValue = 1/1 (cosistent) B) after quietClearSelection() in clearAndSelect() selectedIndices = { } lastGetIndex/lastGetValue = 1/1 (inconsistent) C) After select() in clearAndSelect() selectedIndices = { 2 } lastGetIndex/lastGetValue = 1/1 (inconsistent) At last, line 373 in MultiSelectionModelBase.java, indexOf(2) returns incorrect index -1 (expected result is 0). 373: int changeIndex = selectedIndicesSeq.indexOf(row); 374: change = new NonIterableChange.GenericAddRemoveChange<>( 375: changeIndex, changeIndex+1, previousSelectedIndices, selectedIndicesSeq); STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Run my reproduce program and push 'reproduce' button. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - selection changed added 0 1 [a] selection changed added 1 2 [b] selection changed removed 0 1 [a, b] added 0 1 [c] ACTUAL - selection changed added 0 1 [a] selection changed added 1 2 [b] selection changed removed -1 0 [a, b] added -1 0 =>java.lang.IndexOutOfBoundsException in thread "JavaFX Application Thread" ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.subList(ReadOnlyUnbackedObservableList.java:136) at javafx.collections.ListChangeListener$Change.getAddedSubList(ListChangeListener.java:242) at test.App.lambda$0(App.java:34) at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164) at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73) at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.callObservers(ReadOnlyUnbackedObservableList.java:75) at javafx.scene.control.MultipleSelectionModelBase$1.onChanged(MultipleSelectionModelBase.java:97) at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329) at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73) at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.callObservers(ReadOnlyUnbackedObservableList.java:75) at javafx.scene.control.MultipleSelectionModelBase.clearAndSelect(MultipleSelectionModelBase.java:378) at javafx.scene.control.ListView$ListViewBitSetSelectionModel.clearAndSelect(ListView.java:1403) at test.App.lambda$1(App.java:44) ... REPRODUCIBILITY : This bug can be reproduced often. ---------- BEGIN SOURCE ---------- package test; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener.Change; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.control.MultipleSelectionModel; import javafx.scene.control.SelectionMode; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class App extends Application { static void log(String fmt, Object...args) { System.out.format(fmt, args); } @Override public void start(Stage primaryStage) { ListView<String> listView = new ListView<>( FXCollections.observableArrayList("a", "b", "c")); MultipleSelectionModel<String> sm = listView.getSelectionModel(); sm.setSelectionMode(SelectionMode.MULTIPLE); sm.getSelectedItems().addListener((Change<? extends String> c) -> { log("selection changed\n"); while (c.next()) { if (c.wasRemoved()) { log(" removed %d %d\n", c.getFrom(), c.getTo()); log(" %s\n", c.getRemoved()); } if (c.wasAdded()) { log(" added %d %d\n", c.getFrom(), c.getTo()); log(" %s\n", c.getAddedSubList()); } } }); Button button = new Button("reproduce"); button.setOnAction((ev) -> { sm.clearSelection(); sm.select(0); sm.select(1); // following invocation causes IndexOutOfBoundsException sm.clearAndSelect(2); }); VBox root = new VBox(button, listView); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ---------- END SOURCE ----------

    JDK Bug System | 6 months ago | Webbug Group
    java.lang.IndexOutOfBoundsException
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

    5 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IndexOutOfBoundsException

      No message provided

      at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.subList()
    2. com.sun.javafx
      ReadOnlyUnbackedObservableList.subList
      1. com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.subList(ReadOnlyUnbackedObservableList.java:136)
      1 frame
    3. javafx.collections
      ListChangeListener$Change.getAddedSubList
      1. javafx.collections.ListChangeListener$Change.getAddedSubList(ListChangeListener.java:242)
      1 frame
    4. com.sun.javafx
      ListViewBehavior.lambda$new$177
      1. com.sun.javafx.scene.control.behavior.ListViewBehavior.lambda$new$177(ListViewBehavior.java:269)
      1 frame
    5. javafx.collections
      WeakListChangeListener.onChanged
      1. javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
      1 frame
    6. com.sun.javafx
      ReadOnlyUnbackedObservableList.callObservers
      1. com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
      2. com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
      3. com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.callObservers(ReadOnlyUnbackedObservableList.java:75)
      3 frames
    7. FXSampler
      ListView$ListViewBitSetSelectionModel.clearAndSelect
      1. javafx.scene.control.MultipleSelectionModelBase.clearAndSelect(MultipleSelectionModelBase.java:378)
      2. javafx.scene.control.ListView$ListViewBitSetSelectionModel.clearAndSelect(ListView.java:1403)
      2 frames
    8. com.sun.javafx
      CellBehaviorBase.mousePressed
      1. com.sun.javafx.scene.control.behavior.CellBehaviorBase.simpleSelect(CellBehaviorBase.java:256)
      2. com.sun.javafx.scene.control.behavior.CellBehaviorBase.doSelect(CellBehaviorBase.java:220)
      3. com.sun.javafx.scene.control.behavior.CellBehaviorBase.mousePressed(CellBehaviorBase.java:150)
      3 frames
    9. FXSampler
      BehaviorSkinBase$1.handle
      1. com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:95)
      2. com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      2 frames
    10. com.sun.javafx
      EventUtil.fireEvent
      1. com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      2. com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      3. com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      4. com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      5. com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      6. com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      7. com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      8. com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      9. com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      10. com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      11. com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      12. com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      13. com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      14. com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      15. com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      16. com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      17. com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      17 frames
    11. javafx.event
      Event.fireEvent
      1. javafx.event.Event.fireEvent(Event.java:198)
      1 frame
    12. javafx.scene
      Scene$ScenePeerListener.mouseEvent
      1. javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
      2. javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
      3. javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
      4. javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
      4 frames
    13. com.sun.javafx
      GlassViewEventHandler$MouseEventNotification.run
      1. com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
      2. com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
      2 frames
    14. Java RT
      AccessController.doPrivileged
      1. java.security.AccessController.doPrivileged(Native Method)
      1 frame
    15. com.sun.javafx
      GlassViewEventHandler.handleMouseEvent
      1. com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(GlassViewEventHandler.java:388)
      2. com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      3. com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
      3 frames
    16. com.sun.glass
      WinApplication.lambda$null$149
      1. com.sun.glass.ui.View.handleMouseEvent(View.java:555)
      2. com.sun.glass.ui.View.notifyMouse(View.java:937)
      3. com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      4. com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
      4 frames
    17. Java RT
      Thread.run
      1. java.lang.Thread.run(Thread.java:745)
      1 frame