[ComboBox] class cast exception with generic comboBox.

XMLWordPrintable

      Could be dublicate of RT-22634;

      Run code:
      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class JavaApplication44 extends Application {

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

          public static enum CellType {

              ChoiceBox, ComboBox, CheckBox, TextField, MapValue, Default
          };

          @Override
          public void start(Stage stage) throws Exception {
              VBox vb = new VBox();

              ComboBox<CellType> cb = new ComboBox<CellType>();

              cb.getItems().addAll(CellType.values());

              cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<CellType>() {

                  @Override
                  public void changed(ObservableValue<? extends CellType> ov, CellType t, CellType t1) {
                      System.out.println(t1);
                  }
              });

              vb.getChildren().addAll(cb);

              Scene scene = new Scene(vb, 300, 300);
              stage.setScene(scene);
              stage.show();
          }
      }


      Exception:

      java.lang.ClassCastException: java.lang.String cannot be cast to javaapplication44.JavaApplication44$CellType
      at javaapplication44.JavaApplication44$1.changed(JavaApplication44.java:34)
      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:367)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
      at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:195)
      at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:161)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:130)
      at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
      at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:101)
      at javafx.scene.control.ComboBox$2.changed(ComboBox.java:223)
      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:367)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
      at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:123)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:130)
      at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
      at javafx.scene.control.ComboBoxBase.setValue(ComboBoxBase.java:148)
      at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.setTextFromTextFieldIntoComboBoxValue(ComboBoxListViewSkin.java:397)
      at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.access$200(ComboBoxListViewSkin.java:52)
      at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$3.handle(ComboBoxListViewSkin.java:143)
      at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$3.handle(ComboBoxListViewSkin.java:133)
      at com.sun.javafx.event.CompositeEventHandler.dispatchCapturingEvent(CompositeEventHandler.java:78)
      at com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:202)
      at com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:159)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchCapturingEvent(CompositeEventDispatcher.java:22)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:31)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
      at javafx.event.Event.fireEvent(Event.java:171)
      at javafx.scene.Scene$KeyHandler.process(Scene.java:3508)
      at javafx.scene.Scene$KeyHandler.access$2300(Scene.java:3463)
      at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1865)
      at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2261)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:126)
      at com.sun.glass.ui.View.handleKeyEvent(View.java:518)
      at com.sun.glass.ui.View.notifyKey(View.java:950)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
      at java.lang.Thread.run(Thread.java:662)

      To reproduce:
      Run app, select any item using keyboard (F4 -> down -> Enter). Get exception.

      I see, also, that if you will continue to select items with mouse, you will get exception too. But if you initially start selection with mouse, selection can be done without exceptions.

            Assignee:
            Jonathan Giles
            Reporter:
            Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: