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 crash with null pointer when accessing session #581

Closed
dss-kenya opened this issue Feb 6, 2023 · 8 comments
Closed

Fix crash with null pointer when accessing session #581

dss-kenya opened this issue Feb 6, 2023 · 8 comments

Comments

@dss-kenya
Copy link

I recently upgraded to 4.1.1 from version 3.0.0 and there seems to be a crash reported from the sdk:

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Map ee0.e.d()' on a null object reference
       at com.snowplowanalytics.snowplow.internal.session.Session.getSessionContext(Session.java:202)
       at com.snowplowanalytics.snowplow.internal.tracker.Tracker.workaroundForIncoherentSessionContext(Tracker.java:757)
       at com.snowplowanalytics.snowplow.internal.tracker.Tracker.track(Tracker.java:629)
       at com.snowplowanalytics.snowplow.internal.tracker.TrackerControllerImpl.track(TrackerControllerImpl.java:94)

i set the up the tracker as under:

Snowplow.setup(
            application,
            remoteConfig,
            listOf(configBundle)
        ) { configurationPair ->
            Snowplow.getDefaultTracker()?.attachGlobalContextToTracker() 
            -- manually attach global config since this is not possible at the moment with remoteConfig.
        }

and send the event as below:

Snowplow.getDefaultTracker()?.track(selfDescribingEvent)

Is there something i might be missing? Or may i please know why this crash is happening? I am confident this never happened with version 3.0.0

@dss-kenya dss-kenya changed the title [Question] 4.1.1 crashes the app with null pointer - at Session.getSessionContext - is anything missing something? [Question] 4.1.1 crashes the app with null pointer - at Session.getSessionContext - is anything missing? Feb 6, 2023
@mscwilson
Copy link
Contributor

Thanks for the report! We will try to replicate it and get back to you soon.

@matus-tomlein matus-tomlein changed the title [Question] 4.1.1 crashes the app with null pointer - at Session.getSessionContext - is anything missing? Fix crash with null pointer in Session.getSessionContext Feb 10, 2023
@krobert
Copy link

krobert commented Feb 10, 2023

HEy @mscwilson, we are experiencing the same issue, we were using 4.0.0 for a while, it started doing the issue, upgraded to 4.1.1 hoping it fixes it, but now there are more reports of this crash.
Its currently breaking the app, during start. Seems to be happening api 12-13 on newer devices like pixel 7.


Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 
'java.lang.String com.snowplowanalytics.snowplow.tracker.SessionState.getSessionId()' 
on a null object reference
       at com.snowplowanalytics.snowplow.internal.session.SessionControllerImpl.getSessionId(SessionControllerImpl.java:72)
    ...
       at com.snowplowanalytics.snowplow.internal.session.Session$1.run(Session.java:254)
       at java.lang.Thread.run(Thread.java:1012)

@matus-tomlein
Copy link
Contributor

Hi @krobert, thanks for reporting. We were able to replicate the error in PR #582 in case session tracking is paused and the tracker tracks an event. Do you by any chance pause session tracking in your app using tracker.session.pause()?

@krobert
Copy link

krobert commented Feb 10, 2023

.pause()

@matus-tomlein I updated my comment with the crash report from crashlytics.
No we are not pausing the session , we receive a crash at app start onSessionUpdate callback, when we are trying to get the session id from the tracker

(
            snowplowUserId = tracker?.session?.userId,
            snowplowSessionId = tracker?.session?.sessionId,
            snowplowSessionIndex = tracker?.session?.sessionIndex
        )

@matus-tomlein
Copy link
Contributor

Thanks @krobert, that's useful!

Just a couple more questions to help us identify the problem since I think yours is slightly different than the one reported previously:

  1. Are you also using remote configuration to configure the tracker?
  2. Is it true that you are calling the above snippet from inside the onSessionUpdate callback? In that case, why not use the SessionState object that is passed to the callback to retrieve the information? We will try to fix also the access from the tracker object, but using the state object passed to the callback can be a quick fix for the exception that you are getting.

@krobert
Copy link

krobert commented Feb 10, 2023

@matus-tomlein

  1. yes, we configure the tracker right after, bit problematin, we have to do our own event caching mechanism
  2. sure we can do that

@matus-tomlein matus-tomlein changed the title Fix crash with null pointer in Session.getSessionContext Fix crash with null pointer when accessing session Feb 15, 2023
@matus-tomlein
Copy link
Contributor

Hi @dss-kenya and @krobert, the bug has been fixed in the 4.1.2 release. I hope it will help, please let us know if not.

@dss-kenya
Copy link
Author

Thank you @matus-tomlein 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants