-
Bug
-
Resolution: Unresolved
-
P4
-
9
-
java9-ea-180
The example below adds the same TableColumn more than once: in case A, that's done across nested columns -> run and see a NPE produced in the sizing code, the real error is not indicated. For comparison, case B (un/comment the respective lines) adds the duplicate in the same level of nesting -> run and see the IllegalStateException, which is expected.
The example:
import java.util.Locale;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class DuplicateTableColumnNPE extends Application {
private Parent getContent() {
TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(
Locale.getAvailableLocales()));
TableColumn<Locale, String> country = new TableColumn<>("Country");
TableColumn<Locale, String> countryCode = new TableColumn<>("Code");
countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
TableColumn<Locale, String> countryDisplay = new TableColumn<>("Name");
countryDisplay.setCellValueFactory(new PropertyValueFactory<>("displayCountry"));
// A: this throws NPE in auto-sizing code
// incorrect exception
// that is duplicates across nested headers are not detected
country.getColumns().addAll(countryCode, countryDisplay);
table.getColumns().addAll(countryCode);
// B: this throws IllegalStateException - duplicate columns
// correct exception
// table.getColumns().addAll(countryCode, countryCode);
BorderPane pane = new BorderPane(table);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 800, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The example:
import java.util.Locale;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class DuplicateTableColumnNPE extends Application {
private Parent getContent() {
TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(
Locale.getAvailableLocales()));
TableColumn<Locale, String> country = new TableColumn<>("Country");
TableColumn<Locale, String> countryCode = new TableColumn<>("Code");
countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
TableColumn<Locale, String> countryDisplay = new TableColumn<>("Name");
countryDisplay.setCellValueFactory(new PropertyValueFactory<>("displayCountry"));
// A: this throws NPE in auto-sizing code
// incorrect exception
// that is duplicates across nested headers are not detected
country.getColumns().addAll(countryCode, countryDisplay);
table.getColumns().addAll(countryCode);
// B: this throws IllegalStateException - duplicate columns
// correct exception
// table.getColumns().addAll(countryCode, countryCode);
BorderPane pane = new BorderPane(table);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 800, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}