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

Type parameter mix-up in PropertyValueFactory internal implemenation

XMLWordPrintable

      Though not visible at runtime due to type erasure, it should be fixed to keep code maintainers' sanity :-)

      From the api doc:

          S - The type of the class contained within the TableView.items list.
          T - The type of the class contained within the TableColumn cells.

      That is, S is the type returned by dataFeature.getValue and the class we create a PropertyReference for. The internal implementation incorrectly type-casts that to T to serve the incorrect parameter type (the actual reference takes the actual bean-class, thus is correct)

          @Override
         public ObservableValue<T> call(CellDataFeatures<S,T> param) {
              // would blow without type erasure: the value type is S
              return getCellDataReflectively((T)param.getValue());
          }

          // internal method with incorrect parameter type: rowData
          // is of type S
          private ObservableValue<T> getCellDataReflectively(T rowData) {
                ....
                this.propertyRef = new PropertyReference<T>(rowData.getClass(), getProperty());
           }

      Fix: simply remove the type cast and change the internal methods parameter type to S.

      While you are at it: I would suggest to change the name columnClass to beanClass because .. that's what it is. This misnomer might have triggered the mix-up: the columnClass indeed is T :-)

            jgiles Jonathan Giles
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: