{"record":{"id":"6bf645fe52d4bec0","repo":"MuntashirAkon/AppManager","slug":"package-packagename-not-found","errorCode":null,"errorMessage":"Package ${packageName} not found.","messagePattern":"Package (.+?) not found\\.","errorType":"exception","errorClass":"PackageManager.NameNotFoundException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java","lineNumber":295,"sourceCode":"            info.providers = providers;\n            info.receivers = receivers;\n            info.permissions = permissions;\n        }\n        // Info should never be null here, but it's checked anyway.\n        return Objects.requireNonNull(info);\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    @NonNull\n    public static ApplicationInfo getApplicationInfo(String packageName, int flags, @UserIdInt int userId)\n            throws RemoteException, PackageManager.NameNotFoundException {\n        IPackageManager pm = getPackageManager();\n        ApplicationInfo applicationInfo;\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {\n            applicationInfo = pm.getApplicationInfo(packageName, (long) flags, userId);\n        } else applicationInfo = pm.getApplicationInfo(packageName, flags, userId);\n        if (applicationInfo == null) {\n            throw new PackageManager.NameNotFoundException(\"Package \" + packageName + \" not found.\");\n        }\n        return applicationInfo;\n    }\n\n    @Nullable\n    public static String getInstallerPackageName(@NonNull String packageName, @UserIdInt int userId) {\n        try {\n            InstallSourceInfoCompat installSource = getInstallSourceInfo(packageName, userId);\n            if (installSource.getInstallingPackageName() != null) {\n                return installSource.getInstallingPackageName();\n            }\n            return installSource.getInitiatingPackageName();\n        } catch (RemoteException | SecurityException e) {\n            return null;\n        }\n    }\n\n    @SuppressWarnings(\"deprecation\")","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java#L277-L313","documentation":"PackageManagerCompat.getApplicationInfo calls the hidden IPackageManager.getApplicationInfo, which may return null instead of throwing. When the returned ApplicationInfo is null, this compat method throws PackageManager.NameNotFoundException(\"Package <name> not found.\") to signal the package does not exist for that user.","triggerScenarios":"Calling getApplicationInfo(packageName, flags, userId) where the package is not installed for userId, or the binder call silently returns null (package hidden/removed).","commonSituations":"Querying apps on a different user profile; checking a package right after uninstall; missing package visibility (<queries> filtering) on Android 11+; querying system packages removed in newer OS builds.","solutions":["Wrap the call in try-catch for PackageManager.NameNotFoundException.","Verify installation first via getInstalledPackages for the target user.","Check packageName spelling and the userId argument.","Declare the package in <queries> for visibility if targeting API 30+."],"exampleFix":"// before\nApplicationInfo ai = PackageManagerCompat.getApplicationInfo(pkg, 0, userId);\n// after\nApplicationInfo ai = null;\ntry {\n    ai = PackageManagerCompat.getApplicationInfo(pkg, 0, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    // handle absence\n}","handlingStrategy":"try-catch","validationCode":"boolean installed = getInstalledPackages(userId).stream()\n        .anyMatch(p -> p.packageName.equals(packageName));","typeGuard":null,"tryCatchPattern":"try {\n    ApplicationInfo ai = PackageManagerCompat.getApplicationInfo(pkg, flags, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    ApplicationInfo ai = null;\n}","preventionTips":["Confirm the package exists for the user","Declare <queries> for visibility on API 30+","Validate package name input"],"tags":["android","package-not-found","package-manager"],"backgroundTag":"resource-not-found","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}