Skip to content

fail NaN on float and double bound facets in validateValue - #175

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:nan-bound-facets
Open

aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:nan-bound-facets

Conversation

@aizu-m

@aizu-m aizu-m commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Differential run, XmlObject.validate() vs the JDK Xerces validator, xs:double with <xs:minInclusive value="0"/>:

<v>NaN</v>
     XB: VALID
     XE: INVALID cvc-minInclusive-valid: Value 'NaN' is not facet-valid with respect to minInclusive '0.0E1' for type 'T'.

How it was found: I ran NaN, INF, -INF and 0 against each of the four bound facets on xs:float and xs:double, with bounds of 0, NaN, INF and -INF. 24 of the 128 cases disagreed with Xerces. Every one had NaN on exactly one side.

Observations:

  • JavaFloatHolder.compare and JavaDoubleHolder.compare fall back to the bit patterns, which puts NaN above every other value.
  • So the max facets already reject a NaN value, but minInclusive and minExclusive accept it. A NaN max bound accepts every number.
  • XML Schema makes NaN equal to itself and incomparable with every other value. Xerces reports every bound facet for those pairs.
  • fail min facets on incomparable date and duration values #132 fixed the same min-facet gap for dateTime and duration. It left float and double alone because they looked totally ordered. NaN is the exception.

Conclusion: a schema that bounds a float or double with minInclusive="0" does not keep NaN out, and NaN then slips past range checks in the code that reads the value, since every comparison with it is false. The four bound checks in JavaFloatHolderEx.validateValue and JavaDoubleHolderEx.validateValue now also fail when exactly one side is NaN. NaN against a NaN bound, and every non-NaN value, behave as before. After the fix all 128 cases agree with Xerces.

Cases added to IncomparableMinFacetValidateTest. nanFailsEveryBound fails on trunk and passes with the fix. ./gradlew test is otherwise green, apart from CompilationTests.partials and SaverTest.testLengthAssertion, which fail the same way on an untouched trunk checkout here on Windows (they look like line-ending issues).

JavaFloatHolder.compare and JavaDoubleHolder.compare order NaN above
every other value, so a NaN instance value passed minInclusive and
minExclusive, and a NaN max bound accepted every number. XML Schema
makes NaN equal to itself but incomparable with every other value, so
it satisfies no bound facet of a non-NaN bound. The four bound checks
in both holders now also fail when exactly one side is NaN.

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the change looks right to me: incomparable only fires when exactly one side is NaN, so it does not overlap with #174.

One request before approving: the tests only use a bound of 0. The description also says that NaN against a NaN bound behaves as before and that a NaN max bound no longer accepts every number, but neither is pinned by a test. Could you add cases with a NaN bound to IncomparableMinFacetValidateTest (NaN value vs NaN bound for each of the four facets, and a non-NaN value vs a NaN bound)?

Possible follow-up, not needed here: compareValue still returns 1/-1 for NaN against a number rather than 2 (incomparable).

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.

2 participants