{"record":{"id":"cbec2edacbe14604","repo":"hibernate/hibernate-orm","slug":"cannot-parse-given-string-into-array-of-booleans","errorCode":null,"errorMessage":"Cannot parse given string into array of Booleans. First and last character must be { and }","messagePattern":"Cannot parse given string into array of Booleans\\. First and last character must be (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java","lineNumber":84,"sourceCode":"\t\tsb.append( value[0] );\n\t\tfor ( int i = 1; i < value.length; i++ ) {\n\t\t\tsb.append( value[i] );\n\t\t\tsb.append( ',' );\n\t\t}\n\t\tsb.append( '}' );\n\t\treturn sb.toString();\n\t}\n\n\t@Override\n\tpublic boolean[] fromString(CharSequence charSequence) {\n\t\tif ( charSequence == null ) {\n\t\t\treturn null;\n\t\t}\n\t\tfinal List<Boolean> list = new ArrayList<>();\n\t\tfinal char lastChar = charSequence.charAt( charSequence.length() - 1 );\n\t\tfinal char firstChar = charSequence.charAt( 0 );\n\t\tif ( firstChar != '{' || lastChar != '}' ) {\n\t\t\tthrow new IllegalArgumentException( \"Cannot parse given string into array of Booleans. First and last character must be { and }\" );\n\t\t}\n\t\tfinal int len = charSequence.length();\n\t\tint elementStart = 1;\n\t\tfor ( int i = elementStart; i < len; i ++ ) {\n\t\t\tfinal char c = charSequence.charAt( i );\n\t\t\tif ( c == ',' ) {\n\t\t\t\tlist.add( Boolean.parseBoolean( charSequence.subSequence( elementStart, i ).toString() ) );\n\t\t\t\telementStart = i + 1;\n\t\t\t}\n\t\t}\n\t\tfinal boolean[] result = new boolean[list.size()];\n\t\tfor ( int i = 0; i < result.length; i ++ ) {\n\t\t\tresult[ i ] = list.get( i );\n\t\t}\n\t\treturn result;\n\t}\n\n\t@Override","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java#L66-L102","documentation":"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.","triggerScenarios":"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().","commonSituations":"Hand-written column values or seed data; ETL inserting list strings; mapping boolean[] against an incompatible JdbcType after a mapping refactor.","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."],"exampleFix":"// before\nUPDATE flags SET vals = 'true,false'; -- row read later throws IllegalArgumentException\n\n// after\nUPDATE flags SET vals = '{true,false}';\n\n// mapping alternative\n@JdbcTypeCode(SqlTypes.BOOLEAN_ARRAY)\nprivate boolean[] vals;","handlingStrategy":"validation","validationCode":"static boolean isArrayLiteral(CharSequence s) {\n    return s != null && s.length() >= 2 && s.charAt(0) == '{' && s.charAt(s.length() - 1) == '}';\n}\n// before assignment: if (!isArrayLiteral(value)) value = '{' + value + '}';","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["hibernate","boolean-array","parsing","postgresql-array"],"backgroundTag":"array-string-parse","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}