JFoenix icon indicating copy to clipboard operation
JFoenix copied to clipboard

Closing JFXSnackbar causes NullPointerException

Open gzep opened this issue 4 years ago • 3 comments

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<String>. 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)

gzep avatar Sep 09 '21 20:09 gzep

@gzep can you provide a SSCCE for this issue?

sshahine avatar Sep 13 '21 02:09 sshahine

@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 avatar Sep 13 '21 11:09 gzep

@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

gzep avatar Sep 19 '21 19:09 gzep