Skip to content

fix(java): avoid oversized Gson oneOf constructors - #25539

Open
AndreyVMarkelov wants to merge 3 commits into
OpenAPITools:masterfrom
AndreyVMarkelov:andreymarkelov/fix-java-gson-large-oneof
Open

AndreyVMarkelov wants to merge 3 commits into
OpenAPITools:masterfrom
AndreyVMarkelov:andreymarkelov/fix-java-gson-large-oneof

Conversation

@AndreyVMarkelov

@AndreyVMarkelov AndreyVMarkelov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #25538

Java okhttp-gson clients with a large oneOf can compile but fail with ClassFormatError: Too many arguments in method signature. The generated anonymous adapter captures a separate constructor argument for each variant adapter.

For oneOf schemas with more than 100 variants, initialize variant adapters as fields of the anonymous adapter instead. This avoids exceeding the JVM constructor-parameter limit, including for container variants that may require multiple captured values. Smaller oneOf output remains unchanged.

Tests

  • JavaOkHttpGsonLargeOneOfTest: runtime compilation, adapter loading and JSON round trips for 2, 100, 101 and 260 variants. The 260-variant case fails on master with ClassFormatError and passes with the fix.
  • Generated and compiled a 260-variant client including array and map variants; its adapter loads.
  • Existing okhttp-gson-oneOf-array sample tests: 3 passed, 1 skipped.
  • Regenerated the okhttp-gson sample configurations; no sample changes.
  • Generated and compiled a full public specification with 637 variants in one model. On Java 21, verified adapter class loading, the factory handling an unrelated type, JSON header serialization, and obtaining the actual large model adapter. Verified FilesMetadata variants on Java 11.

The full public-spec compilation used a temporary generated-file workaround for the separate JSON.java initializer limit addressed by #25533. The synthetic regression and this PR do not depend on that change.

PR checklist

  • Read the contribution guidelines.
  • Run the full project build, regenerate all samples and export generator docs.
  • Notify the relevant technical committee members.

Summary by cubic

Fixes Java okhttp-gson clients with large oneOf schemas failing at runtime with ClassFormatError: Too many arguments in method signature. For oneOf schemas with more than 100 variants, variant adapters are now initialized as fields of the anonymous adapter instead of captured constructor arguments; smaller oneOf output is unchanged.

  • Variant adapters in large oneOf models are resolved through the enclosing CustomTypeAdapterFactory, avoiding the JVM constructor-parameter limit for both scalar and container variants.
  • Adds JavaOkHttpGsonLargeOneOfTest covering 2, 100, 101, and 260 variants with runtime compilation, adapter loading, and JSON round trips, including array and map variants.

Written for commit 6958a59. Summary will update on new commits.

View guided diff

@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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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.

[BUG][Java][okhttp-gson] Large oneOf adapter fails to load with too many constructor arguments

1 participant