JDK-8140504 : TreeView/TreeTableView show "index exceeds maxCellCount" warning after scrolling
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u40,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-10-23
  • Updated: 2017-01-15
  • Resolved: 2017-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
If a TreeView/TreeTableView has a vertical scroll bar and I scroll to the end of the tree and then resize my window to be larger than the tree, I get the following warnings:

For TreeView:
Oct 23, 2015 5:42:34 PM com.sun.javafx.scene.control.skin.VirtualFlow addTrailingCells
INFO: index exceeds maxCellCount. Check size calculations for class com.sun.javafx.scene.control.skin.TreeViewSkin$1

For TreeTableView:
Oct 23, 2015 5:42:59 PM com.sun.javafx.scene.control.skin.VirtualFlow addTrailingCells
INFO: index exceeds maxCellCount. Check size calculations for class javafx.scene.control.TreeTableRow

Intermittently, one or two of the associated TreeItem icons will be missing as well.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package sample;

import javafx.application.Application;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Button treeViewButton = new Button("TreeView Test Case");
        treeViewButton.setOnAction(e -> openTreeViewTestCase());

        Button treeTableViewButton = new Button("TreeTableView Test Case");
        treeTableViewButton.setOnAction(e -> openTreeTableViewTestCase());

        VBox root = new VBox(10, treeViewButton, treeTableViewButton);
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    private void openTreeViewTestCase() {
        TreeView<String> tree = new TreeView<>();

        TreeItem<String> treeRoot = new TreeItem<>("root");
        treeRoot.setExpanded(true);
        tree.setRoot(treeRoot);

        for (int i = 0; i < 10; i++)
            treeRoot.getChildren().add(new TreeItem<>("child"));

        StackPane root = new StackPane();
        root.getChildren().add(tree);

        Stage stage = new Stage();
        stage.setTitle("Scroll to end and resize window to show full tree");
        stage.setScene(new Scene(root, 500, 200));
        stage.show();
    }

    private void openTreeTableViewTestCase() {
        TreeTableView<String> treeTable = new TreeTableView<>();
        TreeTableColumn<String, String> col = new TreeTableColumn<>("Scroll to end and resize window to show full tree");
        col.setPrefWidth(330);
        col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getValue()));
        treeTable.getColumns().add(col);

        TreeItem<String> treeRoot = new TreeItem<>("root");
        treeRoot.setExpanded(true);
        treeTable.setRoot(treeRoot);

        for (int i = 0; i < 10; i++)
            treeRoot.getChildren().add(new TreeItem<>("child"));

        StackPane root = new StackPane();
        root.getChildren().add(treeTable);

        Stage stage = new Stage();
        stage.setTitle("Scroll to end and resize window to show full tree");
        stage.setScene(new Scene(root, 500, 200));
        stage.show();
    }

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

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


Comments
Changeset: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/5bdfac345554
15-01-2017

OK. I buy in the code readability comment. +1 for this fix.
13-01-2017

Ajit, thanks for your feedback. 1) I tend to like keeping maxCellCount - it aids in the readability. Let me know if you disagree. 2) This aspect of the bug report is unrelated - there have been numerous issues related to the graphics, most of which have been resolved in recent time. I don't think there is a relationship between this issue and the icons disappearing.
12-01-2017

1) With changed logic, do we still need 'maxCellCount'? I suppose, we can use viewportLength directly in if condition. 2) In bug description there is this sentence - "Intermittently, one or two of the associated TreeItem icons will be missing as well." Have you checked the proposed fix fixes it?
12-01-2017

Webrev: http://cr.openjdk.java.net/~jgiles/8140504/ As far as I can tell there is no functionality regression here, it is simply the logging message in the console that appears (where it didn't before). Nevertheless, I have a webrev available below that resolves this issue. In short, the error was being printed because the VirtualFlow assumed that we were trying to get more cells than what is reasonable. In reading the code, I believe there is a mistake where the maxCellCount was being calculated incorrectly: the maxCellCount is essentially the number of cells that could possibly exist, assuming they had the minimum possible height of 1px. This can therefore be determined simply by getting the height of the viewport. This isn't what is in the code however - in the code we have the maxCellCount being calculated as the viewport height minus the scrolling offset. In the case of this bug report, the scrolling offset was the full height of the VirtualFlow, so we ended up getting maxCellCount of 1 - 2 cells. This would then lead to the error being printed out erroneously. The webrev therefore simply changes the maxCellCount calculation to simply be the viewport height, and so far in my testing there are no regressions that I can see (noting that this maxCellCount is only used for the error condition, and not in the normal flow of the code).
11-01-2017

Targeting back to 9 since it is now marked as a P3 regression. We can defer it if it is not feasible to fix for 9.
05-01-2017

Verified the issue against 8,8u31,8u40,8u112,8u122ea,,9ea on windows,Linux and could reproduce the issue on 8u40 and onward. Steps to reproduce(javac): ********************************** - Run the attached file(JI_9025874.java) with JDK. Result: ********* OS : windows 7 64 bit, Ubuntu Linux 14.04 LTS JDK: ++++ 8 b132 : Pass 8u31 b13 : Pass >> 8u40 b27 : Fail <<=========== Introduced in version 8u112 b15 : Fail 8u122 b04 : Fail 9ea+149 : Fail ==============================================================
05-01-2017