Skip to content

stop at the first matching union member in XmlUnionImpl.set_text - #173

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:union-enum-first-member
Open

aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:union-enum-first-member

Conversation

@aizu-m

@aizu-m aizu-m commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

XmlUnionImpl.set_text tries the union's member types in order. When a member accepted the lexical value but that value was not in the union's enumeration, it carried on to the next member.

XML Schema Datatypes 2.5.1.3 says the first member type that accepts the lexical form gives the union its value, and the enumeration facet is assessed against that value only.

So with memberTypes='xs:int xs:boolean' and <xs:enumeration value='true'/>, the instance value 1 is the xs:int 1, which is not enumerated. It was instead reinterpreted as the boolean true and passed both XmlObject.validate() and ValidatingXMLStreamReader. Xerces reports cvc-enumeration-valid for the same document. The same happened for a union of a list type and an atomic type, and for an attribute of such a type.

Found by a differential run of XmlObject.validate() and ValidatingXMLStreamReader against the JDK Xerces validator. After the change the union enumeration disagreements are gone and no other case moves.

The fix stops at the first member that accepts the lexical form and rejects the value if it is not enumerated. Enumerated values, unions with no enumeration, and the non-validating second pass for lexically valid values are unaffected. Regression test added.

Behaviour change worth a release note: on a union that carries an enumeration facet, setStringValue("1") in the example above now throws XmlValueOutOfRangeException instead of silently becoming the boolean true. Only unions with an enumeration are affected, and it is the same exception set_text already threw for a value no member accepts.

@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.

lgtm

@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.

Two non-blocking notes:

  • This is a visible behaviour change outside validation too: setStringValue("1") on such a union now throws XmlValueOutOfRangeException where it used to silently become the boolean true. I think that is correct, but it deserves a line in the release notes.
  • The PR description is a single long sentence; splitting it up would make the commit message easier to read later.

@aizu-m

aizu-m commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Both fair. Split the description into short paragraphs, and spelled the setStringValue change out at the end of it so it lands in the squash commit and is ready to lift into the notes:

XmlUnionImpl: a union carrying an enumeration facet now rejects a lexical value that its first matching member type accepts but the enumeration does not, so setStringValue may throw XmlValueOutOfRangeException where it previously took a value from a later member.

Your reading of it is right: check() only returns false when there's an enumeration, so nothing else can reach the new throw. CHANGES.txt says it hasn't been updated since V5.0.1 and points at status.html, so I've left it untouched rather than reopen it. Say the word if you'd rather the line went there, or somewhere else.

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