Skip to content

ST6RI-976 Metadata stack overflow - #817

Merged
seidewitz merged 2 commits into
masterfrom
ST6RI-976
Oct 20, 2026
Merged

seidewitz merged 2 commits into
masterfrom
ST6RI-976

Conversation

@seidewitz

@seidewitz seidewitz commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

This PR fixes a bug that causes a StackOverflowError when a metaclass/metadata definition is annotated with itself.

Issue

A self-referential metadata applications such as this one in KerML:

metaclass M {
    metadata M;
}

or this one in SysML:

metadata def M {
    metadata M;
}

result in a StackOverflowError during validation.

Cause

The method TypeAdapter.getBaseTypes is called during implied specialization processing for a Type. It checks all the metadata annotations of a type (if any). If it finds any semantic metadata, it returns the appropriate baseTypes to be specialized.

Method TypeAdapter.getBaseTypes previously made a call on getMetaclass for each metadata feature it checked. This call was added in PR #744 (ST6RI-923 Problem with name resolution when using Semantic metadata). The returned type from this call is not actually used; the reason for the call is just to ensure the proxies are resolved and the metaclass type is available.

The delegate implementing getMetaclass calls FeatureUtil.getFirstTypeOf, which leads to the following call chain:

  • FeatureUtil.getFirstTypeOf
    • FeatureUtil.getAllTypesOf
      • FeatureAdapter.getAllTypes
        • FeatureAdapter.getTypes
        • FeatureAdapter.removeRedundantTypes

When there is a self-referential annotation, as in the examples above, recursion leading to the stack overflow happens through removeRedundantTypes, while looking for other supertypes of the metaclass/metadata def.

Changes

Replaced the getMetaclass call in getBaseTypes with a call to FeatureUtil.getTypesOf, which provides access to the lower-level method FeatureAdapter.getTypes. By avoiding calling removeRedundantTypes, this resolves the stack overflow issue, while preserving the fix of PR #744.

- This avoids calling removeRedundantTypes, which actually caused the
stack overflow.
- It also allows visited features to be carried across metadataFeature
iterations.

All tests pass.
@seidewitz seidewitz added this to the 2026-09 milestone Oct 16, 2026
@seidewitz seidewitz self-assigned this Oct 16, 2026
@seidewitz seidewitz added the bug Something isn't working label Oct 16, 2026
@seidewitz
seidewitz requested a review from vincemolnar October 16, 2026 22:34
@seidewitz

Copy link
Copy Markdown
Member Author

@vincemolnar
Please review this PR as soon as possible so it can be included in the 2026-09 release.

@seidewitz

seidewitz commented Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

@vincemolnar
Please review this PR by Tuesday morning (20 Oct), Eastern Time.

@vincemolnar vincemolnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have confirmed that the fixes prevent the stack overflow for all the previously identified examples.

@seidewitz
seidewitz merged commit b36253a into master Oct 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants