Federico Mariani created CAMEL-24168:
----------------------------------------
Summary: camel-bindy - BigDecimal/Double @DataField without
explicit precision throws ArithmeticException on unmarshal and truncates on
marshal
Key: CAMEL-24168
URL: https://issues.apache.org/jira/browse/CAMEL-24168
Project: Camel
Issue Type: Bug
Components: camel-bindy
Reporter: Federico Mariani
Attachments: BindyBigDecimalNoPrecisionIssueTest.java
*Severity:* High
*Affects:* 4.x (long-standing)
h3. Problem
A {{@DataField}} of type {{BigDecimal}} (or {{Double}}) *without* an explicit
{{precision}} fails to round-trip decimal values. {{@DataField.precision()}}
defaults to {{0}}. {{AbstractNumberFormat}} clamps {{this.precision = precision
> 0 ? precision : 0}}, so the "unset" case becomes {{0}}, and
{{BigDecimalFormatFactory.BigDecimalFormat.parse}}'s guard {{if (getPrecision()
!= -1)}} ({{0 != -1}} -> true) always applies {{setScale(0)}} with implicit
{{RoundingMode.UNNECESSARY}}. The {{!= -1}} check shows the original intent was
"-1 = unset", which the clamp destroyed. The {{@DataField.rounding()}}
attribute is also never passed to this factory.
h3. Failure scenario (reproduced)
{{@DataField(pos = 1) BigDecimal amount}} (no precision):
* unmarshal of {{10.35}} -> {{ArithmeticException: Rounding necessary}} (aborts
the whole record),
* marshal of {{new BigDecimal("10.35")}} -> {{"10"}} (silent truncation).
All suite models set {{precision=2}} explicitly, so this path is untested.
h3. Suggested fix
Preserve {{-1}} as "unset" through {{AbstractNumberFormat}} (or skip
{{setScale}} when no precision was declared) and honor
{{@DataField.rounding()}}. Note {{BindyNumberTest.testMarshall}} asserts the
current whole-number formatting for integral values — keep that.
h3. Reproducer
Attached {{BindyBigDecimalNoPrecisionIssueTest.java}}: unmarshal test errors
with {{ArithmeticException: Rounding necessary}}; marshal test gets {{10,foo}}
instead of {{10.35,foo}}. RED on current code.
----
_Reported by Claude Code on behalf of Federico Mariani (Croway). A failing
JUnit reproducer (confirmed RED on 4.22.0-SNAPSHOT) is attached._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)