MuntashirAkon/AppManager · error · IllegalArgumentException

Data directory cannot be empty.

Error message

Data directory cannot be empty.

What it means

getDataDirectories collects the data directories of an application for backup. It documents that data directories must be readable and non-empty, so if ApplicationInfo.dataDir is null the method immediately throws IllegalArgumentException because no backup of app data is possible without a data directory path.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupUtils.java:331

        // Lib dirs has to be ignored by default
        List<String> excludeDirs = new ArrayList<>(Arrays.asList(BackupManager.LIB_DIR));
        if (includeCache) {
            excludeDirs.addAll(Arrays.asList(BackupManager.CACHE_DIRS));
        }
        if (others != null) {
            excludeDirs.addAll(Arrays.asList(others));
        }
        return excludeDirs.toArray(new String[0]);
    }

    @SuppressLint("SdCardPath")
    @NonNull
    static List<String> getDataDirectories(@NonNull ApplicationInfo applicationInfo, boolean loadInternal,
                                       boolean loadExternal, boolean loadMediaObb) {
        // Data directories *must* be readable and non-empty
        ArrayList<String> dataDirs = new ArrayList<>();
        if (applicationInfo.dataDir == null) {
            throw new IllegalArgumentException("Data directory cannot be empty.");
        }
        int userId = UserHandleHidden.getUserId(applicationInfo.uid);
        if (loadInternal) {
            String dataDir = applicationInfo.dataDir;
            if (dataDir.startsWith("/data/data/")) {
                dataDir = Utils.replaceOnce(dataDir, "/data/data/", String.format(Locale.ROOT, "/data/user/%d/", userId));
            }
            dataDirs.add(dataDir);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && applicationInfo.deviceProtectedDataDir != null) {
                // /data/user_de/{userId}
                dataDirs.add(applicationInfo.deviceProtectedDataDir);
            }
        }
        // External directories could be /sdcard, /storage/sdcard, /storage/emulated/{userId}
        OsEnvironment.UserEnvironment ue = OsEnvironment.getUserEnvironment(userId);
        if (loadExternal) {
            Path[] externalFiles = ue.buildExternalStorageAppDataDirs(applicationInfo.packageName);
            for (Path externalFile : externalFiles) {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Check applicationInfo.dataDir != null before calling getDataDirectories and skip/flag that app for backup.
  2. Re-resolve ApplicationInfo for the correct user via PackageManager with the matching user handle.
  3. Verify the package is actually installed and enabled for the target user before scheduling backup.

Example fix

// before
List<String> dirs = BackupUtils.getDataDirectories(appInfo, true, true, true);
// after
if (appInfo.dataDir == null) {
    throw new BackupException(appInfo.packageName + " is not installed for this user; skipping backup");
}
List<String> dirs = BackupUtils.getDataDirectories(appInfo, true, true, true);
Defensive patterns

Strategy: validation

Validate before calling

if (applicationInfo == null || applicationInfo.dataDir == null) {
    // skip or re-resolve ApplicationInfo for the correct user
    return Collections.emptyList();
}

Type guard

boolean isBackable(ApplicationInfo info) { return info != null && info.dataDir != null; }

Prevention

When it happens

Trigger: Calling getDataDirectories with an ApplicationInfo whose dataDir field is null — typically for system/shared apps or applications not installed for the queried user.

Common situations: Backing up an app whose ApplicationInfo was obtained for a user where it is not installed, or from a stale/removed package record; also happens with disabled or hidden system packages on some OEM ROMs.

Related errors


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