launchdarkly / android-client-sdk

LaunchDarkly Client-side SDK for Android
Other
45 stars 23 forks source link

NullPointerException in DiagnosticEventProcessor.stopScheduler #127

Closed valeriyo closed 3 years ago

valeriyo commented 3 years ago

With 2.14.1, this happens:

Caused by java.lang.NullPointerException: Attempt to invoke interface method 'void java.util.concurrent.ScheduledExecutorService.shutdown()' on a null object reference
       at com.launchdarkly.android.DiagnosticEventProcessor.stopScheduler(DiagnosticEventProcessor.java:88)
       at com.launchdarkly.android.DiagnosticEventProcessor.close(DiagnosticEventProcessor.java:92)
       at com.launchdarkly.android.LDClient.closeInternal(LDClient.java:458)
       at com.launchdarkly.android.LDClient.closeInstances(LDClient.java:468)
       at com.launchdarkly.android.LDClient.close(LDClient.java:451)
       ...

if LDClient.close is called before app is foregrounded, because DiagnosticEventProcessor.executorService is initialized inside DiagnosticEventProcessor.startScheduler which is called only when app is foregrounded for the first time.

Suggest to check for null:

  private void stopScheduler() {
    if (executorService != null) {
      executorService.shutdown();
    }
  }
gwhelanLD commented 3 years ago

Hi @valeriyo,

This issue had been fixed in the 3.0.0 release, but I've back-ported a fix in a 2.14.2 release as well.

Thanks, @gwhelanLD