Tencent/matrix · error · TaskInitException

TaskInitException wrapping e.getMessage()…

Error message

TaskInitException wrapping e.getMessage() (FileNotFoundException)

What it means

While collecting .dex files, MethodCountTask.init() opens each dex file with new RandomAccessFile(file, "rw"). A FileNotFoundException (e.g. the dex file vanished between listing and opening, or is unreadable) is caught and rethrown as TaskInitException wrapping e.getMessage().

Solutions

  1. Ensure no concurrent job deletes/modifies the unzipped APK directory while the task runs (use unique temp dirs per job).
  2. Check filesystem permissions on the dex files (read/write for the running user).
  3. Re-run the unzip step and inspect the wrapped FileNotFoundException message for the exact missing file.

Example fix

// before
// shared temp dir cleaned by another CI job mid-run
String dir = "/tmp/apk-unzipped";
// after
String dir = "/tmp/apk-unzipped-" + UUID.randomUUID(); // isolated per run
Defensive patterns

Strategy: try-catch

Validate before calling

File[] dexFiles = new File(config.getUnzipPath()).listFiles((d, n) -> n.endsWith(".dex"));
if (dexFiles == null || dexFiles.length == 0) {
    throw new IllegalStateException("no readable .dex files in unzip path");
}

Try / catch

try {
    task.init();
} catch (TaskInitException e) {
    Throwable cause = e.getCause(); // FileNotFoundException
    // check the missing file path in cause.getMessage()
}

Prevention

When it happens

Trigger: A file ending in .dex disappears or cannot be opened between inputFile.listFiles() and new RandomAccessFile(file, "rw") during init — e.g. concurrent cleanup, permission denial, or file replaced by a dangling symlink.

Common situations: Build tools cleaning the unzipped output while the checker runs; restricted read/write permissions on the unzipped directory; filesystem race in CI with parallel jobs sharing a temp directory.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

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

        inputFile = new File(inputPath);
        if (!inputFile.exists()) {
            throw new TaskInitException(TAG + "---APK-UNZIP-PATH '" + inputPath + "' is not exist!");
        } else if (!inputFile.isDirectory()) {
            throw new TaskInitException(TAG + "---APK-UNZIP-PATH '" + inputPath + "' is not directory!");
        }
        File[] files = inputFile.listFiles();
        try {
            if (files != null) {
                for (File file : files) {
                    if (file.isFile() && file.getName().endsWith(ApkConstants.DEX_FILE_SUFFIX)) {
                        dexFileNameList.add(file.getName());
                        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
                        dexFileList.add(randomAccessFile);
                    }
                }
            }
        } catch (FileNotFoundException e) {
            throw new TaskInitException(e.getMessage(), e);
        }
        if (params.containsKey(JobConstants.PARAM_GROUP)) {
            if (JobConstants.GROUP_PACKAGE.equals(params.get(JobConstants.PARAM_GROUP))) {
                group = JobConstants.GROUP_PACKAGE;
            } else if (JobConstants.GROUP_CLASS.equals(params.get(JobConstants.PARAM_GROUP))) {
                group = JobConstants.GROUP_CLASS;
            } else {
                Log.e(TAG, "GROUP-BY '" + params.get(JobConstants.PARAM_GROUP) + "' is not correct!");
            }
        }
    }

    private void countDex(RandomAccessFile dexFile) throws IOException {
        classInternalMethod.clear();
        classExternalMethod.clear();
        pkgInternalRefMethod.clear();
        pkgExternalMethod.clear();
        DexData dexData = new DexData(dexFile);

View on GitHub (pinned to 3b8293bd65)