Fix possible crash in RevealableMessageManager.

The crash happened because #getNextClosestEvent was called when
mmsDatabase was null, which would normally be impossible. However, it
seems implied that somehow #getNextClosestEvent was being called in the
parent constructor before the child class was fully initialized. That
would imply that the looper was called synchronously in some freak
scenario, but it's the only explanation. So I added a delay to the call
in the parent constructor.

```java
java.lang.NullPointerException:
  at org.thoughtcrime.securesms.revealable.RevealableMessageManager.getNextClosestEvent (RevealableMessageManager.java:40)
  at org.thoughtcrime.securesms.revealable.RevealableMessageManager.getNextClosestEvent (RevealableMessageManager.java:23)
  at org.thoughtcrime.securesms.service.TimedEventManager.lambda$scheduleIfNecessary$1 (TimedEventManager.java:44)
  at org.thoughtcrime.securesms.service.-$$Lambda$TimedEventManager$kZDO3F2WBQVtGx-SkAgEDt8jCeU.run (Unknown Source:2)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:193)
  at android.os.HandlerThread.run (HandlerThread.java:65)
```
This commit is contained in:
Greyson Parrelli 2019-07-23 09:23:52 -04:00
parent ba8597900a
commit acb48752ce

View file

@ -30,7 +30,9 @@ public abstract class TimedEventManager<E> {
this.application = application;
this.handler = new Handler(handlerThread.getLooper());
scheduleIfNecessary();
// XXX Have to delay it because some devices will run the resulting handler#post synchronously,
// triggering a method call to an uninitialized child class.
handler.postDelayed(this::scheduleIfNecessary, 5);
}
/**