Skip to content

WW-5711 fix(conversion): bound fraction digits when formatting BigDecimal - #1888

Open
lukaszlenart wants to merge 1 commit into
support/struts-6-x-xfrom
WW-5711-bound-bigdecimal-fraction-digits-6x
Open

WW-5711 fix(conversion): bound fraction digits when formatting BigDecimal#1888
lukaszlenart wants to merge 1 commit into
support/struts-6-x-xfrom
WW-5711-bound-bigdecimal-fraction-digits-6x

Conversation

@lukaszlenart

Copy link
Copy Markdown
Member

6.x backport of #1887.

StringConverter formatted BigDecimal, Double and Float with maximumFractionDigits set to Integer.MAX_VALUE.

That constant arrived with WW-4871, which fixed round-trip precision loss for double and float. Both of those types are naturally bounded — the widest double needs 325 fraction digits (Double.MIN_VALUE) and the widest float needs 45 — so Integer.MAX_VALUE is far wider than WW-4871 required.

BigDecimal carries no such bound. DecimalFormat honours maximumFractionDigits literally and pads the fraction out to the value's full scale, so the length of the formatted output followed the scale of the value rather than its precision.

Bound the setting to 340 instead.

Differences from the main-line change

Same change, adjusted for this line: the class sits under com.opensymphony.xwork2.conversion.impl rather than org.apache.struts2.conversion.impl, and the surrounding code uses the X.class.isInstance(value) idiom, which is left as it is. Not a cherry-pick.

Backward compatibility

Every double and float value still formats in full, so WW-4871's behaviour is preserved exactly. Every BigDecimal with a scale of 340 or less is also unchanged. A BigDecimal scaled beyond 340 is now rounded to that bound rather than padded out in full — the only observable difference.

The existing round-trip assertions are untouched and still pass: testDoubleToStringConversionPL pins Double.MIN_VALUE at 325 fraction digits, and testBigDecimalToStringConversionPL pins a value slightly wider than double at 326.

Scope

Render side only. NumberConverter.convertToBigDecimal is unchanged in this PR.

Testing

The new test was confirmed failing on support/struts-6-x-x before the fix was applied, then green after. Full suite: mvn test -DskipAssembly -pl core — 2728 tests, 0 failures.

Fixes WW-5711

…imal

StringConverter formatted BigDecimal, Double and Float with
maximumFractionDigits set to Integer.MAX_VALUE. That constant arrived
with WW-4871, which fixed round-trip precision loss for double and
float; both of those types are naturally bounded, the widest being
Double.MIN_VALUE at 325 fraction digits.

BigDecimal has no such bound. DecimalFormat honours
maximumFractionDigits literally and pads the fraction out to the
value's full scale, so the length of the formatted output followed the
scale of the value rather than its precision.

Bound the setting to 340. Every double and float value still formats in
full, as does every BigDecimal within that range; beyond it the value is
rounded to the bound. The existing round-trip assertions for
Double.MIN_VALUE (325 fraction digits) and for a BigDecimal slightly
wider than double (326) are untouched and still pass.

Backport of the same change on main, adjusted for the
com.opensymphony.xwork2 package layout of this line.

Fixes: https://issues.apache.org/jira/browse/WW-5711

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LwgeV4TN78ke2hHKTVWAUP
@sonarqubecloud

Copy link
Copy Markdown

@lukaszlenart
lukaszlenart marked this pull request as ready for review September 1, 2026 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant