Skip to content

NPE on LDClient.init #311

@malena4G

Description

@malena4G

SDK version
5.9.0

Describe the bug
We started using LD around 5.6.1 and we've consistenly gotten quite the high % of crashes in our app when trying to init the LDClient at the start of a session:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.HashMap.get(java.lang.Object)' on a null object reference
       at com.launchdarkly.sdk.android.LDClient.init(LDClient.java:252)

The issue has gotten worse now that we need to insantiate the client closer to the start of the app initialisation, the moment the first screen appears.

Our initialisation setup looks something like this:

val ldConfig = LDConfig.Builder(LDConfig.Builder.AutoEnvAttributes.Enabled)
            .applicationInfo(
                Components.applicationInfo()
                    .applicationId(applicationId)
                    .applicationName(...)
                    .applicationVersion(...)
                    .applicationVersionName(...)
            )
            .mobileKey(...)
            .build()
val ldContext = LDContext.builder(ContextKind.DEFAULT, userId)
                .name(userName)
                ...
                .build()
LDClient.init(applicationContext as Application, ldConfig, ldContext, 5)

To reproduce
There's not a consistent way to reproduce this. Up until now it only happened in crash reports in production.
With the new change (instantiating the client closer to the start of the app) this sometimes happen locally. Killing the app and restarting it usually fixes it.

OS/platform
Android app targeting version 35, compile version 36, minSdk 24.
Most of our userbase uses Samsung Galaxy A40e/A05 Android 13 to 15.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions