Tencent/matrix · error · TaskExecuteException

---File '<outputFile.getAbsolutePath()>' is already exists!

Error message

---File '<outputFile.getAbsolutePath()>' is already exists!

What it means

During UnzipTask.call() execution, if the configured unzip output path resolves to an existing regular file (not a directory) the task cannot create its output directory there and throws TaskExecuteException. Directories are deleted and recreated; plain files are treated as a conflict.

Solutions

  1. Delete the file at the configured unzip path, or choose a different output directory.
  2. Ensure unzipPath denotes a directory location (ending with a directory name not used by any file).
  3. Add pre-run cleanup in your build script that removes the unzip output location.

Example fix

// before
config.setUnzipPath("build/outputs/apk/release/app-release.apk"); // a file
// after
config.setUnzipPath("build/matrix/unzip-output");
Defensive patterns

Strategy: validation

Validate before calling

File out = new File(config.getUnzipPath());
if (out.isFile()) {
    throw new IllegalArgumentException("unzipPath is an existing file: " + out.getAbsolutePath());
}

Try / catch

try {
    task.call();
} catch (TaskExecuteException e) {
    if (e.getMessage().contains("is already exists")) {
        new File(config.getUnzipPath()).delete();
        task.call(); // retry after removing the conflicting file
    } else throw e;
}

Prevention

When it happens

Trigger: config.getUnzipPath() points to an existing file (e.g. a zip archive or a leftover file) instead of a directory.

Common situations: Pointing unzip output at the APK file itself or at some artifact file; a previous run left a file at that path; misconfigured output path colliding with an existing build artifact.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/92587e89ad66baa1. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/UnzipTask.java:246

                zipInputStream.close();
            }
            if (bufferedOutput != null) {
                bufferedOutput.close();
            }
        }
        return outEntryName;
    }

    @Override
    public TaskResult call() throws TaskExecuteException {
        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(inputFile);
            if (outputFile.isDirectory() && outputFile.exists()) {
                Log.i(TAG, "%s exists, delete it.", outputFile.getAbsolutePath());
                FileUtils.deleteDirectory(outputFile);
            } else if (outputFile.isFile()) {
                throw new TaskExecuteException(TAG + "---File '" + outputFile.getAbsolutePath() + "' is already exists!");
            }
            TaskResult taskResult = TaskResultFactory.factory(getType(), TASK_RESULT_TYPE_JSON, config);
            if (taskResult == null) {
                return null;
            }
            long startTime = System.currentTimeMillis();
            if (!outputFile.mkdir()) {
                throw new TaskExecuteException(TAG + "---Create directory '" + outputFile.getAbsolutePath() + "' failed!");
            }

            ((TaskJsonResult) taskResult).add("total-size", inputFile.length());

            readMappingTxtFile();
            config.setProguardClassMap(proguardClassMap);
            ResguardUtil.readResMappingTxtFile(resMappingTxt, resDirMap, resguardMap);
            config.setResguardMap(resguardMap);

            Enumeration entries = zipFile.entries();

View on GitHub (pinned to 3b8293bd65)