{"record":{"id":"fd07ed66c885ade1","repo":"Konloch/bytecode-viewer","slug":"codebase-is-not-a-directory","errorCode":null,"errorMessage":"'${codebase}' is not a directory","messagePattern":"'(.+?)' is not a directory","errorType":"exception","errorClass":"LoaderException","httpStatus":null,"severity":"error","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java","lineNumber":43,"sourceCode":"import java.io.BufferedInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\n\npublic class DirectoryLoader implements Loader\n{\n    protected String codebase;\n    protected long lastModified;\n    protected boolean isFile;\n\n    public DirectoryLoader(File file) throws LoaderException\n    {\n        this.codebase = file.getAbsolutePath();\n        this.lastModified = file.lastModified();\n        this.isFile = file.isFile();\n\n        if (!(file.exists() && file.isDirectory()))\n            throw new LoaderException(\"'\" + codebase + \"' is not a directory\");\n    }\n\n    @Override\n    public byte[] load(String internalPath) throws LoaderException\n    {\n        if (!internalPath.endsWith(\".class\"))\n            internalPath = internalPath + \".class\";\n\n        File file = new File(this.codebase, internalPath);\n\n        try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis))\n        {\n            return IOUtils.toByteArray(bis);\n        }\n        catch (IOException e)\n        {\n            throw new LoaderException(\"'\" + file.getAbsolutePath() + \"'  not found.\");\n        }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java#L25-L61","documentation":"DirectoryLoader's constructor throws LoaderException when the given File does not exist or is not a directory. DirectoryLoader only serves .class files from a directory codebase, so constructing it with a single file or a non-existent path is invalid — use the file/jar loader instead.","triggerScenarios":"new DirectoryLoader(new File(\"path/to/MyClass.class\")) — passing a class file instead of a directory; path misspelled or directory deleted/moved at runtime; on network mounts, a directory that failed to mount; case-sensitivity mismatches on Linux paths that existed on the dev's Windows machine.","commonSituations":"Config pointing at a jar's inner path instead of an extracted directory; a workspace directory not checked out/mounted when the tool runs; users selecting 'a file' where the loader setting expects 'a folder'; relative paths resolved against the wrong working directory.","solutions":["Call file.exists() && file.isDirectory() before constructing DirectoryLoader; reject or redirect with a clear user message.","If the user selected a single file/jar, construct the appropriate file-based loader instead.","Resolve config paths to absolute paths and log them at startup to catch wrong-working-directory issues.","Catch LoaderException around loader construction and show a friendly 'not a directory' message."],"exampleFix":"// before\nLoader l = new DirectoryLoader(new File(cfg.get(\"codebase\")));\n// after\nFile dir = new File(cfg.get(\"codebase\"));\nif (!dir.exists() || !dir.isDirectory()) throw new LoaderException(\"codebase must be an existing directory: \" + dir);\nLoader l = new DirectoryLoader(dir);","handlingStrategy":"validation","validationCode":"File dir = new File(path);\nif (!dir.exists() || !dir.isDirectory())\n    throw new LoaderException(\"Expected an existing directory, got: \" + dir.getAbsolutePath());\nDirectoryLoader loader = new DirectoryLoader(dir);","typeGuard":"boolean isExistingDirectory(java.io.File f) {\n    return f != null && f.exists() && f.isDirectory();\n}","tryCatchPattern":"try {\n    loader = new DirectoryLoader(dir);\n} catch (LoaderException e) {\n    if (e.getMessage() != null && e.getMessage().endsWith(\"is not a directory\")) {\n        ui.showError(\"Please select an existing directory, not a file or missing path: \" + e.getMessage());\n    } else throw e;\n}","preventionTips":["Validate path exists and is a directory before constructing the loader","Resolve relative paths to absolute and log them to catch wrong working-directory issues","Offer a file/jar loader when the user selects a single class file or jar","Watch for case-sensitivity and unmounted-drive differences between dev and prod"],"tags":["java","loader","filesystem","input-validation"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"31430e0033fa220db566b5ef461256727ff6793b","analyzedAt":"2026-09-05T18:22:22.725Z","contentChangedAt":"2026-09-05T18:22:22.725Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}