[PR] Stop xsd2inst building digit-facet bounds as strings [p oi-xmlbeans]
pjfanning (via GitHub) <[email protected]>
| Newsgroups | gmane.comp.jakarta.poi.devel |
|---|---|
| Message-ID | <[email protected]> |
pjfanning opened a new pull request, #99:
URL: https://github.com/apache/poi-xmlbeans/pull/99
Branched from trunk, independent of #98.
### The bug
`SampleXmlUtil.formatDecimal` derived both digit-facet bounds by building a string and parsing it back — `xsd:totalDigits` as that many nines, `xsd:fractionDigits` as `"0.00...1"`. Both facets are `positiveInteger` with no ceiling of their own, so as soon as a schema asks for more digits than `maxNumberOfCharsForNumbers` allows, `parseAsBigDecimal` rejects the string the method just built:
```
IllegalArgumentException: Number has more than 1024 characters
```
and `xsd2inst` cannot generate a sample for the schema at all. 5.3.0 used `new BigDecimal(...)` here and was unaffected; the limit arrived in 5.4.0.
A minimal reproducer — nothing else in the schema:
```xml
<xs:simpleType name="constrainedDecimal">
<xs:restriction base="xs:decimal">
<xs:totalDigits value="2000"/>
</xs:restriction>
</xs:simpleType>
```
The `fractionDigits` branch fails the same way at 1023.
### The fix
Compute both values instead of spelling them out:
- `10^totalDigits - 1` for the widest value the facet allows;
- `BigDecimal.ONE.scaleByPowerOfTen(-fractionDigits)` for the increment, which only sets a scale and expands nothing.
The `totalDigits` bound can only narrow a `min`/`max` that is at least as wide, so it is now computed only when it can actually bind. That is what keeps `10^n` away from a `totalDigits` far larger than any bound the schema declares — the previous code built its string of nines unconditionally, even when no `min` or `max` facet existed for it to constrain.
Behaviour for schemas within the limit is unchanged: `totalDigits` still pulls the seed value down to the widest value it permits.
### Tests
`testDigitFacetsWiderThanTheNumberLengthLimit` covers both facets past the limit — it fails on trunk with the exception above. `testTotalDigitsStillNarrowsTheBounds` pins the normal case (seed `1000.00`, `totalDigits=3` → `999`) and passes both before and after, so it guards the semantics rather than the fix.
Full suite: 3084 tests, 0 failures.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]