{"record":{"id":"92ae05e1307cf27b","repo":"quarkusio/quarkus","slug":"failed-to-create-jbang-download-directory-dir","errorCode":null,"errorMessage":"Failed to create JBang download directory: ${dir}","messagePattern":"Failed to create JBang download directory: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/JBangSupport.java","lineNumber":188,"sourceCode":"    }\n\n    private Path getInstallationDir() {\n        Path currentDir = workingDirectory;\n        Optional<Path> dir = Optional.ofNullable(currentDir).filter(EXISTS_AND_WRITABLE);\n        while (dir.map(Path::getParent).filter(EXISTS_AND_WRITABLE).isPresent()) {\n            dir = dir.map(Path::getParent);\n        }\n        return dir.map(d -> d.resolve(\".jbang\"))\n                .orElseThrow(() -> new IllegalStateException(\"Failed to determine .jbang directory\"));\n    }\n\n    private void installJBang() {\n        try {\n            String uri = \"https://www.jbang.dev/releases/latest/download/jbang.zip\";\n            Path downloadDir = Files.createTempDirectory(\"jbang-download-\");\n\n            if (!downloadDir.toFile().exists() && !downloadDir.toFile().mkdirs()) {\n                throw new IOException(\"Failed to create JBang download directory: \" + downloadDir.toAbsolutePath().toString());\n            }\n\n            Path downloadFile = downloadDir.resolve(\"jbang.zip\");\n            Path installDir = getInstallationDir();\n            if (!installDir.toFile().exists() && !installDir.toFile().mkdirs()) {\n                throw new IOException(\"Failed to create JBang install directory: \" + installDir.toAbsolutePath().toString());\n            }\n            HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build();\n            HttpRequest request = HttpRequest.newBuilder()\n                    .uri(new URI(uri))\n                    .GET()\n                    .build();\n            HttpResponse<Path> response = client.send(request, BodyHandlers.ofFile(downloadFile));\n            ZipUtils.unzip(downloadFile, downloadDir);\n            ZipUtils.copyFromZip(downloadDir.resolve(\"jbang\"), installDir);\n        } catch (Exception e) {\n            throw new RuntimeException(e);\n        }","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/JBangSupport.java#L170-L206","documentation":"JBangSupport.installJBang throws IOException 'Failed to create JBang download directory: <absolute path>' when the temporary download directory used to unzip JBang cannot be created. Normally Files.createTempDirectory succeeds, so this fires only in a race or hostile environment where the dir disappears or cannot be materialized. It propagates wrapped as a runtime exception from doEnsureJBangIsInstalledInternal.","triggerScenarios":"Calling ensureJBangIsInstalled (leading to installJBang) when downloadDir.toFile() does not exist and File.mkdirs() fails — e.g. temp dir deleted concurrently or permissions on java.io.tmpdir.","commonSituations":"Read-only or full /tmp; TMPDIR pointing to an unwritable location; security policies (sandboxed CI) blocking temp directory creation; cleanup daemon deleting temp dirs mid-run.","solutions":["Verify java.io.tmpdir/TMPDIR is writable (touch a file there) and has free space","Set -Djava.io.tmpdir to a writable directory and retry the command","Re-run the installation — temp directory races are often transient"],"exampleFix":"// before\nexport TMPDIR=/nonexistent-quarkus-tmp\n\n// after\nexport TMPDIR=$HOME/.tmp && mkdir -p $TMPDIR","handlingStrategy":"try-catch","validationCode":"Path tmp = Paths.get(System.getProperty(\"java.io.tmpdir\"));\nif (!Files.isDirectory(tmp) || !Files.isWritable(tmp))\n    throw new IllegalStateException(\"Temp dir not writable: \" + tmp);","typeGuard":null,"tryCatchPattern":"try {\n    jbangSupport.ensureJBangIsInstalled();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Failed to create JBang download directory\")) {\n        // point TMPDIR/-Djava.io.tmpdir at a writable dir and retry\n    } else throw e;\n}","preventionTips":["Keep java.io.tmpdir writable and with free space in CI and dev environments","Avoid aggressive tmp-cleanup daemons during long-running installs","Preinstall JBang yourself so installJBang is never triggered"],"tags":["filesystem","jbang","temp-directory"],"backgroundTag":"file-create-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}