MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid queue item.

Error message

Invalid queue item.

What it means

PackageInstallerViewModel.loadPackageInfo() obtains the ApkSource from a non-install-existing queue item via apkQueueItem.getApkSource(); if it returns null the queue item carries no installable source and an IllegalArgumentException ('Invalid queue item.') is thrown.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java:285

    @WorkerThread
    @NonNull
    private PackageParseResult loadPackageInfo(@NonNull ApkQueueItem apkQueueItem) throws Throwable {
        ApkSource apkSource;
        ApkFile apkFile = null;
        try {
            PackageInfo installedPackageInfo = null;
            if (apkQueueItem.isInstallExisting()) {
                String packageName = apkQueueItem.getPackageName();
                if (packageName == null) {
                    throw new IllegalArgumentException("Package name not set for install-existing.");
                }
                installedPackageInfo = loadInstalledPackageInfo(packageName);
                apkSource = ApkSource.getApkSource(installedPackageInfo.applicationInfo);
            } else {
                apkSource = apkQueueItem.getApkSource();
                if (apkSource == null) {
                    throw new IllegalArgumentException("Invalid queue item.");
                }
            }
            apkFile = apkSource.resolve();
            PackageInfo newPackageInfo = loadNewPackageInfo(apkFile);
            String packageName = newPackageInfo.packageName;
            throwIfInterrupted();
            if (installedPackageInfo == null) {
                try {
                    installedPackageInfo = loadInstalledPackageInfo(packageName);
                } catch (PackageManager.NameNotFoundException ignore) {
                }
            }
            throwIfInterrupted();
            String appLabel = mPm.getApplicationLabel(newPackageInfo.applicationInfo).toString();
            Drawable appIcon = mPm.getApplicationIcon(newPackageInfo.applicationInfo);
            int trackerCount = ComponentUtils.getTrackerComponentsCountForPackage(newPackageInfo);
            throwIfInterrupted();
            boolean isSignatureDifferent = installedPackageInfo != null

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Attach a valid ApkSource (APK file/content URI) to the queue item before handing it to the ViewModel
  2. Verify persisted content-URI permissions (takePersistableUriPermission) so the source survives process restarts
  3. Check the APK file still exists at the referenced path/URI and re-prompt the user if it was deleted
  4. Catch IllegalArgumentException and treat it as 'queue item unusable', restarting the install flow from file selection

Example fix

// before
ApkQueueItem item = ApkQueueItem.fromJson(json); // apk_source lost
vm.loadPackageInfo(item); // throws Invalid queue item.
// after
ApkQueueItem item = ApkQueueItem.fromJson(json);
if (!item.isInstallExisting() && item.getApkSource() == null) {
    item.setApkSource(new ApkSource(pickApkUri()));
}
vm.loadPackageInfo(item);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!item.isInstallExisting() && item.getApkSource() == null) {
    throw new IllegalStateException("Queue item carries no APK source; re-pick the APK.");
}

Type guard

boolean isUsableQueueItem(ApkQueueItem item) {
    return item.isInstallExisting()
        ? item.getPackageName() != null
        : item.getApkSource() != null;
}

Try / catch

try {
    vm.loadPackageInfo(item);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Invalid queue item")) {
        restartInstallFromPicker();
    }
}

Prevention

When it happens

Trigger: Passing an ApkQueueItem that is neither install-existing nor holds an APK source — e.g. a default-constructed/empty queue item, one whose source was revoked or failed to deserialize from JSON, or a null source returned by a dead content-URI.

Common situations: Restoring an install session from JSON where apk_source was dropped (e.g. persisted URI permission expired); constructing a queue item and forgetting to attach the APK file/URI; race conditions where the source file was deleted before the ViewModel loaded it.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/fdd7901610c3aa21. Report an issue: GitHub.