{"record":{"id":"29943d2a243e7b97","repo":"Tencent/matrix","slug":"taskinitexception-wrapping-e-getmessage-filenot","errorCode":null,"errorMessage":"TaskInitException wrapping e.getMessage() (FileNotFoundException)","messagePattern":"TaskInitException wrapping e\\.getMessage\\(\\) \\(FileNotFoundException\\)","errorType":"exception","errorClass":"TaskInitException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/MethodCountTask.java","lineNumber":106,"sourceCode":"        inputFile = new File(inputPath);\n        if (!inputFile.exists()) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH '\" + inputPath + \"' is not exist!\");\n        } else if (!inputFile.isDirectory()) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH '\" + inputPath + \"' is not directory!\");\n        }\n        File[] files = inputFile.listFiles();\n        try {\n            if (files != null) {\n                for (File file : files) {\n                    if (file.isFile() && file.getName().endsWith(ApkConstants.DEX_FILE_SUFFIX)) {\n                        dexFileNameList.add(file.getName());\n                        RandomAccessFile randomAccessFile = new RandomAccessFile(file, \"rw\");\n                        dexFileList.add(randomAccessFile);\n                    }\n                }\n            }\n        } catch (FileNotFoundException e) {\n            throw new TaskInitException(e.getMessage(), e);\n        }\n        if (params.containsKey(JobConstants.PARAM_GROUP)) {\n            if (JobConstants.GROUP_PACKAGE.equals(params.get(JobConstants.PARAM_GROUP))) {\n                group = JobConstants.GROUP_PACKAGE;\n            } else if (JobConstants.GROUP_CLASS.equals(params.get(JobConstants.PARAM_GROUP))) {\n                group = JobConstants.GROUP_CLASS;\n            } else {\n                Log.e(TAG, \"GROUP-BY '\" + params.get(JobConstants.PARAM_GROUP) + \"' is not correct!\");\n            }\n        }\n    }\n\n    private void countDex(RandomAccessFile dexFile) throws IOException {\n        classInternalMethod.clear();\n        classExternalMethod.clear();\n        pkgInternalRefMethod.clear();\n        pkgExternalMethod.clear();\n        DexData dexData = new DexData(dexFile);","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/MethodCountTask.java#L88-L124","documentation":"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().","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure no concurrent job deletes/modifies the unzipped APK directory while the task runs (use unique temp dirs per job).","Check filesystem permissions on the dex files (read/write for the running user).","Re-run the unzip step and inspect the wrapped FileNotFoundException message for the exact missing file."],"exampleFix":"// before\n// shared temp dir cleaned by another CI job mid-run\nString dir = \"/tmp/apk-unzipped\";\n// after\nString dir = \"/tmp/apk-unzipped-\" + UUID.randomUUID(); // isolated per run","handlingStrategy":"try-catch","validationCode":"File[] dexFiles = new File(config.getUnzipPath()).listFiles((d, n) -> n.endsWith(\".dex\"));\nif (dexFiles == null || dexFiles.length == 0) {\n    throw new IllegalStateException(\"no readable .dex files in unzip path\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    task.init();\n} catch (TaskInitException e) {\n    Throwable cause = e.getCause(); // FileNotFoundException\n    // check the missing file path in cause.getMessage()\n}","preventionTips":["Give each checker run its own unzipped-output directory to avoid races.","Verify read/write permissions on the unzipped output.","Inspect getCause() to identify the exact file that vanished."],"tags":["io","file-not-found","apk-canary"],"backgroundTag":"file-not-found","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}