Skip to content

fix(android): add null check for plugin annotation in getPermissionStates#8400

Open
robingenz wants to merge 1 commit intoionic-team:mainfrom
robingenz:fix/bridge-npe-get-permission-states
Open

fix(android): add null check for plugin annotation in getPermissionStates#8400
robingenz wants to merge 1 commit intoionic-team:mainfrom
robingenz:fix/bridge-npe-get-permission-states

Conversation

@robingenz
Copy link
Contributor

@robingenz robingenz commented Mar 24, 2026

Fixes a NullPointerException crash in Bridge.getPermissionStates() that occurs when getPluginAnnotation() returns null at runtime (see #8399). The fix wraps the permissions iteration in a null check, matching the defensive pattern in Plugin.isPermissionDeclared() (see here).

Closes #8399

…ates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 24, 2026 16:07
@jcesarmobile
Copy link
Member

#8399 is closed due to the lack of reproduction, can you provide a sample app that reproduces the issue?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 null guard around annotation.permissions() iteration in Bridge.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.
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
@robingenz
Copy link
Contributor Author

@zovi-code Can you please provide a Minimal, Reproducible Example? Feel free to use this template.

@zovi-code
Copy link

@robingenz

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.
There I saw it happened on these devices today: Galaxy A15 (Android 16), Galaxy S25+ (Android 16), Galaxy A22 5G (Android 13)

@zovi-code
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: getPermissionStates causes app crash

4 participants