{"record":{"id":"f3ddb360145132c2","repo":"hibernate/hibernate-orm","slug":"cannot-parse-given-string-into-array-of-doubles-f","errorCode":null,"errorMessage":"Cannot parse given string into array of Doubles. First and last character must be { and }","messagePattern":"Cannot parse given string into array of Doubles\\. 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/DoublePrimitiveArrayJavaType.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 double[] fromString(CharSequence charSequence) {\n\t\tif ( charSequence == null ) {\n\t\t\treturn null;\n\t\t}\n\t\tfinal List<Double> 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 Doubles. 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( Double.parseDouble( charSequence.subSequence( elementStart, i ).toString() ) );\n\t\t\t\telementStart = i + 1;\n\t\t\t}\n\t\t}\n\t\tfinal double[] result = new double[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/DoublePrimitiveArrayJavaType.java#L71-L107","documentation":"DoublePrimitiveArrayJavaType.fromString reconstructs a double[] from the string form Hibernate uses for array-valued columns ('{1.0,2.0}' — PostgreSQL array-literal style, produced by the matching toString). It throws IllegalArgumentException when the first and last characters are not '{' and '}', i.e. the stored text is not an array literal in the expected shape.","triggerScenarios":"Reading a double[] attribute whose column text was written by another producer in a different format ('[1.0, 2.0]', '1.0;2.0', 'null'); hand-migrated data; a dialect or mapping change that altered how arrays are rendered to text.","commonSituations":"Databases without native ARRAY support storing arrays as text; ETL imports; switching between @JdbcTypeCode(SqlTypes.ARRAY) and varchar-backed mappings; migrations that reformat array columns.","solutions":["Normalize the stored data to '{e1,e2}' exactly as Hibernate writes it","Add an AttributeConverter<double[], String> that accepts and normalizes multiple input formats on read","Use a real SQL ARRAY column with @JdbcTypeCode(SqlTypes.ARRAY) on a dialect that supports it, avoiding text round-trips","If you control writes, always emit the brace format"],"exampleFix":"// before: column text is '1.0;2.0' -> IllegalArgumentException\n\n// after: normalizing converter on read\n@Converter\npublic class DoubleArrayConverter implements AttributeConverter<double[], String> {\n    @Override public String convertToDatabaseColumn(double[] a) {\n        StringBuilder sb = new StringBuilder(\"{\");\n        for (int i = 0; i < a.length; i++) sb.append(i > 0 ? \",\" : \"\").append(a[i]);\n        return sb.append(\"}\").toString();\n    }\n    @Override public double[] convertToEntityAttribute(String s) {\n        String t = s.trim();\n        if (t.startsWith(\"[\")) t = '{' + t.substring(1, t.length() - 1) + '}';\n        // then parse the {..} form\n        ...\n    }\n}","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":["Keep a single writer for array-as-text columns — Hibernate itself","Verify array literal format after data migrations with a SELECT","Prefer native ARRAY/vector column types over text storage"],"tags":["hibernate","array","parsing","double","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"}