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
While scanning inside the braces, this parser accepts only quoted elements ("..."), the unquoted token null, whitespace and commas. Any other character found outside a quote — i.e. a bare unquoted element such as {red,green} — aborts with this IllegalArgumentException. Hibernate serializes every non-null string element in quotes, so an unquoted literal means the text came from some other producer (PostgreSQL's own output omits quotes when elements do not need them).
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/BasicCollectionJavaType.java:331
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') {
list.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 );
}
final C result = semantics.instantiateRaw( list.size(), null );
for ( int i = 0; i < list.size(); i ++ ) {
if ( list.get( i ) != null ) {
result.add( componentJavaType.fromString( list.get( i ) ) );
}
}
return result;
}View on GitHub (pinned to fad1729dce)
Solutions
- Quote every element when building literals: {"one","two"}
- Write values through Hibernate parameter binding so quoting is generated automatically
- In native SQL, select the array column directly instead of array_to_string(...)
- Emit nulls exactly as the unquoted four-letter token null
Example fix
// before
String literal = "{" + String.join(",", List.of("one", "two")) + "}"; // {one,two} -> throws
// after
String literal = list.stream()
.map(v -> v == null ? "null" : '"' + v + '"')
.collect(java.util.stream.Collectors.joining(",", "{", "}")); // {"one","two"} Defensive patterns
Strategy: validation
Validate before calling
static String toHibernateStringArrayLiteral(List<String> values) {
return values.stream()
.map(v -> v == null ? "null"
: '"' + v.replace("\\", "\\\\").replace("\"", "\\\"") + '"')
.collect(java.util.stream.Collectors.joining(",", "{", "}"));
} // always quote elements and escape backslash/quote before fromString() Try / catch
try {
Collection<String> c = basicCollectionJavaType.fromString(raw);
} catch (IllegalArgumentException e) {
// unquoted literal from an external producer: parse leniently yourself
String inner = raw.substring(1, raw.length() - 1);
List<String> c = inner.isEmpty() ? List.of() : List.of(inner.split(","));
} Prevention
- Never assemble array literals with plain string concatenation
- Remember psql and Hibernate do not quote literals identically
- Route external array text through a quoting normalizer before handing it to Hibernate
When it happens
Trigger: Feeding '{one,two}' produced by native array_to_string(), psql output copied into fixtures, String.join(",", list) wrapped in braces by hand, or an upstream system emitting PostgreSQL ARRAY text where quoting is optional.
Common situations: Reporting/ETL tools normalizing array text; test fixtures pasted from psql; version of the literal format written by a different driver or library that quotes less aggressively.
Related errors
- Cannot parse given string into array of Shorts. First and la
- Cannot parse given string into array of strings. First and l
- Cannot parse given string into array of strings. First and l
- Cannot parse given string into array of strings. Outside of
- Cannot parse given string into array of Doubles. First and l
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/872e58f165cff986.
Report an issue: GitHub.