{"record":{"id":"b85516c9a220f1c2","repo":"java-native-access/jna","slug":"output-directory-not-sucessfully-created-to-comrootdir","errorCode":null,"errorMessage":"Output directory NOT sucessfully created to: <comRootDir>","messagePattern":"Output directory NOT sucessfully created to: <comRootDir>","errorType":"exception","errorClass":"java.io.FileNotFoundException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/tlb/TlbImp.java","lineNumber":156,"sourceCode":"    private void createDir() throws FileNotFoundException {\n        String _outputDir = this.cmdlineArgs.getParam(CMD_ARG_OUTPUT_DIR);\n        String path = \"_jnaCOM_\" + System.currentTimeMillis() + \"\\\\myPackage\\\\\"\n                + this.typeLibUtil.getName().toLowerCase() + \"\\\\\";\n\n        if (_outputDir != null) {\n            this.comRootDir = new File(_outputDir + \"\\\\\" + path);\n        } else {\n            String tmp = System.getProperty(\"java.io.tmpdir\");\n            this.comRootDir = new File(tmp + \"\\\\\" + path);\n        }\n\n        if (this.comRootDir.exists())\n            this.comRootDir.delete();\n\n        if (this.comRootDir.mkdirs()) {\n            logInfo(\"Output directory sucessfully created.\");\n        } else {\n            throw new FileNotFoundException(\n                    \"Output directory NOT sucessfully created to: \"\n                            + this.comRootDir.toString());\n        }\n    }\n\n    private String getPackageName() {\n        return \"myPackage.\" + this.typeLibUtil.getName().toLowerCase();\n    }\n\n    private void writeTextFile(String filename, String str) throws IOException {\n        String file = this.comRootDir + File.separator + filename;\n        BufferedOutputStream bos = new BufferedOutputStream(\n                new FileOutputStream(file));\n        bos.write(str.getBytes());\n        bos.close();\n    }\n\n    private void writeTlbClass(TlbBase tlbBase) throws IOException {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/tlb/TlbImp.java#L138-L174","documentation":"TlbImp's createDir deletes any existing comRootDir and then calls mkdirs(); if directory creation fails (permissions, path in use, disk issues) it throws this FileNotFoundException. It means the type-library-to-Java generator could not prepare its output directory. Note the message text says 'to' but means the output path.","triggerScenarios":"Calling com2java / TlbImp.startCOM2Java when comRootDir cannot be created: parent directory missing or unwritable, an undeletable file occupies the path, or the path is a locked/removable location.","commonSituations":"Running the JNA COM code generator with an output directory under a read-only or non-existent parent; insufficient Windows permissions on the target folder; another process (IDE, explorer) holding a handle on the directory so delete() fails and mkdirs() then fails too.","solutions":["Verify the parent directory of comRootDir exists and is writable before running TlbImp","Close any processes locking the output directory and delete it manually, then re-run","Run the generator with sufficient privileges or choose an output path under a user-writable location","Check the full path string in the message for typos or invalid characters"],"exampleFix":"// before\nTlbImp imp = new TlbImp(\"C:\\\\Program Files\\\\MyLib\\\\my.tlb\", \"C:\\\\Program Files\\\\out\");\n// after\nFile out = new File(\"C:\\\\dev\\\\generated\");\nout.mkdirs(); // ensure parent exists and is writable first\nif (!out.isDirectory()) throw new IllegalStateException(\"output dir not usable: \" + out);\nTlbImp imp = new TlbImp(\"C:\\\\dev\\\\libs\\\\my.tlb\", out.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File dir = new File(outPath);\nif (dir.exists() && !dir.delete()) throw new IllegalStateException(\"cannot delete old dir \" + dir);\nif (!dir.mkdirs() && !dir.isDirectory()) throw new IllegalStateException(\"cannot create \" + dir);","typeGuard":null,"tryCatchPattern":"try { imp.startCOM2Java(); } catch (FileNotFoundException e) { log.error(\"output dir unusable: \" + e.getMessage()); }","preventionTips":["Check parent directory writability before invoking TlbImp","Avoid output paths other processes may lock","Use user-writable paths, not Program Files"],"tags":["java","com","file-io","codegen","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}