Skip to content

fix(java): batch Gson model adapter registration - #25533

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

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

Conversation

@AndreyVMarkelov

@AndreyVMarkelov AndreyVMarkelov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #25532

Java okhttp-gson clients with thousands of models can fail compilation because the generated JSON.java static initializer exceeds the JVM method-size limit.

Group model adapter registrations into helper methods of at most 200 registrations, preserving their original order. Specifications with at most 200 registered models retain the existing output.

Tests

  • JavaClientCodegenTest#testOkHttpGsonBatchesModelAdapterRegistrations verifies both batches and every generated registration for 201 models.
  • A synthetic 6000-model specification fails to compile before the change and compiles afterward. The order of all 6000 adapter registrations is identical.
  • Generated and compiled a public specification with 5822 registered adapters; verified three FilesMetadata variants and JSON header serialization.
  • Regenerated the okhttp-gson sample configurations; no sample changes.
  • git diff --check.

A separate local runtime observation: Homebrew OpenJDK 21.0.12.1 crashed while loading a very large generated model during the header probe. The probe passed with Java 11, Java 27, and Java 21 with -Xint. The cause of that JVM crash has not been determined; it is outside the compilation fix in this PR.

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 #25532. Java okhttp-gson clients with thousands of models previously failed compilation because the generated JSON.java static initializer exceeded the JVM method-size limit. Model adapter registrations are now grouped into helper methods of at most 200 registrations each, preserving their original order. Specifications with at most 200 registered models keep the existing output, and the batching behavior is documented in the generator docs.

Written for commit 0ad1d5a. 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.

No issues found across 3 files

View guided diff | Re-trigger cubic

public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
generateYAMLSpecFile(objs);
if (isLibrary(OKHTTP_GSON)) {
@SuppressWarnings("unchecked")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add comments explaining what this new block code does. thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a comment explaining that adapter registrations are split into batches to avoid exceeding the JVM method size limit. The original registration order is preserved.

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] JSON.java fails to compile with many model adapters

2 participants