Konloch/bytecode-viewer · error · LoaderException

'${codebase}' is not a directory

Error message

'${codebase}' is not a directory

What it means

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.

Source

Thrown at src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java:43

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class DirectoryLoader implements Loader
{
    protected String codebase;
    protected long lastModified;
    protected boolean isFile;

    public DirectoryLoader(File file) throws LoaderException
    {
        this.codebase = file.getAbsolutePath();
        this.lastModified = file.lastModified();
        this.isFile = file.isFile();

        if (!(file.exists() && file.isDirectory()))
            throw new LoaderException("'" + codebase + "' is not a directory");
    }

    @Override
    public byte[] load(String internalPath) throws LoaderException
    {
        if (!internalPath.endsWith(".class"))
            internalPath = internalPath + ".class";

        File file = new File(this.codebase, internalPath);

        try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis))
        {
            return IOUtils.toByteArray(bis);
        }
        catch (IOException e)
        {
            throw new LoaderException("'" + file.getAbsolutePath() + "'  not found.");
        }

View on GitHub (pinned to 31430e0033)

Solutions

  1. Call file.exists() && file.isDirectory() before constructing DirectoryLoader; reject or redirect with a clear user message.
  2. If the user selected a single file/jar, construct the appropriate file-based loader instead.
  3. Resolve config paths to absolute paths and log them at startup to catch wrong-working-directory issues.
  4. Catch LoaderException around loader construction and show a friendly 'not a directory' message.

Example fix

// before
Loader l = new DirectoryLoader(new File(cfg.get("codebase")));
// after
File dir = new File(cfg.get("codebase"));
if (!dir.exists() || !dir.isDirectory()) throw new LoaderException("codebase must be an existing directory: " + dir);
Loader l = new DirectoryLoader(dir);
Defensive patterns

Strategy: validation

Validate before calling

File dir = new File(path);
if (!dir.exists() || !dir.isDirectory())
    throw new LoaderException("Expected an existing directory, got: " + dir.getAbsolutePath());
DirectoryLoader loader = new DirectoryLoader(dir);

Type guard

boolean isExistingDirectory(java.io.File f) {
    return f != null && f.exists() && f.isDirectory();
}

Try / catch

try {
    loader = new DirectoryLoader(dir);
} catch (LoaderException e) {
    if (e.getMessage() != null && e.getMessage().endsWith("is not a directory")) {
        ui.showError("Please select an existing directory, not a file or missing path: " + e.getMessage());
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Konloch/bytecode-viewer@31430e0033 (2026-09-05). Data as JSON: /api/errors/fd07ed66c885ade1. Report an issue: GitHub.