fix(android): add null check for plugin annotation in getPermissionStates#8400
fix(android): add null check for plugin annotation in getPermissionStates#8400robingenz wants to merge 1 commit intoionic-team:mainfrom
Conversation
…ates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
#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.
| if (!key.isEmpty()) { | ||
| PermissionState existingResult = permissionsResults.get(key); | ||
|
|
||
| // auto set permission state to GRANTED if the alias is empty. |
There was a problem hiding this comment.
The inline comment is misleading: this block only executes when key (the alias) is not empty, but the comment says the alias is empty. Please update the comment to match the actual condition (or adjust the condition if the comment reflects intended behavior).
| // auto set permission state to GRANTED if the alias is empty. | |
| // Auto-set permission state to GRANTED for non-empty aliases with no permission strings. |
|
@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. |
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