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

TableColumn: incorrect exception for duplicate columns across nested columns

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      java9-ea-180

      Description

      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);
          }

      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: