hibernate/hibernate-orm · error · IllegalArgumentException
Cannot parse given string into array of Booleans. First and
Error message
Cannot parse given string into array of Booleans. First and last character must be { and } What it means
BooleanPrimitiveArrayJavaType.fromString parses a boolean[] from an array literal in the PostgreSQL output format, e.g. '{true,false}'. If the first character is not '{' or the last is not '}', it throws IllegalArgumentException instead of attempting to parse a plain list.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java:84
sb.append( value[0] );
for ( int i = 1; i < value.length; i++ ) {
sb.append( value[i] );
sb.append( ',' );
}
sb.append( '}' );
return sb.toString();
}
@Override
public boolean[] fromString(CharSequence charSequence) {
if ( charSequence == null ) {
return null;
}
final List<Boolean> list = new ArrayList<>();
final char lastChar = charSequence.charAt( charSequence.length() - 1 );
final char firstChar = charSequence.charAt( 0 );
if ( firstChar != '{' || lastChar != '}' ) {
throw new IllegalArgumentException( "Cannot parse given string into array of Booleans. First and last character must be { and }" );
}
final int len = charSequence.length();
int elementStart = 1;
for ( int i = elementStart; i < len; i ++ ) {
final char c = charSequence.charAt( i );
if ( c == ',' ) {
list.add( Boolean.parseBoolean( charSequence.subSequence( elementStart, i ).toString() ) );
elementStart = i + 1;
}
}
final boolean[] result = new boolean[list.size()];
for ( int i = 0; i < result.length; i ++ ) {
result[ i ] = list.get( i );
}
return result;
}
@OverrideView on GitHub (pinned to fad1729dce)
Solutions
- Store values in '{...}' array-literal form (the exact inverse of toString()).
- Map boolean[] with a real SQL array type: @JdbcTypeCode(SqlTypes.BOOLEAN_ARRAY) on a supporting database.
- Transform legacy rows before reading: wrap the value in braces.
Example fix
// before
UPDATE flags SET vals = 'true,false'; -- row read later throws IllegalArgumentException
// after
UPDATE flags SET vals = '{true,false}';
// mapping alternative
@JdbcTypeCode(SqlTypes.BOOLEAN_ARRAY)
private boolean[] vals; Defensive patterns
Strategy: validation
Validate before calling
static boolean isArrayLiteral(CharSequence s) {
return s != null && s.length() >= 2 && s.charAt(0) == '{' && s.charAt(s.length() - 1) == '}';
}
// before assignment: if (!isArrayLiteral(value)) value = '{' + value + '}'; Prevention
- Write array columns only through Hibernate's own array support so format stays symmetric.
- Validate third-party/imported strings before they reach the attribute.
- Prefer native SQL array types over text-encoded arrays.
When it happens
Trigger: Reading a boolean[] attribute from a String-typed column whose content is a plain comma list like 'true,false'; native queries returning array text without braces; a boolean[] field mapped with @JdbcTypeCode(SqlTypes.VARCHAR) or read from a cache value not produced by toString().
Common situations: Hand-written column values or seed data; ETL inserting list strings; mapping boolean[] against an incompatible JdbcType after a mapping refactor.
Related errors
- Unexpected PostgreSQL lock_timeout format: {}
- Could not find root
- Cannot parse given string into array of strings. First and l
- Cannot parse given string into array of strings. Outside of
- The string is not a valid string representation of a binary
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/cbec2edacbe14604.
Report an issue: GitHub.