projectlombok/lombok · error

DELOMBOK: delombok will only write to a directory. If you…

Error message

DELOMBOK: delombok will only write to a directory. If you want to delombok a single file, use -p to output to standard output, then redirect this to a file:
delombok MyJavaFile.java -p >MyJavaFileDelombok.java

What it means

Delombok.setOutput enforces that the output target is a directory: if the given File is an existing file, or a non-existent path whose name ends with '.java', it throws IllegalArgumentException with a hint to use -p for single-file output to stdout. Delombok writes the delomboked tree as a mirror of the source tree and does not support writing a single delomboked .java file directly.

Solutions

  1. Pass a directory as the output (-d out/ or setOutput(new File("out"))) and let delombok mirror the source tree
  2. For a single file, run delombok with -p (or no -d) to print to stdout and redirect: delombok MyJavaFile.java -p > MyJavaFileDelombok.java
  3. Rename/remove an accidentally-named .java output path before rerunning

Example fix

// before
delombok MyJavaFile.java -d MyJavaFileDelombok.java
// after
delombok MyJavaFile.java -p > MyJavaFileDelombok.java
Defensive patterns

Strategy: validation

Validate before calling

File out = new File(outputPath);
if (out.isFile() || (!out.isDirectory() && out.getName().endsWith(".java")))
    throw new IllegalArgumentException("Output must be a directory; use -p > file.java for single-file output");

Try / catch

try { delombok.setOutput(out); } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); /* fall back to stdout: use -p */ }

Prevention

When it happens

Trigger: Calling setOutput(new File("Foo.java")) (or CLI -d Foo.java) where Foo.java either exists as a file or does not exist but has a .java extension, or passing any existing file instead of a directory.

Common situations: Expecting '-d output.java' to write a single delomboked file; scripting delombok per-file and reusing the CLI switch intended for directory output; build tools wiring a file path into the output option.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of projectlombok/lombok@6d6a3e9fec (2026-09-07). Data as JSON: /api/errors/3741684efee7c02f. Report an issue: GitHub.

Appendix: source

Thrown at src/delombok/lombok/delombok/Delombok.java:549

	
	public void setVerbose(boolean verbose) {
		this.verbose = verbose;
	}
	
	public void setNoCopy(boolean noCopy) {
		this.noCopy = noCopy;
	}
	
	public void setDisablePreview(boolean disablePreview) {
		this.disablePreview = disablePreview;
	}
	
	public void setOnlyChanged(boolean onlyChanged) {
		this.onlyChanged = onlyChanged;
	}
	
	public void setOutput(File dir) {
		if (dir.isFile() || (!dir.isDirectory() && dir.getName().endsWith(".java"))) throw new IllegalArgumentException(
				"DELOMBOK: delombok will only write to a directory. " +
				"If you want to delombok a single file, use -p to output to standard output, then redirect this to a file:\n" +
				"delombok MyJavaFile.java -p >MyJavaFileDelombok.java");
		output = dir;
	}
	
	public void setOutputToStandardOut() {
		this.output = null;
	}
	
	public void setModulepath(String modulepath) {
		this.modulepath = modulepath;
	}
	
	public void addDirectory(File base) throws IOException {
		addDirectory0(false, base, "", 0);
	}
	

View on GitHub (pinned to 6d6a3e9fec)