projectlombok/lombok · error

Unclosed backslash escape in @ file

Error message

Unclosed backslash escape in @ file

What it means

When Delombok reads arguments from an @argfile (delombok @file), it parses each line character by character, tracking backslash escapes and quoted strings with a state machine. State < 0 after the input ends means a backslash started an escape sequence that was never completed, so it throws IOException("Unclosed backslash escape in @ file").

Solutions

  1. Remove the trailing backslash or follow it with the intended escaped character
  2. Use forward slashes in paths inside the @argfile (Java accepts them on all platforms)
  3. Double backslashes where a literal backslash is wanted: path\\to\\file

Example fix

// before (@args.txt)
-d C:\output\
// after (@args.txt)
-d C:\output
Defensive patterns

Strategy: validation

Validate before calling

for (String line : java.nio.file.Files.readAllLines(argfile)) {
    if (line.endsWith("\\")) throw new IllegalArgumentException("Trailing backslash in argfile: " + line);
}

Try / catch

try { return delombok.parts(new String[]{"@args.txt"}); } catch (IOException e) { if (e.getMessage().contains("Unclosed backslash")) { /* fix argfile and retry */ } throw e; }

Prevention

When it happens

Trigger: An @argfile line ends with a lone trailing backslash (e.g. -d /path/to\ or an argument ending in \), so the parser enters escape state and hits end-of-input without a following character.

Common situations: Windows-style paths in argfiles written with backslashes where the last segment ends with a separator; copy-pasted lines ending in '\'; shell-escaped arguments pasted verbatim into the file.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

				a.append(c);
				continue;
			}
			if (state == 3) {
				if (c == '\'') {
					state = 1;
					x.add(a.toString());
					a.setLength(0);
					continue;
				}
				a.append(c);
				continue;
			}
		}
		if (state == 1) {
			String aa = a.toString();
			if (!aa.isEmpty()) x.add(aa);
		} else if (state < 0) {
			throw new IOException("Unclosed backslash escape in @ file");
		} else if (state == 2) {
			throw new IOException("Unclosed \" in @ file");
		} else if (state == 3) {
			throw new IOException("Unclosed ' in @ file");
		}
		
		return x.toArray(new String[0]);
	}
	
	public static class InvalidFormatOptionException extends Exception {
		public InvalidFormatOptionException(String msg) {
			super(msg);
		}
	}
	
	public static Map<String, String> formatOptionsToMap(List<String> formatOptions) throws InvalidFormatOptionException {
		boolean prettyEnabled = false;
		Map<String, String> formatPrefs = new HashMap<String, String>();

View on GitHub (pinned to 6d6a3e9fec)