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

bug + PR: Camera Plugin crashes app on restoreState (NullPointerException) #5290

Closed
hermitdemschoenenleben opened this issue Dec 2, 2021 · 1 comment Β· Fixed by #5289
Closed

Comments

@hermitdemschoenenleben
Copy link
Contributor

Bug Report

This is essentially the same bug as ionic-team/capacitor-plugins#658 , this time with a pull request that fixes the issue: #5289

Capacitor Version

❯ npx cap doctor                                                     
πŸ’Š   Capacitor Doctor  πŸ’Š 

Latest Dependencies:

  @capacitor/cli: 3.3.2
  @capacitor/core: 3.3.2
  @capacitor/android: 3.3.2
  @capacitor/ios: 3.3.2

Installed Dependencies:

  @capacitor/cli: 3.3.2
  @capacitor/core: 3.3.2
  @capacitor/android: 3.3.2
  @capacitor/ios: 3.3.2

Platform(s)

android

Current Behavior

Roughly 5 % of our android users that try to pick an image (or multiple images) see this crash:

java.lang.NullPointerException: 
  at com.capacitorjs.plugins.camera.CameraPlugin.restoreState (CameraPlugin.java:721)
  at com.getcapacitor.Bridge.restoreInstanceState (Bridge.java:811)
  at com.getcapacitor.Bridge$Builder.create (Bridge.java:1286)
  at com.getcapacitor.BridgeActivity.load (BridgeActivity.java:72)
  at com.getcapacitor.BridgeActivity.onStart (BridgeActivity.java:110)
  at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1435)
  at android.app.Activity.performStart (Activity.java:8231)
  at android.app.ActivityThread.handleStartActivity (ActivityThread.java:3861)
  at android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:221)
  at android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:201)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:173)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2325)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:246)
  at android.app.ActivityThread.main (ActivityThread.java:8633)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)

Expected Behavior

App should not crash.

Code Reproduction

I was not able to reproduce the bug, but reading the code it appears evident that there is a problem:

  • When capacitor tries to restoreInstanceState() it fetches Bundle bundleData = savedInstanceState.getBundle(BUNDLE_PLUGIN_CALL_BUNDLE_KEY);
  • It does not perform a null check and passes it to the camera plugin's restoreState which uses it without a null check
  • Looking at the camera plugin's saveInstanceState (and super.saveInstanceState) it is clear that sometimes bundleData is going to be null, leading to the crash
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 10, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants