Details
-
Type:
Bug
-
Status: Resolved
-
Priority:
P4
-
Resolution: Fixed
-
Affects Version/s: 8u40
-
Fix Version/s: 8u60
-
Component/s: javafx
-
Labels:
-
Environment:
Ubuntu 14.10
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
-
Subcomponent:
Description
When calling tableView.getSelectionModel().getFocusedIndex() an exception is thrown if the TableView is empty.
To reproduce just run the example code:
Example Code:
package bugreports;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import static javafx.application.Platform.runLater;
public class TableViewNullPointerException extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final TableView<String> view = new TableView<>();
primaryStage.setScene(new Scene(view));
primaryStage.show();
runLater(() -> view.getSelectionModel().getFocusedIndex());
}
}
Workaround for now is something like this:
int index;
try {
index = tableView.getSelectionModel().getFocusedIndex();
} catch (NullPointerException e) {
index = -1;
}
To reproduce just run the example code:
Example Code:
package bugreports;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import static javafx.application.Platform.runLater;
public class TableViewNullPointerException extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final TableView<String> view = new TableView<>();
primaryStage.setScene(new Scene(view));
primaryStage.show();
runLater(() -> view.getSelectionModel().getFocusedIndex());
}
}
Workaround for now is something like this:
int index;
try {
index = tableView.getSelectionModel().getFocusedIndex();
} catch (NullPointerException e) {
index = -1;
}