{"record":{"id":"8456d6cc824193ce","repo":"hibernate/hibernate-orm","slug":"cannot-coerce-float-value-s-to-double-overflo","errorCode":null,"errorMessage":"Cannot coerce Float value `%s` to Double : overflow","messagePattern":"Cannot coerce Float value `(.+?)` to Double : overflow","errorType":"exception","errorClass":"CoercionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CoercionHelper.java","lineNumber":346,"sourceCode":"\t\tif ( ! isWholeNumber( floatValue ) ) {\n\t\t\tthrow new CoercionException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Unable to coerce Double Float `%s` as BigInteger: not a whole number\",\n\t\t\t\t\t\t\tfloatValue\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn BigInteger.valueOf( floatValue.longValue() );\n\t}\n\n\tpublic static BigInteger toBigInteger(BigDecimal value) {\n\t\treturn coerceWrappingError( value::toBigIntegerExact );\n\t}\n\n\tpublic static Double toDouble(Float floatValue) {\n\t\tif ( floatValue > (float) Double.MAX_VALUE ) {\n\t\t\tthrow new CoercionException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Cannot coerce Float value `%s` to Double : overflow\",\n\t\t\t\t\t\t\tfloatValue\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\tif ( floatValue < (float) Double.MIN_VALUE ) {\n\t\t\tthrow new CoercionException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Cannot coerce Float value `%s` to Double : underflow\",\n\t\t\t\t\t\t\tfloatValue\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CoercionHelper.java#L328-L364","documentation":"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.","triggerScenarios":"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.","commonSituations":"Essentially never seen in isolation; developers chasing Float-to-Double coercion failures actually hit the sibling 'underflow' throw (the next check) instead.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"static boolean doubleSafe(Float f) {\n    return f != null && f.isFinite(); // infinite/NaN never widen meaningfully\n}","typeGuard":"static boolean isFiniteFloat(Number n) {\n    return !(n instanceof Float f) || f.isFinite();\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["hibernate","type-coercion","numeric","overflow","dead-code"],"backgroundTag":"numeric-type-coercion-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}