Fixes AB#3553684 Fix NPE in PackageHelper.isPackageInstalledAndEnabled - #3051
Merged
Siddhi (siddhijain) merged 2 commits intoMar 24, 2026
Merged
Conversation
|
✅ Work item link check complete. Description contains link AB#3553684 to an Azure Boards work item. |
1 similar comment
|
✅ Work item link check complete. Description contains link AB#3553684 to an Azure Boards work item. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in PackageHelper.isPackageInstalledAndEnabled by ensuring the method exits immediately when PackageManager.getApplicationInfo() throws NameNotFoundException, preventing a null dereference path when checking ApplicationInfo.enabled.
Changes:
- Add an early
return false;inside theNameNotFoundExceptioncatch block inisPackageInstalledAndEnabled.
PackageManager.getApplicationInfo() can return null on some OEM devices instead of throwing NameNotFoundException when a package is not installed. The method then dereferences applicationInfo.enabled, causing: NullPointerException: Attempt to read from field 'boolean android.content.pm.ApplicationInfo.enabled' on a null object reference Add a null check on the ApplicationInfo result and return false immediately if null. Also return false in the NameNotFoundException catch block for completeness. Add unit tests covering: - NameNotFoundException (package not found) - getApplicationInfo returns null (OEM behavior) - Package installed and enabled - Package installed but disabled - USE_ENABLED_SETTING_FOR_PACKAGE_CHECK flight enabled path - IllegalArgumentException fallback in flight-enabled path
Siddhi (siddhijain)
force-pushed
the
fix/package-helper-npe-on-missing-package
branch
from
March 24, 2026 04:03
6f5a451 to
abf2627
Compare
Contributor
|
Siddhi (@siddhijain) I've opened a new pull request, #3052, to work on those changes. Once the pull request is ready, I'll request review from you. |
3 tasks
Cesar Acosta (cacosta33)
approved these changes
Mar 24, 2026
Dome Pongmongkol (rpdome)
approved these changes
Mar 24, 2026
Siddhi (siddhijain)
added a commit
that referenced
this pull request
Mar 24, 2026
#3051) Fixes [AB#3553684](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3553684) When getApplicationInfo throws NameNotFoundException for an uninstalled package, the catch block logged the error but did not return. Execution fell through to code that could dereference applicationInfo.enabled, causing a NullPointerException. Return false immediately in the NameNotFoundException catch block so the method exits cleanly when the queried package is not installed.
Siddhi (siddhijain)
added a commit
that referenced
this pull request
Mar 24, 2026
#3053) …d (#3051) Fixes [AB#3553684](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3553684) When getApplicationInfo throws NameNotFoundException for an uninstalled package, the catch block logged the error but did not return. Execution fell through to code that could dereference applicationInfo.enabled, causing a NullPointerException. Return false immediately in the NameNotFoundException catch block so the method exits cleanly when the queried package is not installed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes AB#3553684 When getApplicationInfo throws NameNotFoundException for an uninstalled package, the catch block logged the error but did not return. Execution fell through to code that could dereference applicationInfo.enabled, causing a NullPointerException.
Return false immediately in the NameNotFoundException catch block so the method exits cleanly when the queried package is not installed.