Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
This repository was 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

Description

@longnguyen2

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions