JDK-8252863 : Spinner keeps spinning if removed from Scene
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u261,openjfx14,openjfx15
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2020-09-04
  • Updated: 2020-09-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
ADDITIONAL SYSTEM INFORMATION :
Java 1.8.0_144 on Redhat Linux 6.8, also OpenJDK 14.0.1 on Windows 7


A DESCRIPTION OF THE PROBLEM :
If either the increment/decrement arrows are pressed whilst a spinner is removed from the Scene it keeps going, even when it is added back to the Scene

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the test app
2. (Within 10 seconds of window appearing) press and hold down mouse button on spinner increment button
3. Wait for spinner to be removed
4. Release mouse button


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Spinner should stop incrementing
ACTUAL -
Spinner is still incremented when added back to the scene

---------- BEGIN SOURCE ----------
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Spinner;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.util.Duration;

public class SpinnerKeepsIncrementing extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Spinner<Double> spinner = new Spinner<>(0d, 1000d, 500d);
        HBox container = new HBox(spinner);
        primaryStage.setScene(new Scene(container));
        primaryStage.show();

        Timeline timeline = new Timeline();
        timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(10), event -> {
            container.getChildren().clear();
        }));
        timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(15), event -> {
            container.getChildren().setAll(spinner);
        }));
        timeline.play();
    }

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

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Following monkey patch can clear the error state

    /**
     * if we're holding down key on spinner whilst the cell changes bug in javaFX
     * keeps firing update events.
     * 
     * manually fire mouse released if decoupled from scene as workaround
     */
    private void monkeyPatchSpinnerBug(Spinner<?> spinner) {
        spinner.sceneProperty().addListener((obs, oldValue, newValue) -> {
            Node increment = spinner.lookup(".increment-arrow-button");
            if (increment != null) {
                increment.getOnMouseReleased().handle(null);
            }
            Node decrement = spinner.lookup(".decrement-arrow-button");
            if (decrement != null) {
                decrement.getOnMouseReleased().handle(null);
            }
        });
    }

FREQUENCY : always



Comments
It seems to be a corner case and needs to be addressed. Removing the Spinner from a Scene while increment/decrement button is pressed seems a uncommon scenario.
08-09-2020

See Discussion here: https://stackoverflow.com/questions/55933513/javafx-spinner-keeps-going-after-removed-from-scene
07-09-2020

Checking with attached test case on windows 10 Test Result: ============ 8u261 : Fail OpenJDK 14.0.1+Javafx 14.0.1 : Fail openjfx_14.0.2.1 : Fail openjfx_16ea : Fail
07-09-2020