hibernate/hibernate-orm · error · IllegalArgumentException
Cannot parse given string into array of strings. Outside of
Error message
Cannot parse given string into array of strings. Outside of quote, but neither whitespace, comma, array end, nor null found.
What it means
The in-loop companion of ArrayJavaType.fromString: while scanning the '{...}' literal it hit a character outside quotes that is neither whitespace, a comma, the closing '}' nor the start of the token 'null'. The literal is syntactically malformed at that position.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java:238
sb = null;
}
continue;
}
else {
// i + 4, because there has to be a comma or closing brace after null
if ( i + 4 < len
&& charSequence.charAt( i ) == 'n'
&& charSequence.charAt( i + 1 ) == 'u'
&& charSequence.charAt( i + 2 ) == 'l'
&& charSequence.charAt( i + 3 ) == 'l') {
lst.add( null );
i += 4;
continue;
}
if (i + 1 == len) {
break;
}
throw new IllegalArgumentException( "Cannot parse given string into array of strings."
+ " Outside of quote, but neither whitespace, comma, array end, nor null found." );
}
}
else if ( c == '\\' && i + 2 < len && (charSequence.charAt( i + 1 ) == '\\' || charSequence.charAt( i + 1 ) == '"')) {
c = charSequence.charAt( ++i );
}
// If there is ever a null-pointer here, the if-else logic before is incomplete
sb.append( c );
}
//noinspection unchecked
final var result = (T[]) newInstance( getElementJavaType().getJavaTypeClass(), lst.size() );
for ( int i = 0; i < result.length; i ++ ) {
if ( lst.get( i ) != null ) {
result[i] = getElementJavaType().fromString( lst.get( i ) );
}
}
return result;
}View on GitHub (pinned to fad1729dce)
Solutions
- Quote any element containing ',', ';', '{', '}' or '"' and escape embedded quotes/backslashes ("\"" and "\\")
- Build literals with a proper formatter or let the driver/ORM write them instead of string concatenation
- Repair truncated/corrupt rows (validate with a regex like ^\{.*\}$ plus per-token checks)
- Add a converter that normalizes the stored text before Hibernate parses it
Example fix
// before
String literal = "{amount;total}"; // ';' illegal outside quotes -> IllegalArgumentException
// after
String literal = "{\"amount;total\"}"; // quoted element: {"amount;total"} Defensive patterns
Strategy: validation
Validate before calling
// per-element formatter that quotes/escapes everything risky
static String pgArrayLiteral(List<String> elems) {
return elems.stream()
.map(e -> e == null ? "null" : '"' + e.replace("\\", "\\\\").replace("\"", "\\\"") + '"')
.collect(joining(",", "{", "}"));
} Type guard
static boolean onlyLegalTokens(CharSequence s) {
boolean inQuote = false;
for (int i = 1; i < s.length() - 1; i++) {
char c = s.charAt(i);
if (c == '"') inQuote = !inQuote;
else if (!inQuote && !Character.isWhitespace(c) && c != ',' && c != 'n' && c != 'u' && c != 'l') return false;
}
return !inQuote;
} Try / catch
try {
doc.setTags(literal);
session.flush();
} catch (IllegalArgumentException e) {
if (String.valueOf(e.getMessage()).contains("Outside of quote")) {
doc.setTags(pgArrayLiteral(tagList)); // rewrite in canonical literal form and retry
session.flush();
} else throw e;
} Prevention
- Always build literals with a quoting formatter, never concatenation
- Escape backslash and double-quote inside quoted elements
- Fuzz-test any hand-rolled literal builder with special characters
- Prefer native array columns over varchar hacks
When it happens
Trigger: An array literal containing unquoted special characters, e.g. '{a{b}', '{x y z;w}', stray text after an element ('{a b}' is fine as separator-free whitespace but '{a;b}' is not), or a truncated value like '{a,b' where the parser walks past garbage before reaching the missing '}'.
Common situations: Elements containing commas, semicolons, braces or backslashes stored without quoting; hand-built literal strings via naive string concatenation; escaped-quote handling that dropped the closing quote ('{"a}' leaves the parser mid-token); data corruption/truncation in the varchar column backing the array.
Related errors
- Cannot parse given string into array of strings. First and l
- Unexpected PostgreSQL lock_timeout format: {}
- Locking with OUTER joins is not supported
- Illegal null value for array index encountered while reading
- Nested arrays (with the exception of byte[][]) are not suppo
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3df20379b01ef37d.
Report an issue: GitHub.