{"record":{"id":"5b426de043385833","repo":"hibernate/hibernate-orm","slug":"cannot-parse-given-string-into-array-of-floats-fi","errorCode":null,"errorMessage":"Cannot parse given string into array of Floats. First and last character must be { and }","messagePattern":"Cannot parse given string into array of Floats\\. 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/FloatPrimitiveArrayJavaType.java","lineNumber":89,"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 float[] fromString(CharSequence charSequence) {\n\t\tif ( charSequence == null ) {\n\t\t\treturn null;\n\t\t}\n\t\tfinal List<Float> 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 Floats. 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( Float.parseFloat( charSequence.subSequence( elementStart, i ).toString() ) );\n\t\t\t\telementStart = i + 1;\n\t\t\t}\n\t\t}\n\t\tfinal float[] result = new float[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":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatPrimitiveArrayJavaType.java#L71-L107","documentation":"FloatPrimitiveArrayJavaType.fromString reconstructs a float[] from the array-literal string form Hibernate uses for array-valued columns ('{1.0,2.0}'). It throws IllegalArgumentException when the first and last characters are not '{' and '}' — the stored text is not in the expected array-literal shape.","triggerScenarios":"Reading a float[] attribute whose column text was written by another producer in a different format ('[1.0, 2.0]', '1.0;2.0'); hand-migrated data; dialect or mapping changes that altered the array rendering.","commonSituations":"Databases storing arrays as text without native ARRAY support; ETL imports; switching mappings between SqlTypes.ARRAY and varchar-backed storage.","solutions":["Normalize stored data to the '{e1,e2}' form Hibernate emits","Add an AttributeConverter<float[], String> that tolerates other formats on read","Use a native ARRAY column type with @JdbcTypeCode(SqlTypes.ARRAY) where the dialect supports it","Ensure a single writer for array-as-text columns"],"exampleFix":"// before: column text is '[1.5, 2.5]' -> IllegalArgumentException\n\n// after: normalize before Hibernate parses, or fix the data\nUPDATE mytable SET vals = '{' || substring(vals from 2 for length(vals) - 2) || '}' WHERE vals LIKE '[%]';","handlingStrategy":"validation","validationCode":"static boolean isArrayLiteral(CharSequence s) {\n    return s != null && s.length() >= 2\n            && s.charAt(0) == '{' && s.charAt(s.length() - 1) == '}';\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize stored array text to the {a,b} literal form","Add an AttributeConverter if multiple formats must be tolerated on read","Prefer native ARRAY columns where the dialect supports them"],"tags":["hibernate","array","parsing","float","postgres-literal"],"backgroundTag":"array-literal-parse-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}