Skip to content

fix(android): ignore permission results without a saved call - #121

Open
Mobiletainment wants to merge 1 commit into
ionic-team:mainfrom
Mobiletainment:fix/android-null-permission-call
Open

Mobiletainment wants to merge 1 commit into
ionic-team:mainfrom
Mobiletainment:fix/android-null-permission-call

Conversation

@Mobiletainment

Copy link
Copy Markdown

Description

completeCurrentPosition and completeWatchPosition now accept a nullable PluginCall and return early when it is null.

Context

Closes #87.

Capacitor calls @PermissionCallback methods from Plugin#triggerPermissionCallback with bridge.getPermissionCall(...), which can return null and is passed on without a check. The saved call only lives in memory, so one way to lose it is Android recreating the app process while the location permission dialog is open. The reports in #87 come from Crashlytics, so the exact trigger is not confirmed. Either way, the plugin passed the null on to startWatch / getPosition, which matches the reported crash:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.getcapacitor.PluginCall.getCallbackId()' on a null object reference
at com.capacitorjs.plugins.geolocation.GeolocationPlugin$startWatch$1.invokeSuspend

There is no call left to resolve or reject, so returning is the only option. The JavaScript side that made the request is already gone at that point.

I have carried an equivalent guard in a local patch for my Android apps since May 2026.

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Platforms affected

  • Android
  • iOS
  • JavaScript

Tests

  • Added PermissionCallbackTest, a JVM unit test that checks that both methods carry @PermissionCallback and invokes them by reflection with a null call, the way Capacitor does. Without the fix both tests fail with a NullPointerException. With the fix they pass.
  • cd android && ./gradlew clean build test passes (JDK 21).
  • npm run build, npm run eslint and npm run prettier -- --check pass.
  • The commit also applies cleanly to next (9.0.0-next.5), where the callbacks are unchanged.

🤖 Generated with Claude Code

Capacitor's Plugin#triggerPermissionCallback passes the call it saved before
the permission request. That call only lives in memory and can be null, for
example if Android recreated the app process while the location permission
dialog was open. The callbacks passed null on to getPosition/startWatch,
which matches the NullPointerException on PluginCall.getCallbackId()
reported in ionic-team#87.

Accept a nullable call in both permission callbacks and return early.

Closes ionic-team#87

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant