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

ListView sometimes throws an IndexOutOfBoundsException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • jfx22
    • jfx21
    • javafx
    • b05

    Description

      Steps to reproduce:

      Scroll the all the way down by dragging the scrollbar thumb. Now try to scroll back up by clicking on the bar near the top (not on the thumb).

      I managed to reproduce this with 21-ea-24 but couldn't in 19.0.2.1 (but there seems to be another problem there, as you can't click the bar all the way back up in that way).

      Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 2

            at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)

            at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)

            at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)

            at java.base/java.util.Objects.checkIndex(Objects.java:359)

            at java.base/java.util.ArrayList.get(ArrayList.java:427)

            at javafx.controls/javafx.scene.control.skin.VirtualFlow.updateCellSize(VirtualFlow.java:3099)

            at javafx.controls/javafx.scene.control.skin.VirtualFlow.positionCell(VirtualFlow.java:1975)

            at javafx.controls/javafx.scene.control.skin.VirtualFlow.scrollPixels(VirtualFlow.java:1650)

            at javafx.controls/javafx.scene.control.skin.VirtualFlow.tryScrollOneCell(VirtualFlow.java:1565)

            at javafx.controls/javafx.scene.control.skin.VirtualFlow.scrollTo(VirtualFlow.java:1536)

            at javafx.controls/com.sun.javafx.scene.control.VirtualScrollBar.adjustValue(VirtualScrollBar.java:142)

            at javafx.controls/com.sun.javafx.scene.control.behavior.ScrollBarBehavior.lambda$20(ScrollBarBehavior.java:162)

            at javafx.controls/com.sun.javafx.scene.control.behavior.ScrollBarBehavior.trackPress(ScrollBarBehavior.java:173)

            at javafx.controls/javafx.scene.control.skin.ScrollBarSkin.lambda$7(ScrollBarSkin.java:411)

            at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)

            at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)

            at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)

            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.controls/javafx.scene.control.skin.VirtualFlow.lambda$2(VirtualFlow.java:369)

            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:3984)

            at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1890)

            at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2708)

            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:1)

            at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)

            at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$2(GlassViewEventHandler.java:450)

            at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)

            at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)

            at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:551)

            at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:937)

            at javafx.graphics/com.sun.glass.ui.mac.MacView.notifyMouse(MacView.java:127)

      Code:

      package org.int4.sdui.ui;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ListCell;
      import javafx.scene.control.ListView;
      import javafx.scene.control.TextArea;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Priority;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Main2 {

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

        public static class UI extends Application {

          @Override
          public void start(Stage primaryStage) throws InterruptedException {
            Image image1 = new Image("https://picsum.photos/512/512");
            Image image2 = new Image("https://picsum.photos/512/512");

            TextArea prompt = new TextArea("a flower on Mars");
            Button button = new Button("Submit");
            ListView<Image> listView = new ListView<>();

            while(image1.isBackgroundLoading() || image2.isBackgroundLoading()) {
              Thread.sleep(100);
            }

            listView.getItems().addAll(image1, image2);
            listView.setCellFactory(lv -> {
              final ImageView imageView = new ImageView();

              return new ListCell<>() {
                protected void updateItem(Image image, boolean empty) {
                  super.updateItem(image, empty);
                  if(empty) {
                    setGraphic(null);
                  }
                  else {
                    imageView.setImage(image);
                    setGraphic(imageView);
                  }
                }
              };
            });

            HBox hbox = new HBox() {{
              getChildren().addAll(
                new VBox() {{
                  getChildren().addAll(prompt, button);
                }},
                listView
              );
            }};

            HBox.setHgrow(listView, Priority.ALWAYS);

            Scene scene = new Scene(hbox);

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


      Attachments

        Issue Links

          Activity

            People

              angorya Andy Goryachev
              jhendrikx John Hendrikx
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: