Skip to content

[core] Fix UnsupportedOperationException for oneOf members declaring x-implements (#23577)#24076

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-23577-x-implements-immutable-list
Jun 21, 2026
Merged

[core] Fix UnsupportedOperationException for oneOf members declaring x-implements (#23577)#24076
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-23577-x-implements-immutable-list

Conversation

@seonwooj0810

@seonwooj0810 seonwooj0810 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #23577

Problem

When a schema is a member of a oneOf and also declares its own x-implements in the spec, generation crashes with java.lang.UnsupportedOperationException during model post-processing:

java.lang.UnsupportedOperationException
    at java.util.AbstractList.add(AbstractList.java:155)
    at org.openapitools.codegen.utils.OneOfImplementorAdditionalData.addToImplementor(OneOfImplementorAdditionalData.java:111)
    at org.openapitools.codegen.DefaultCodegen.postProcessAllModels(DefaultCodegen.java:577)
    ...

addToImplementor did putIfAbsent(X_IMPLEMENTS, new ArrayList<>()) and then List.add(...) on the stored value. When the model already carries x-implements from the spec, that value is the parser-supplied object (a scalar string or an immutable list), so putIfAbsent is a no-op and the subsequent add fails.

This is the default oneOf-interface code path. The existing oneOf_issue_23577 test only covers the REPLACE_ONE_OF_BY_DISCRIMINATOR_MAPPING normalizer path, which converts oneOf to inheritance and never reaches this code — so the default path remained broken.

Fix

Normalize the existing x-implements value into a fresh mutable list (preserving any user-supplied interfaces, whether stored as a scalar string or a list) before appending the oneOf interface. Models without a pre-existing x-implements are unaffected — the result is identical to the previous putIfAbsent(new ArrayList<>()) behavior.

Test evidence

Added SpringCodegenTest#oneOf_issue_23577_userDefinedXImplements, which generates the reporter's spec on the default oneOf-interface path (no normalizer) and asserts the member implements both its declared interface and the oneOf parent:

  • CreatedEvent implements com.example.Notification and Event
  • UpdatedEvent implements Event

Confirmed the new test fails with UnsupportedOperationException before the change and passes after. The pre-existing oneOf_issue_23577 and OneOfImplementorAdditionalDataTest still pass.

Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

No generated samples change (the previously-crashing combination produced no committed samples; the no-x-implements path is byte-for-byte unchanged), so no sample regeneration is included.

Verification done: (1) no in-flight PR (searched open PRs for x-implements/OneOfImplementor/#23577); (2) no claim comments on the issue; (3) code fix in .java only; (4) reproduced the crash on upstream/master via a failing test, then confirmed the fix; (5) no parent epic.


Summary by cubic

Fixes a crash when a oneOf member also declares its own x-implements. We now normalize existing x-implements to a mutable list before adding the oneOf interface.

  • Bug Fixes
    • Convert pre-existing x-implements (string or immutable list) into a new mutable list before appending oneOf interfaces; models without x-implements are unchanged.
    • Add test oneOf_issue_23577_userDefinedXImplements to verify members implement both the user-defined interface(s) and the oneOf parent.

Written for commit bac76e7. Summary will update on new commits.

Review in cubic

)

OneOfImplementorAdditionalData.addToImplementor used putIfAbsent + List.add
on the model's x-implements vendor extension. When a oneOf member schema
already declares x-implements in the spec, the parsed value is a scalar
string or an immutable list, so appending the oneOf interface threw
java.lang.UnsupportedOperationException during model post-processing.

Normalize the existing value into a fresh mutable list (preserving any
user-supplied interfaces) before appending. No behavior change for models
without a pre-existing x-implements.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

Re-trigger cubic

@wing328

wing328 commented Jun 21, 2026

Copy link
Copy Markdown
Member

tested locally to confirm no longer get the UnsupportedOperationException.

@wing328 wing328 merged commit b634273 into OpenAPITools:master Jun 21, 2026
15 checks passed
@wing328 wing328 added this to the 7.24.0 milestone Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Exception when using x-implements with allOf with spring generator

2 participants