Skip to content

reject a partly filled optional xs:all group in SchemaTypeVisitorImpl - #170

Merged
aizu-m merged 1 commit into
apache:trunkfrom
aizu-m:optional-all-group-required
Nov 23, 2026
Merged

aizu-m merged 1 commit into
apache:trunkfrom
aizu-m:optional-all-group-required

Conversation

@aizu-m

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

Copy link
Copy Markdown
Contributor

Differential run, XmlObject.validate() vs the JDK Xerces validator, schema <xs:all minOccurs="0"> a, b, c? </xs:all>:

<r><a>1</a></r>
     XB: VALID
     XE: INVALID cvc-complex-type.2.4.b: The content of element 'r' is not complete. One of '{"urn:t":b, "urn:t":c}' is expected.
<r><c/></r>
     XB: VALID
     XE: INVALID cvc-complex-type.2.4.b: The content of element 'r' is not complete. One of '{"urn:t":a, "urn:t":b}' is expected.

How it was found: I was diffing XmlBeans against Xerces over content-model variants. Sequence, choice and xs:all with minOccurs="1" all agreed. Only an optional all group disagreed, and a <xs:group ref> to an all group with minOccurs="0" does the same.

Observation: in the ALL case of SchemaTypeVisitorImpl.visit, a missing required member is only an error while _curCount < _curMin. With minOccurs="0" that is never true. Once the group is entered, any subset of its members is accepted. Required elements can be left out of an untrusted instance and it still validates, through XmlObject.validate() and ValidatingXMLStreamReader.

Conclusion: a started all group is committed, as the SEQUENCE case already treats it (_processedChildCount != 0). The fix adds that condition. An absent optional group, complete groups in any order, and minOccurs="1" behave as before. After the fix the xs:all disagreements are gone. OptionalAllGroupValidateTest fails before and passes after. The remaining local gradle test failures (CompilationTests.partials, SaverTest.testLengthAssertion) also fail on trunk on Windows (CRLF).

The ALL case of SchemaTypeVisitorImpl.visit only reported a missing
required member when the group had not reached its minOccurs. For an
xs:all with minOccurs='0' that is never the case, so once the group
was entered any subset of its members validated, e.g. only the
optional member. Treat a started all group as committed, as the
sequence case already does.

@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

@aizu-m
aizu-m merged commit 254a219 into apache:trunk Nov 23, 2026
3 checks passed
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