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

Spinner<Integer> throws a ClassCastException under Linux

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_66"
        Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
        Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux pc682 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


        A DESCRIPTION OF THE PROBLEM :
        An JavaFX Spinner<Integer> throws a "java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer" exception under Linux whereas it perfectly works under Windows.
        The problem seems to be that the JVM uses the order of the constructors of Spinner to decide whether to instantiate a Spinner<Double> or Spinner<Integer> and this constructor order seems to be interpreted differently in the Windows JVM and the Linux JVM.
        That's why a Java program with a Spinner<Integer> that runs nicely under Windows throws an exception under Linux.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Use the example code from the description, start the application and change the spinner value.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The Spinner should not throw an exception.
        ACTUAL -
        The Spinner throws the following exception (under Linux):
        Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
        at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:361)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:176)
        at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:142)
        at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
        at javafx.beans.property.ObjectPropertyBase.access$000(ObjectPropertyBase.java:51)
        at javafx.beans.property.ObjectPropertyBase$Listener.invalidated(ObjectPropertyBase.java:233)
        at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
        at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
        at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
        at javafx.scene.control.SpinnerValueFactory.setValue(SpinnerValueFactory.java:150)
        at javafx.scene.control.SpinnerValueFactory$DoubleSpinnerValueFactory.increment(SpinnerValueFactory.java:850)
        at javafx.scene.control.Spinner.increment(Spinner.java:394)
        at com.sun.javafx.scene.control.behavior.SpinnerBehavior.increment(SpinnerBehavior.java:132)
        at com.sun.javafx.scene.control.behavior.SpinnerBehavior.lambda$new$209(SpinnerBehavior.java:62)
        at com.sun.javafx.scene.control.behavior.SpinnerBehavior.startSpinning(SpinnerBehavior.java:151)
        at com.sun.javafx.scene.control.skin.SpinnerSkin.lambda$new$468(SpinnerSkin.java:99)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
        at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
        at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
        at com.sun.glass.ui.View.notifyMouse(View.java:937)
        at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
        at java.lang.Thread.run(Thread.java:745)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        Here is a minimal example that shows the bug when you change the Spinner value:

        TestApplication.java
        --------------------
        import javafx.application.Application;
        import javafx.fxml.FXMLLoader;
        import javafx.scene.Parent;
        import javafx.scene.Scene;
        import javafx.stage.Stage;

        import java.net.URL;

        public class TestApplication extends Application {

        @Override
        public void start(Stage stage) throws Exception {
        URL resource = getClass().getResource("test.fxml");
        FXMLLoader loader = new FXMLLoader(resource);
        Parent root = loader.load();

        stage.setScene(new Scene(root));

        stage.show();
        }

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

        }

        TestController.java
        -------------------
        import javafx.fxml.Initializable;
        import javafx.scene.control.Spinner;

        import java.net.URL;
        import java.util.ResourceBundle;

        public class TestController implements Initializable {

        public Spinner<Integer> smoothingSpinner;

        @Override
        public void initialize(URL location, ResourceBundle resources) {
        smoothingSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
        System.out.println(newValue);
        });
        }

        }

        test.fxml
        ---------
        <?xml version="1.0" encoding="UTF-8"?>
        <?import javafx.scene.control.Spinner?>
        <?import javafx.scene.layout.GridPane?>
        <?import javafx.scene.layout.VBox?>
        <VBox prefHeight="200.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="TestController">
          <Spinner fx:id="smoothingSpinner" editable="true" min="0" max="100" initialValue="3" />
        </VBox>

        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  vadim Vadim Pakhnushev
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: