hibernate/hibernate-orm · error · IllegalArgumentException

Cannot parse given string into array of Doubles. First and l

Error message

Cannot parse given string into array of Doubles. First and last character must be { and }

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoublePrimitiveArrayJavaType.java:89

		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 double[] fromString(CharSequence charSequence) {
		if ( charSequence == null ) {
			return null;
		}
		final List<Double> 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 Doubles. 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( Double.parseDouble( charSequence.subSequence( elementStart, i ).toString() ) );
				elementStart = i + 1;
			}
		}
		final double[] result = new double[list.size()];
		for ( int i = 0; i < result.length; i ++ ) {
			result[ i ] = list.get( i );
		}
		return result;
	}

	@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Normalize the stored data to '{e1,e2}' exactly as Hibernate writes it
  2. Add an AttributeConverter<double[], String> that accepts and normalizes multiple input formats on read
  3. Use a real SQL ARRAY column with @JdbcTypeCode(SqlTypes.ARRAY) on a dialect that supports it, avoiding text round-trips
  4. If you control writes, always emit the brace format

Example fix

// before: column text is '1.0;2.0' -> IllegalArgumentException

// after: normalizing converter on read
@Converter
public class DoubleArrayConverter implements AttributeConverter<double[], String> {
    @Override public String convertToDatabaseColumn(double[] a) {
        StringBuilder sb = new StringBuilder("{");
        for (int i = 0; i < a.length; i++) sb.append(i > 0 ? "," : "").append(a[i]);
        return sb.append("}").toString();
    }
    @Override public double[] convertToEntityAttribute(String s) {
        String t = s.trim();
        if (t.startsWith("[")) t = '{' + t.substring(1, t.length() - 1) + '}';
        // then parse the {..} form
        ...
    }
}
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) == '}';
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/f3ddb360145132c2. Report an issue: GitHub.