hibernate/hibernate-orm · error · CoercionException
Cannot coerce Float value `%s` to Double : overflow
Error message
Cannot coerce Float value `%s` to Double : overflow
What it means
Guard inside CoercionHelper.toDouble(Float): it throws when floatValue > (float) Double.MAX_VALUE, i.e. a float supposedly too large for a double. In standard Java this branch is effectively unreachable: casting Double.MAX_VALUE to float yields +Infinity, every finite float (even Float.MAX_VALUE) is exactly representable as a double, and neither NaN nor Infinity satisfies a strict > against Infinity. It exists as the symmetric counterpart to the underflow check on the next lines.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CoercionHelper.java:346
if ( ! isWholeNumber( floatValue ) ) {
throw new CoercionException(
String.format(
Locale.ROOT,
"Unable to coerce Double Float `%s` as BigInteger: not a whole number",
floatValue
)
);
}
return BigInteger.valueOf( floatValue.longValue() );
}
public static BigInteger toBigInteger(BigDecimal value) {
return coerceWrappingError( value::toBigIntegerExact );
}
public static Double toDouble(Float floatValue) {
if ( floatValue > (float) Double.MAX_VALUE ) {
throw new CoercionException(
String.format(
Locale.ROOT,
"Cannot coerce Float value `%s` to Double : overflow",
floatValue
)
);
}
if ( floatValue < (float) Double.MIN_VALUE ) {
throw new CoercionException(
String.format(
Locale.ROOT,
"Cannot coerce Float value `%s` to Double : underflow",
floatValue
)
);
}
View on GitHub (pinned to fad1729dce)
Solutions
- If you believe you hit this, log the exact floatValue and verify no custom/patched CoercionHelper is on the classpath
- Sanitize inputs for Float.isInfinite() / Float.isNaN() before binding them
- Upgrade to a current hibernate-core 6.x release so the whole Float-to-Double path matches upstream
Defensive patterns
Strategy: validation
Validate before calling
static boolean doubleSafe(Float f) {
return f != null && f.isFinite(); // infinite/NaN never widen meaningfully
} Type guard
static boolean isFiniteFloat(Number n) {
return !(n instanceof Float f) || f.isFinite();
} Prevention
- Sanitize numeric inputs for NaN and Infinity before handing them to Hibernate
- Pin stock hibernate-core and avoid patching internal CoercionHelper
- If this exact message appears, suspect a modified classpath before blaming the data
When it happens
Trigger: Not producible by a plain float on a stock JVM, because (float > +Infinity) is always false; only reachable if a patched or custom CoercionHelper changes the comparison semantics.
Common situations: Essentially never seen in isolation; developers chasing Float-to-Double coercion failures actually hit the sibling 'underflow' throw (the next check) instead.
Related errors
- Cannot coerce Long value `%s` to Byte : overflow
- Cannot coerce Double value `%s` to Byte : overflow
- Cannot coerce Float value `%s` to Byte : overflow
- Cannot coerce Integer value `%s` as Short : overflow
- Cannot coerce Long value `%s` as Short : overflow
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/8456d6cc824193ce.
Report an issue: GitHub.