Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Cannot capture event on android 5 (API 21): NullPointerException 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference #259

Closed
longnguyen2 opened this issue Feb 4, 2020 · 3 comments · Fixed by #260
Assignees
Labels
bug Something isn't working

Comments

@longnguyen2
Copy link

longnguyen2 commented Feb 4, 2020

I run a test event on my project, it worked perfectly on Xiaomi MI 8 (API 28) but there is a problem with Nexus 5X (API 21). The detail log below

E/Sentry: Error while capturing message: test
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference
at io.sentry.android.core.DefaultAndroidEventProcessor.getExternalStorageDep(DefaultAndroidEventProcessor.java:666)
at io.sentry.android.core.DefaultAndroidEventProcessor.getExternalStorageStat(DefaultAndroidEventProcessor.java:629)
at io.sentry.android.core.DefaultAndroidEventProcessor.getDevice(DefaultAndroidEventProcessor.java:348)
at io.sentry.android.core.DefaultAndroidEventProcessor.process(DefaultAndroidEventProcessor.java:129)
at io.sentry.core.SentryClient.captureEvent(SentryClient.java:91)
at io.sentry.core.ISentryClient$-CC.$default$captureException(ISentryClient.java:119)
at io.sentry.core.SentryClient.captureException(SentryClient.java)
at io.sentry.core.Hub.captureException(Hub.java:144)
at io.sentry.core.IHub$-CC.$default$captureException(IHub.java:73)
at io.sentry.core.Hub.captureException(Hub.java)
at io.sentry.core.Sentry.captureException(Sentry.java:205)
at io.gigasource.faceattendance.activities.main.MainActivity.onCreate(MainActivity.java:31)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2642)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

I debugged the project and found out that the root cause was in io.sentry.android.core.DefaultAndroidEventProcessor, the problem is getEternalFilesDirs() might return an array that contains a null object. There was no null checking here so I changed the logic a little bit, at line 666

- if (file.getAbsolutePath().contains(internalStoragePath)) {
+ if (file == null || file.getAbsolutePath().contains(internalStoragePath)) { 

This is just a hot fix, please be considered to fix this bug.

@marandaneto marandaneto added the bug Something isn't working label Feb 4, 2020
@triage-new-issues triage-new-issues bot removed the triage label Feb 4, 2020
@marandaneto
Copy link
Contributor

@longnguyen2 hey, thanks for raising this issue.

I'm gonna have a look.

@marandaneto
Copy link
Contributor

@longnguyen2 we've released a new version with this fix https://github.com/getsentry/sentry-android/releases/tag/2.0.0-rc03 please try it out and let us know if something goes wrong :)

@longnguyen2
Copy link
Author

@marandaneto Thank you for fast response, it works fine now : )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants