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

IllegalArgumentException: fromIndex(0) > toIndex(-1) after clear and select TableCell

XMLWordPrintable

        Given a TableView with multiple selection mode and cell selection enabled, after selecting some cells (with shift), and deselecting them by clicking on one of the selected cells, this exception is thrown:

        Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: fromIndex(0) > toIndex(-1)
                at java.base/java.util.AbstractList.subListRangeCheck(AbstractList.java:509)
                at java.base/java.util.ArrayList.subList(ArrayList.java:1137)
                at javafx.controls/javafx.scene.control.ControlUtils$1.<init>(ControlUtils.java:90)
                at javafx.controls/javafx.scene.control.ControlUtils.buildClearAndSelectChange(ControlUtils.java:75)
                at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearAndSelect(TableView.java:2468)
                at javafx.controls/javafx.scene.control.TableView$TableViewSelectionModel.clearAndSelect(TableView.java:1966)
                at javafx.controls/com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.simpleSelect(TableCellBehaviorBase.java:213)
                at javafx.controls/com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.doSelect(TableCellBehaviorBase.java:195)
                at javafx.controls/com.sun.javafx.scene.control.behavior.CellBehaviorBase.mouseReleased(CellBehaviorBase.java:185)
                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:247)
                at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
                at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
                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.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.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$MouseHandler.process(Scene.java:3880)
                at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1873)
                at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2606)
                at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
                at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
                at java.base/java.security.AccessController.doPrivileged(Native Method)
                at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
                at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:423)
                at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
                at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:557)
                at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:943)
                at javafx.graphics/com.sun.glass.ui.mac.MacView.notifyMouse(MacView.java:127)

        This happens only after JDK-8196065 integration (starting 17-ea+14).

        Attached is a test that can be used to reproduce the issue, with head or any ea greater than 17-ea+13.

        Steps:
        1. Select the first cell in the first row by mouse clicking on it. Log:
        Change: { [Person{a b}] added at 0 }, selected items: [Person{a b}]

        2. Press Shift and mouse click the other cell in the same row. Log:
        Change: { [Person{a b}] removed at 0 }, selected items: []
        Change: { [Person{a b}] added at 0 }, selected items: [Person{a b}]

        3. Release Shift, and mouse click on one of the already-selected cells.

        Before 17-ea+14, it will log:
        Change: { [null] removed at 1 }, selected items: []
        However, starting with 17-ea+14, the above exception is thrown.

        After a quick look, it seems that JDK-8196065 introduced Collections.binarySearch in ControlUtils::buildClearAndSelectChange, which after following the above steps, it returns 0 for some reason, which sets midIndex = -1, causing subList(0, midIndex) to return the above exception.

              mstrauss Michael Strauß
              jpereda Jose Pereda
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: