apache/beam · error · IllegalArgumentException
illegal trailing backslash
Error message
illegal trailing backslash
What it means
unescapeFieldName() throws this IllegalArgumentException when the quoted identifier's content ends with a lone backslash that starts an escape sequence but has no following character. A trailing \ cannot be interpreted as any valid escape, so the identifier is rejected.
Source
Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/QueryUtils.java:272
for (int i = 0; i < fieldName.length(); i++) {
char c = fieldName.charAt(i);
// Roughly speaking, there are 4 cases we care about:
// - carriage returns: \r and \r\n
// - unescaped quotes: `
// - non-escape sequences
// - escape sequences
if (c == '`') {
throw new IllegalArgumentException("quoted identifier cannot contain unescaped quote");
} else if (c == '\r') {
buf.append('\n');
// Convert '\r\n' into '\n'
if (i + 1 < fieldName.length() && fieldName.charAt(i + 1) == '\n') {
i++;
}
} else if (c != '\\') {
buf.append(c);
} else if (i + 1 >= fieldName.length()) {
throw new IllegalArgumentException("illegal trailing backslash");
} else {
i++;
switch (fieldName.charAt(i)) {
case 'a':
buf.appendCodePoint(Ascii.BEL); // "Alert" control character
break;
case 'b':
buf.append('\b');
break;
case 'f':
buf.append('\f');
break;
case 'n':
buf.append('\n');
break;
case 'r':
buf.append('\r');
break;View on GitHub (pinned to 12126d8942)
Solutions
- Remove the trailing backslash if it is accidental
- Escape it as \\ so it represents a literal backslash
- Validate the quoted identifier has no trailing lone backslash before parsing
Example fix
// before
OrderByFieldPath.fromString("doc.`path\\`"); // ends with single \\
// after
OrderByFieldPath.fromString("doc.`path\\\\`"); Defensive patterns
Strategy: validation
Validate before calling
public static boolean endsWithLoneBackslash(String quotedContent) {
int bs = 0;
for (int i = quotedContent.length() - 1; i >= 0 && quotedContent.charAt(i) == '\\'; i--) bs++;
return bs % 2 == 1;
} Try / catch
try {
OrderByFieldPath p = OrderByFieldPath.fromString(path);
} catch (IllegalArgumentException e) {
LOG.warn("Trailing backslash in quoted identifier '{}'", path);
} Prevention
- Double every intended-literal backslash (\\) when authoring quoted identifiers
- Check config strings for trailing backslashes after editing, especially Windows-derived paths
When it happens
Trigger: A quoted segment like `abc\` where the final character is a backslash not followed by any escape character (a, b, f, n, r, t, v, \, `, 0-3, x, u, U).
Common situations: Config strings where a trailing backslash was intended as a literal (e.g. Windows-style name) and not doubled; string escaping done twice or truncated by upstream tooling.
Related errors
- quoted identifier cannot contain unescaped quote
- illegal octal escape sequence
- illegal hex escape sequence
- illegal unicode escape sequence
- Could not resolve empty field path
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/99d546e8881e86f8.
Report an issue: GitHub.