{"record":{"id":"cf5ced55c2a98ac3","repo":"Konloch/bytecode-viewer","slug":"failed-to-create-temp-folder","errorCode":null,"errorMessage":"Failed to create temp folder: ","messagePattern":"Failed to create temp folder: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/util/apk2Jar/Apk2Jar.java","lineNumber":41,"sourceCode":"            return resourceContainerFromApkImpl(inputApk);\n        }\n    }\n\n    protected abstract ResourceContainer resourceContainerFromApkImpl(File inputApk) throws IOException;\n\n    final protected File createTempJarFile()\n    {\n        String name = MiscUtils.getRandomizedName() + \".jar\";\n        return new File(TEMP_DIRECTORY + FS + name);\n    }\n\n    final protected File createTempFolder()\n    {\n        String name = MiscUtils.getRandomizedName();\n        File folder = new File(TEMP_DIRECTORY + FS + name);\n        if (!folder.mkdir())\n        {\n            throw new RuntimeException(\"Failed to create temp folder: \" + folder.getAbsolutePath());\n        }\n        return folder;\n    }\n\n    final protected ResourceContainer createResourceContainerFromJar(File output) throws IOException\n    {\n        return new ResourceContainerImporter(new ResourceContainer(output)).importAsZip().getContainer();\n    }\n\n    final protected ResourceContainer createResourceContainerFromFolder(File output) throws IOException\n    {\n        return new ResourceContainerImporter(new ResourceContainer(output)).importAsFolder().getContainer();\n    }\n\n    /**\n     * Translates dex classes from an apk to a folder\n     *\n     * @param input The apk file","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/util/apk2Jar/Apk2Jar.java#L23-L59","documentation":"Apk2Jar.createTempFolder generates a randomized directory name under TEMP_DIRECTORY and calls File.mkdir(); if mkdir returns false the folder was not created (parent missing, permissions, or an existing file/collision) and it throws RuntimeException with the absolute path. This aborts the APK-to-JAR conversion pipeline before any conversion work starts.","triggerScenarios":"Calling folder()/createTempFolder() when the parent TEMP_DIRECTORY does not exist (mkdir does not create parents), the process lacks write permission there, or the path already exists.","commonSituations":"Read-only or unwritable temp directory configuration; TEMP_DIRECTORY pointing at a path whose parents were never created; disk/name collision with an existing entry; sandboxed environments restricting writes to the configured temp root.","solutions":["Ensure TEMP_DIRECTORY exists (and is writable) before conversion — create it at startup or use mkdirs() instead of mkdir()","Check permissions/ownership of the temp directory for the user running BCV","Point the temp directory at a location you control (e.g. java.io.tmpdir) and verify it is empty/writable","If a name collision occurs, retry with a new randomized name"],"exampleFix":"// before\nFile folder = new File(TEMP_DIRECTORY + FS + name);\nif (!folder.mkdir())\n    throw new RuntimeException(\"Failed to create temp folder: \" + folder.getAbsolutePath());\n// after\nFile folder = new File(TEMP_DIRECTORY + FS + name);\nif (!folder.mkdirs()) // creates missing parents too\n    throw new RuntimeException(\"Failed to create temp folder: \" + folder.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File tmpRoot = new File(Apk2JarTempRoot);\nif (!tmpRoot.isDirectory() && !tmpRoot.mkdirs())\n    throw new IOException(\"Temp root not writable: \" + tmpRoot);\nif (!tmpRoot.canWrite()) throw new IOException(\"No write permission: \" + tmpRoot);","typeGuard":null,"tryCatchPattern":"try {\n    File folder = apk2Jar.folder();\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Failed to create temp folder:\")) {\n        // fix/verify TEMP_DIRECTORY, then retry with a fresh name\n    } else throw e;\n}","preventionTips":["Create the temp root (mkdirs) at application startup and verify canWrite","Point TEMP_DIRECTORY at java.io.tmpdir or another guaranteed-writable path","Check disk space and permissions in the deployment environment","Retry with a new randomized name on rare collisions"],"tags":["java","io","filesystem","temp-directory"],"backgroundTag":"temp-dir-creation-failed","analyzedSha":"31430e0033fa220db566b5ef461256727ff6793b","analyzedAt":"2026-09-05T18:22:22.725Z","contentChangedAt":"2026-09-05T18:22:22.725Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}