Repository navigation
fix(android): add null checks for plugin annotation when retrieving permissions - #8400
Conversation
…ates Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
#8399 is closed due to the lack of reproduction, can you provide a sample app that reproduces the issue? |
There was a problem hiding this comment.
Pull request overview
Prevents an Android crash in Bridge.getPermissionStates() when a plugin’s @CapacitorPlugin annotation metadata is missing at runtime (reported in #8399), by guarding the permissions iteration with a null check.
Changes:
- Add
nullguard aroundannotation.permissions()iteration inBridge.getPermissionStates(). - Return an empty permission-state map when plugin annotation metadata is unavailable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@zovi-code Can you please provide a Minimal, Reproducible Example? Feel free to use this template. |
|
I will create it now but it is important to add that it does not happen always but sometimes. I have 5 Android devices and I can not reproduce it but in Crashlytics there are reports where exactly this causes crash. |
|
@robingenz here it is https://github.com/ferhadm/capcrash Note: My original app is in NextJS so I wanted to use same exact code that I use there and here is minimum version. |
|
@robingenz I want to inform you that in the meantime, I found a device that can reproduce this issue. I installed a patch and pushed it to production. This same device reinstalled the app and crash was not happening anymore. That proves that you managed to fix this issue. Thank you very much!
|
This comment was marked as abuse.
This comment was marked as abuse.
|
Hello team, Thanks for working on a fix for this. Adding this comment here, since the original issue is now limited to collaborators. My team hit this same bug in production on There's a second unguarded path with the same (or related) root cause in private String[] getPermissionStringsForAliases(@NonNull String[] aliases) {
CapacitorPlugin annotation = handle.getPluginAnnotation();
HashSet<String> perms = new HashSet<>();
for (Permission perm : annotation.permissions()) { // NPE when annotation is nullWe applied the same fix, wrapping the for loop in I will note that with both null guards in place the crash is resolved, but local notifications are silently non-functional for affected users. |
|
We hit the same release-only permission metadata problem on Symptom 1 (original)NPE in Symptom 2 (after null-guard patch only)No NPE, but camera still fails:
Root cause (our finding)Shipped consumer rules in But What fixed it for usApp-level After this, Not sure if your issue may have a similar root cause. |
…ar has nothing to show, log widget update failures (#79) The push-notification-enable crash was never actually fixed by the earlier proguard/double-permission-request changes — got the real Crashlytics stack trace this time, and it's an open, unfixed upstream Capacitor bug (ionic-team/capacitor#8400): Bridge.getPermissionStates() throws a real native NullPointerException when PushNotifications.requestPermissions() is called, crashing the whole app before any JS try/catch ever gets a chance to run. Confirmed present on both 1.0.8 and 1.0.9, unrelated to anything shipped so far this session. Added NotificationPermissionPlugin, a small native plugin that requests POST_NOTIFICATIONS directly with Android's own permission API instead of going through Capacitor's broken helper. enableNativeNotifications() now calls it first, falling back to the old Capacitor call only if that plugin is somehow unavailable. Also: html/body never had an explicit background-color, so the safe-area strip under Android's edge-to-edge status bar could fall back to the WebView's own default canvas color instead of the app's actual background — set explicitly now. And the widget's update call no longer swallows errors silently, so a real failure is visible in the WebView console/logcat instead of just disappearing. Co-authored-by: SableWolphen <[email protected]>
…ates (#92) Sync of upstream ionic-team#8400.
|
This fix is available as a quick patch through Patch ID: plugins: {
CapacitorPatch: {
patches: ['upstream-pr-8400-android'],
strict: true,
},
}Run |
OS-pedrogustavobilro
left a comment
There was a problem hiding this comment.
Hey @robingenz, thanks for opening the PR, sorry for the time it took to look into it.
I took the liberty of making an additional null-check on Plugin.java that was mentined in a comment.
I was able to reproduce this on https://github.com/ferhadm/capcrash + turning on minification, which may not be the exact same reproduction conditions, but with this PR the crash no longer occured.
While there could be future work we'll do to address other issues with proguard and app obfuscation (especially with upcoming Play Store changes for early 2027), this PR still makes sense, so we'll be merging it, and it should go on the next Capacitor release.
Thanks for the contribution!
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.5.2](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#852-2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6))
##### [v8.6.0](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#860-2026-10-28) ##### Bug Fixes - **android:** keep callbacks on non-public base classes from R8 ([02e43f8](ionic-team/capacitor@02e43f8)) - **android:** keep plugin annotation types from R8 full mode ([#8646](ionic-team/capacitor#8646)) ([9dc5aeb](ionic-team/capacitor@9dc5aeb)) - **cli:** bump xcode to ^4.0.0 to drop vulnerable uuid\@7 ([#8674](ionic-team/capacitor#8674)) ([463225f](ionic-team/capacitor@463225f)) - **cli:** redact sensitive values from telemetry payloads ([#8665](ionic-team/capacitor#8665)) ([d19f1ea](ionic-team/capacitor@d19f1ea)) - **cli:** report npm 12 blocked install scripts in doctor and migrate ([#8655](ionic-team/capacitor#8655)) ([841017a](ionic-team/capacitor@841017a)) ##### Features - **android:** recognize [@capacitor-community/ssl-pinning](https://github.com/capacitor-community/ssl-pinning) for cert pinning ([#8669](ionic-team/capacitor#8669)) ([19d2a40](ionic-team/capacitor@19d2a40)) - **cli:** recognize [@capacitor-community/ssl-pinning](https://github.com/capacitor-community/ssl-pinning) for auto cert copy ([#8666](ionic-team/capacitor#8666)) ([50a3c51](ionic-team/capacitor@50a3c51)) ##### Reverts - Revert "chore(ios): add `App/CapApp-SPM/Package.resolved` to `.gitignore` ([#8649](ionic-team/capacitor#8649))" ([175c933](ionic-team/capacitor@175c933)), closes [#8649](ionic-team/capacitor#8649) #### [8.5.3](ionic-team/capacitor@8.5.2...8.5.3) (2026-10-07) ##### Bug Fixes - **cli:** change Cordova AppDelegate.h imports for SPM ([#8618](ionic-team/capacitor#8618)) ([145560e](ionic-team/capacitor@145560e)) #### [8.5.2](ionic-team/capacitor@8.5.1...8.5.2) (2026-09-11) ##### Bug Fixes - **android:** add null checks for plugin annotation when retrieving permissions ([#8400](ionic-team/capacitor#8400)) ([035b16a](ionic-team/capacitor@035b16a)) - **ios:** do not forward scene lifecycle events to the page before it has loaded ([#8595](ionic-team/capacitor#8595)) ([c567328](ionic-team/capacitor@c567328)) - resolve issues with safe area / systembars plugin ([#8535](ionic-team/capacitor#8535)) ([e37d9c6](ionic-team/capacitor@e37d9c6)) #### [8.5.1](ionic-team/capacitor@8.5.0...8.5.1) (2026-08-31) ##### Bug Fixes - block navigation to the internal HTTP proxy path ([ee586ae](ionic-team/capacitor@ee586ae)) - **cli:** use POSIX paths in CapApp-SPM Package.swift ([#8549](ionic-team/capacitor#8549)) ([5e5bb3b](ionic-team/capacitor@5e5bb3b)) - **core:** prevent removeListener from removing wrong listener ([#8271](ionic-team/capacitor#8271)) ([5ac4dd6](ionic-team/capacitor@5ac4dd6)) ##### [v8.5.3](https://github.com/ionic-team/capacitor/blob/HEAD/CHANGELOG.md#853-2026-10-07) ##### Bug Fixes - **cli:** change Cordova AppDelegate.h imports for SPM ([#8618](ionic-team/capacitor#8618)) ([145560e](ionic-team/capacitor@145560e))
* Release 8.3.2 * fix(cli): copy plugin files in CocoaPods projects (ionic-team#8467) * Release 8.3.3 * chore(cli): update telemetry endpoint (ionic-team#8464) * Release 8.3.4 * chore: format java code (ionic-team#8475) * chore: format java code (ionic-team#8477) * feat: add method getDouble to plugin config (ionic-team#7638) Co-authored-by: jcesarmobile <[email protected]> * fix(SystemBars): make `safe-area-inset-x` available on API <= 34 (ionic-team#8424) * feat(cli): add experimental packageOptions (ionic-team#8471) * feat(cli): capture ios_package_manager in telemetry (ionic-team#8482) * fix(cli): revert live reload config on failure (ionic-team#8485) * chore: fix typo in declarations.ts (ionic-team#8488) * fix(SystemBars): respect `insetsHandling` disable (ionic-team#8481) * fix(android): show only the requested system bar (ionic-team#8480) Co-authored-by: Joey Pender <[email protected]> Co-authored-by: Pedro Bilro <[email protected]> Co-authored-by: Mark Anderson <[email protected]> * chore: Decrease timeout for CI jobs from 60 to 30 minutes (ionic-team#8476) Co-authored-by: jcesarmobile <[email protected]> * Release 8.4.0 * fix(cli): patch Capacitor SPM dependency version in plugins (ionic-team#8492) Co-authored-by: Mark Anderson <[email protected]> * fix(cli): make SPM dependency patch work on prereleases (ionic-team#8508) * Release 8.4.1 * chore: run `npm run fmt` to fix lint errors (ionic-team#8516) * fix(android): explicitly grant URI permissions for image capture intent (ionic-team#8526) * Release 8.4.2 * chore(android): fix lint issues (ionic-team#8542) * fix(cli): support TypeScript 7 when loading capacitor.config.ts (ionic-team#8534) * feat(ios): UIScene Support (ionic-team#8536) * feat(cli): add migrator functionality for adopting UIScene (ionic-team#8544) * Release 8.5.0 * fix(cli): use POSIX paths in CapApp-SPM Package.swift (ionic-team#8549) Co-authored-by: Cursor <[email protected]> * fix(core): prevent removeListener from removing wrong listener (ionic-team#8271) Co-authored-by: Eric Horodyski <[email protected]> * fix: block navigation to the internal HTTP proxy path * Release 8.5.1 * fix(ios): do not forward scene lifecycle events to the page before it has loaded (ionic-team#8595) * fix(android): add null checks for plugin annotation when retrieving permissions (ionic-team#8400) Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Pedro Bilro <[email protected]> * fix: resolve issues with safe area / systembars plugin (ionic-team#8535) * Release 8.5.2 * fix(cli): change Cordova AppDelegate.h imports for SPM (ionic-team#8618) * chore: add .build/ folder to gitignore (ionic-team#8640) * Release 8.5.3 * chore(ios): add `App/CapApp-SPM/Package.resolved` to `.gitignore` (ionic-team#8649) * Revert "chore(ios): add `App/CapApp-SPM/Package.resolved` to `.gitignore` (ionic-team#8649)" This reverts commit eb06606. * fix(android): keep plugin annotation types from R8 full mode (ionic-team#8646) * docs: minor correction (ionic-team#8660) * fix(cli): report npm 12 blocked install scripts in doctor and migrate (ionic-team#8655) * feat(cli): recognize @capacitor-community/ssl-pinning for auto cert copy (ionic-team#8666) * feat(android): recognize @capacitor-community/ssl-pinning for cert pinning (ionic-team#8669) * fix(android): keep callbacks on non-public base classes from R8 * fix(cli): redact sensitive values from telemetry payloads (ionic-team#8665) * fix(cli): bump xcode to ^4.0.0 to drop vulnerable uuid@7 (ionic-team#8674) Co-authored-by: Mark Anderson <[email protected]> * chore: add Backstage catalog-info.yaml Adds a catalog-info.yaml so Capacitor and its core, cli, android, and ios packages show up in OutSystems' Backstage software catalog. * Release 8.6.0 * fix(android): skip lifecycle events when the Capacitor bridge is not present (ionic-team#8683) * fix(ios): read CapacitorCookies/CapacitorHttp isEnabled from injected global (ionic-team#8688) * style: format files after merging plus --------- Co-authored-by: Github Workflow (on behalf of markemer) <users.noreply.github.com> Co-authored-by: jcesarmobile <[email protected]> Co-authored-by: Alex J. <[email protected]> Co-authored-by: Robin Genz <[email protected]> Co-authored-by: Joey Pender <[email protected]> Co-authored-by: Minh Vu <[email protected]> Co-authored-by: Pedro Bilro <[email protected]> Co-authored-by: Mark Anderson <[email protected]> Co-authored-by: Conor Brady <[email protected]> Co-authored-by: Omri Willheim <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Manik Tyagi <[email protected]> Co-authored-by: Eric Horodyski <[email protected]> Co-authored-by: Chace Daniels <[email protected]> Co-authored-by: Gábor Tóth <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Tafel <[email protected]> Co-authored-by: Piotr <[email protected]> Co-authored-by: DravenLee <[email protected]> Co-authored-by: OS-ruimoreiramendes <[email protected]> Co-authored-by: Mauro Kinjuk <[email protected]> Co-authored-by: Eric Horodyski <[email protected]> Co-authored-by: Tori Chan <[email protected]>


Fixes a
NullPointerExceptioncrash inBridge.getPermissionStates()that occurs whengetPluginAnnotation()returnsnullat runtime (see #8399). The fix wraps the permissions iteration in a null check, matching the defensive pattern inPlugin.isPermissionDeclared()(see here).Closes #8399