Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE when Network Tree window closing overlaps with event #234

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/org/openlcb/swing/networktree/TreePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Comparator;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;

import javax.swing.AbstractAction;
import javax.swing.JButton;
Expand Down Expand Up @@ -81,6 +82,16 @@ public void propertyChange(PropertyChangeEvent e) {
// This code will delay the updating of the display by a bit and coalesces update
// commands. This way we can ensure we don't spend too much CPU repeatedly
// updating the display.

if (timer == null) {
// A release() has removed the timer, which can
// happen if property changes overlap with the window closing.
// We ignore the event with a warning.
Logger logger = Logger.getLogger(TreePane.class.getName());
logger.warning("Data change while closing configuration window ignored");
return;
}

synchronized (timer) {
needResortTree = true;
}
Expand Down Expand Up @@ -403,7 +414,7 @@ public int compare(NodeTreeRep n1, NodeTreeRep n2) {
/**
* Cleans up all property change listeners etc in preparation when closing the window.
*/
public void release() {
public void release() {
timer.cancel();
timer = null; // get a new one next time
}
Expand Down