sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.27k stars 1.05k forks source link

Closing JFXSnackbar causes NullPointerException #1217

Open gzep opened 2 years ago

gzep commented 2 years ago

I'm using Snackbars as a simple undo mechanism.

deleteButton.setOnAction(evt -> {
    String item = nodeList.getSelectionModel().getSelectedItem();
    if (item != null) {
        nodeList.getItems().remove(item);
        snackbar.enqueue(new SnackbarEvent(
                new JFXSnackbarLayout("removed " + item, "UNDO", evt2 -> Platform.runLater(() -> {
                    nodeList.getItems().add(item);
                    snackbar.close();
                })), Duration.seconds(8)));
    }
});

Where deleteButton is a JFXButton and nodeList is JFXListView. When I pres UNDO on the snackbar there will be a NullPointer after the duration:

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.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
    at java.lang.Thread.run(Thread.java:748)
sshahine commented 2 years ago

@gzep can you provide a SSCCE for this issue?

gzep commented 2 years ago

@sshahine hope this helps: https://github.com/gzep/sscce-snackbar On my system I was able to handle it with two null checks in a copy of JFXSnackbar class but I think it aint the best fix.

gzep commented 2 years ago

@sshahine I added a repo with my fix. (was unable to place a pull request) If you like to review it: https://github.com/gzep/jfoenix-snackbar-fix