{"record":{"id":"c0c0afba0450ce89","repo":"MuntashirAkon/AppManager","slug":"package-name-not-set-for-install-existing","errorCode":null,"errorMessage":"Package name not set for install-existing.","messagePattern":"Package name not set for install-existing\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java","lineNumber":278,"sourceCode":"            if (mSelectedSplits.isEmpty()) {\n                throw new IllegalArgumentException(\"No splits selected.\");\n            }\n            return new ArrayList<>(mSelectedSplits);\n        }\n        return new ArrayList<>(Collections.singletonList(apkFile.getBaseEntry().id));\n    }\n\n    @WorkerThread\n    @NonNull\n    private PackageParseResult loadPackageInfo(@NonNull ApkQueueItem apkQueueItem) throws Throwable {\n        ApkSource apkSource;\n        ApkFile apkFile = null;\n        try {\n            PackageInfo installedPackageInfo = null;\n            if (apkQueueItem.isInstallExisting()) {\n                String packageName = apkQueueItem.getPackageName();\n                if (packageName == null) {\n                    throw new IllegalArgumentException(\"Package name not set for install-existing.\");\n                }\n                installedPackageInfo = loadInstalledPackageInfo(packageName);\n                apkSource = ApkSource.getApkSource(installedPackageInfo.applicationInfo);\n            } else {\n                apkSource = apkQueueItem.getApkSource();\n                if (apkSource == null) {\n                    throw new IllegalArgumentException(\"Invalid queue item.\");\n                }\n            }\n            apkFile = apkSource.resolve();\n            PackageInfo newPackageInfo = loadNewPackageInfo(apkFile);\n            String packageName = newPackageInfo.packageName;\n            throwIfInterrupted();\n            if (installedPackageInfo == null) {\n                try {\n                    installedPackageInfo = loadInstalledPackageInfo(packageName);\n                } catch (PackageManager.NameNotFoundException ignore) {\n                }","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java#L260-L296","documentation":"PackageInstallerViewModel.loadPackageInfo() handles install-existing queue items (reinstalling a package already present on the device). Such an item must carry the target package name; if ApkQueueItem.getPackageName() returns null an IllegalArgumentException is thrown because the installed package info cannot be looked up.","triggerScenarios":"Creating an ApkQueueItem with mInstallExisting=true but never setting mPackageName, then passing it to the installer ViewModel — e.g. JSON deserialization of a replay session missing the package_name field.","commonSituations":"Restoring a queued install-existing replay from JSON where package_name was not persisted; programmatic construction of an install-existing queue item that only set installExisting=true; a caller mistakenly using install-existing mode for a fresh APK install (which needs apkSource, not packageName).","solutions":["Set the package name on the queue item before using install-existing mode","If installing from an APK file instead, set installExisting=false and provide an apkSource","Validate the serialized JSON contains package_name when install_existing is true before constructing the item","Catch IllegalArgumentException around ViewModel setup and surface a configuration error to the caller"],"exampleFix":"// before\nApkQueueItem item = new ApkQueueItem();\nitem.setInstallExisting(true);\nvm.loadPackageInfo(item); // throws\n// after\nApkQueueItem item = new ApkQueueItem();\nitem.setInstallExisting(true);\nitem.setPackageName(\"com.example.app\");\nvm.loadPackageInfo(item);","handlingStrategy":"validation","validationCode":"if (item.isInstallExisting() && (item.getPackageName() == null || item.getPackageName().isEmpty())) {\n    throw new IllegalStateException(\"install-existing queue item requires a package name.\");\n}","typeGuard":"boolean isValidInstallExisting(ApkQueueItem item) {\n    return !item.isInstallExisting()\n        || (item.getPackageName() != null && !item.getPackageName().isEmpty());\n}","tryCatchPattern":"try {\n    vm.loadPackageInfo(item);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Package name\")) {\n        showError(\"Queue item is missing the package name for install-existing replay.\");\n    }\n}","preventionTips":["Always set packageName together with installExisting=true","Persist package_name in session JSON for replays","Use install-existing only for packages already installed; otherwise use an apkSource"],"tags":["android","apk-installer","install-existing","missing-argument"],"backgroundTag":"missing-required-argument","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"}