expo: [Battery][Android] Standalone app crash - Battery Module - onBatteryStateChange - java.lang.NullPointerException

🐛 Bug Report

Since I’ve upgraded to SDK 34 and 35, I’m getting this crash in production. However, I’m only getting this error on Android. Sentry doesn’t seem to catch anything.

I’m not using the Battery module at all.

I’ve hesitated to post this error since I’m not able to reproduce in development, but it happened to different devices in production. It’s the exact stack trace every single time. So if you have an idea on how to prevent me to have this issue, it would greatly appreciated.

Here’s the full error:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3118)
  at android.app.ActivityThread.-wrap18 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1593)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:163)
  at android.app.ActivityThread.main (ActivityThread.java:6228)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: 
  at expo.modules.battery.BatteryModule.onBatteryStateChange (BatteryModule.java:78)
  at expo.modules.battery.BatteryStateReceiver.onReceive (BatteryStateReceiver.java:16)
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3103)

Environment

Production - Managed App - Standalone Android

Steps to Reproduce

N/A

Expected Behavior

To not crash.

Actual Behavior

Crashes.

Reproducible Demo

N/A

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

This fix has been deployed, so I’m closing this issue 👍

@Gorbus that fix will require you to rebuild your apk