Skip to content

[Bug] resolve bare same-document href references; fixes #192#193

Merged
samatstariongroup merged 2 commits into
developmentfrom
fix/bare-same-document-href-192
Jul 1, 2026
Merged

[Bug] resolve bare same-document href references; fixes #192#193
samatstariongroup merged 2 commits into
developmentfrom
fix/bare-same-document-href-192

Conversation

@samatstariongroup

Copy link
Copy Markdown
Member

Summary

The XMI reader dropped cross-reference children whose href is a bare same-document fragment (href="#id"), while the cross-document form (href="file#id") resolved correctly. Observed for <subsettedProperty> / <redefinedProperty> but the cause was generic href resolution, so it affected every href-based reference element.

Fixes #192. Downstream: STARIONGROUP/SysML2.NET#315.

Root cause

The element cache is keyed by {DocumentName}#{XmiId} (XmiElement.FullyQualifiedIdentifier). In Assembler.TryGetReferencedElement the lookup key was built with referenceIdKey.Contains("#"): a bare #id contains #, so it was used verbatim as the key and never matched documentName#id — the reference was silently dropped (only a warning logged).

Change

Assembler.TryGetReferencedElement now inspects the position of #:

  • hashIndex > 0 → a document part is present (file#id) → used as-is
  • otherwise → a bare id (id, from xmi:idref) or a bare same-document fragment (#id) → normalized to {documentName}#{id}

This is the single, generic resolution point every href-based reference flows through (subsettedProperty, redefinedProperty, type, general, …), so the fix is uniform. ExternalReferenceResolver already correctly treated bare fragments as same-document, so no change was needed there.

Tests

  • AssemblerTestFixture — unit tests for the bare-fragment single-value and multi-value resolution paths (each fails without the fix, passes with it).
  • SysML2.XmiReaderTestFixture — end-to-end regression test against the real SysML2 model. Reads SysML_only_xmi.uml (plus cross-document KerML_only_xmi.uml) and asserts directedUsage.SubsettedProperty resolves both the cross-document reference (directedFeature) and the bare same-document reference (usage). Without the fix this model dropped the bare #id reference (count 1 instead of 2, plus ~38 "not found in cache" warnings across the model).

Verification

  • New regression test fails on the pre-fix Assembler and passes after.
  • Full uml4net.xmi.Tests suite green (54/54).
  • Confirmed the fix does not change uml4net's own generated code: the UML.xmi metamodel contains zero bare href="#" references, and regenerating through the patched Assembler produces byte-for-byte identical AutoGenClasses/AutoGenInterfaces (CorePocoGenerator exact-match tests pass).

Notes

  • Adds resources/SySML2/SysML_only_xmi.uml and KerML_only_xmi.uml as test fixtures (wired into TestData via the test csproj).

The XMI reader dropped cross-reference children whose href is a bare
same-document fragment (href=#id), while the cross-document form
(href=file#id) resolved correctly. A bare #id contains #, so the
Assembler used it verbatim as the cache lookup key, but the cache is
keyed by {DocumentName}#{XmiId} - the lookup therefore never matched
and the reference was silently dropped.

Assembler.TryGetReferencedElement now inspects the position of #:
a document part (hashIndex > 0, e.g. file#id) is used as-is, while a
bare id or a bare same-document fragment is normalized to the current
document. This is the single, generic resolution point every
href-based reference flows through (subsettedProperty,
redefinedProperty, type, general, ...), so the fix is uniform.

Tests:
- AssemblerTestFixture: unit tests for the bare-fragment single- and
  multi-value paths.
- SysML2.XmiReaderTestFixture: end-to-end regression test against the
  real SysML2 model (SysML_only_xmi.uml + KerML_only_xmi.uml) asserting
  directedUsage.SubsettedProperty resolves both the cross-document
  (directedFeature) and bare same-document (usage) references.
…s pathmap

Commit resources/SySML2/PrimitiveTypes.xmi and point the SysML2 reader
test's UMLPrimitiveTypes pathmap at it (instead of borrowing the UML
copy), so the SysML2 fixtures resolve every reference on their own.

Assert that the pathmap-typed 'isReference' attribute resolves to the
Boolean primitive, proving the model is fully assembled.
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

@samatstariongroup
samatstariongroup merged commit cef3f84 into development Jul 1, 2026
8 checks passed
@samatstariongroup
samatstariongroup deleted the fix/bare-same-document-href-192 branch July 1, 2026 08:03
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.

XMI reader drops cross-reference children with bare same-document href (href=#id not resolved)

2 participants