Skip to content

build the complete attribute wildcard of restrictions from their attribute groups - #168

Merged
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:attr-wildcard-restriction
Nov 15, 2026
Merged

pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:attr-wildcard-restriction

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Follow-up to #167, which fixed the complete attribute wildcard (XML Schema 1.0 3.4.2) for plain complex types and extensions but left restrictions as they were.

Restriction bug. At the end of translateAttributeModel, a restriction with no anyAttribute resets the inherited wildcard. That reset also ran at the end of each attribute group's recursive call, and for the type itself when the wildcard came only from groups. So

<xs:restriction base="t:any"><xs:attributeGroup ref="t:ab"/></xs:restriction>

ended up with no attribute wildcard at all, and urn:a/urn:b attributes were rejected. Each wildcard was also checked against the base type's wildcard on its own. A group wildcard wider than the base therefore failed derivation-ok-restriction.4.2, even when the combined wildcard was a subset.

Fix. Restrictions now build the complete wildcard the same way extensions do. The type's own anyAttribute and its attribute group wildcards are intersected, and derivation-ok-restriction.4.1/4.2 are checked once, against the complete wildcard. processContents comes from the type's own anyAttribute, or else from the first attribute group wildcard, which matches Xerces. The top-level call versus a group's recursive call is now an explicit private overload, instead of #167's seenAttributes == null check.

Opt-out. XmlOptions.setCompileLegacyAttributeWildcards() (compile time, @since 6.0.0) restores the pre-6.0.0 handling. That covers both the union of a type's own wildcards that #167 replaced and the old restriction behaviour. The attribute model is stored in the compiled type system, so precompiled .xsb jars keep their wildcards either way.

AttributeWildcardRestrictionTest covers:

  • a restriction whose wildcard comes only from a group;
  • a group intersected with a local wildcard;
  • where processContents comes from;
  • the subset check on the complete wildcard;
  • the 4.1 and 4.2 errors;
  • the legacy option.

🤖 Generated with Claude Code

…ibute groups

A restriction dropped any attribute wildcard that came only from its
attribute groups: the inherited-wildcard reset at the end of
translateAttributeModel also ran for every attribute group, and for the
type itself when it had no anyAttribute of its own. Each wildcard was also
checked against the base type's wildcard on its own, so a group wildcard
wider than the base failed even when the combined wildcard was a subset.

Restrictions now build the complete wildcard like extensions do
(XML Schema 1.0 3.4.2): the type's own anyAttribute and its attribute group
wildcards are intersected, and derivation-ok-restriction.4 is checked once
against the complete wildcard. processContents comes from the type's own
anyAttribute, or else from the first attribute group wildcard, as Xerces does.

XmlOptions.setCompileLegacyAttributeWildcards() restores the pre-6.0.0
handling, including the union of a type's own wildcards that apache#167 replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pjfanning
pjfanning merged commit 356dc2e into apache:trunk Nov 15, 2026
3 checks passed
@pjfanning
pjfanning deleted the attr-wildcard-restriction branch November 15, 2026 21:01
pjfanning added a commit that referenced this pull request Nov 16, 2026
Since #168 a restriction's attribute wildcard takes processContents from
its own anyAttribute, so Any2LocalT's ##local wildcard is strict rather
than the base type's skip. No global no-namespace attribute is declared,
so an unqualified attribute is not resolved, as Xerces also reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pjfanning added a commit that referenced this pull request Nov 16, 2026
Only the XSD files were inputs, so a change to the schema compiler in
src/main/java reused stale generated sources from the build cache. That
hid the AttrWCRestriction failure from #168 locally while CI, without a
cache, reported it. The test SchemaGen tasks now also depend on
bootstrapMigrate, which builds the compiler classes they run, and the sEXT
classpath keeps the task dependencies of the main source set output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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