Insubstantial / insubstantial

Swing look-and-feel library and assorted widgets
195 stars 57 forks source link

NullPointerException in RootPaneDefaultButtonTracker #137

Open enwired opened 9 years ago

enwired commented 9 years ago

The following stack trace has been found in one of our applications using Insubstantial 7.3:

java.lang.NullPointerException
    at org.pushingpixels.substance.internal.animation.RootPaneDefaultButtonTracker.onTimelineEvent(RootPaneDefaultButtonTracker.java:173)
    at org.pushingpixels.substance.internal.animation.RootPaneDefaultButtonTracker.onTimelineStateChanged(RootPaneDefaultButtonTracker.java:147)
    at org.pushingpixels.trident.Timeline$Chain.onTimelineStateChanged(Timeline.java:214)
    at org.pushingpixels.trident.TimelineEngine$1.run(TimelineEngine.java:591)
    at org.pushingpixels.trident.TimelineEngine$TimelineCallbackThread.run(TimelineEngine.java:242)```

The error occurs here:
```java
            RootPaneDefaultButtonTracker tracker = trackers.get(jButton);
            tracker.stopTimer();

I suspect, but am not sure, that it is caused by this order of events:

            tracker.startTimer();
            trackers.put(jButton, tracker);

The timer could start firing events prior to the tracker being put into the map.

I suggest to fix the problem by doing a check for null at the point of the observed error:

            RootPaneDefaultButtonTracker tracker = trackers.get(jButton);
      if (tracker != null) {
            tracker.stopTimer();
      }

and also reversing the later two lines to be:

            trackers.put(jButton, tracker);
            tracker.startTimer();