sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.29k stars 1.06k forks source link

Exception when closing Snackbar while a event is still active #1101

Closed qtran closed 4 years ago

qtran commented 4 years ago
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
    at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
    at java.util.concurrent.ConcurrentHashMap$KeySetView.remove(ConcurrentHashMap.java:4569)
    at com.jfoenix.controls.JFXSnackbar.lambda$null$5(JFXSnackbar.java:249)
    at com.jfoenix.controls.JFXSnackbar$$Lambda$11.handle(Unknown Source)
    at javafx.animation.Animation.impl_finished(Animation.java:1132)
    at javafx.animation.AnimationAccessorImpl.finished(AnimationAccessorImpl.java:49)
    at com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(SingleLoopClipEnvelope.java:103)
    at javafx.animation.Animation.impl_timePulse(Animation.java:1102)
    at javafx.animation.Animation$1.lambda$timePulse$25(Animation.java:186)
    at java.security.AccessController.doPrivileged(Native Method)
    at javafx.animation.Animation$1.timePulse(Animation.java:185)
    at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
    at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:514)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:498)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:491)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$403(QuantumToolkit.java:319)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)

Code to reproduce:

public class TestApplicaton extends Application {

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

    @Override
    public void start(final Stage primaryStage) {
    primaryStage.setTitle("Hello!");

    final StackPane root = new StackPane();

    final JFXSnackbar snackbar = new JFXSnackbar(root);

    final Button btn = new Button();
    btn.setText("Show snackbar");
    btn.setOnAction(event -> {
        final JFXSnackbarLayout content = new JFXSnackbarLayout("Hello World!", "Hide", e -> snackbar.close());
        snackbar.enqueue(new SnackbarEvent(content, Duration.seconds(10)));
    });

    root.getChildren().add(btn);
    final Scene scene = new Scene(root, 400, 250);
    root.getStylesheets().add(JFoenixResources.load("css/jfoenix-design.css").toExternalForm());
    primaryStage.setScene(scene);

    primaryStage.show();
    }
}

Tested with version 8.0.9

Kind regards

gabrielpaim commented 3 years ago

Hi there,

I'm still experiencing this issue, even on version 8.0.10. The proposed test code fails after the event duration time: in that case, 10s. The problem also happens on 8.0.9. This is the stack trace.

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
    at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
    at java.util.concurrent.ConcurrentHashMap$KeySetView.remove(ConcurrentHashMap.java:4569)
    at com.jfoenix.controls.JFXSnackbar.lambda$null$5(JFXSnackbar.java:249)
    at com.jfoenix.controls.JFXSnackbar$$Lambda$11.handle(Unknown Source)
    at javafx.animation.Animation.impl_finished(Animation.java:1132)
    at javafx.animation.AnimationAccessorImpl.finished(AnimationAccessorImpl.java:49)
    at com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(SingleLoopClipEnvelope.java:103)
    at javafx.animation.Animation.impl_timePulse(Animation.java:1102)
    at javafx.animation.Animation$1.lambda$timePulse$0(Animation.java:186)
    at java.security.AccessController.doPrivileged(Native Method)
    at javafx.animation.Animation$1.timePulse(Animation.java:185)
    at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
    at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:557)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:541)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:534)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:340)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$10(GtkApplication.java:245)
    at java.lang.Thread.run(Thread.java:748)

Additionally, implementing the workaround proposed by @sawaYch on the another related issue also does not completely solve the problem, as it makes the second event invisible.

Am I doing something wrong? Thank you all :)