Repository navigation
fix(java): avoid oversized Gson oneOf constructors - #25539
Open
AndreyVMarkelov wants to merge 3 commits into
Open
AndreyVMarkelov wants to merge 3 commits into
AndreyVMarkelov wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
…rator into andreymarkelov/fix-java-gson-large-oneof
This was referenced Nov 3, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #25538
Java
okhttp-gsonclients with a largeoneOfcan compile but fail withClassFormatError: Too many arguments in method signature. The generated anonymous adapter captures a separate constructor argument for each variant adapter.For
oneOfschemas 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. SmalleroneOfoutput 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 withClassFormatErrorand passes with the fix.okhttp-gson-oneOf-arraysample tests: 3 passed, 1 skipped.FilesMetadatavariants on Java 11.The full public-spec compilation used a temporary generated-file workaround for the separate
JSON.javainitializer limit addressed by #25533. The synthetic regression and this PR do not depend on that change.PR checklist
Summary by cubic
Fixes Java
okhttp-gsonclients with largeoneOfschemas failing at runtime withClassFormatError: Too many arguments in method signature. ForoneOfschemas with more than 100 variants, variant adapters are now initialized as fields of the anonymous adapter instead of captured constructor arguments; smalleroneOfoutput is unchanged.oneOfmodels are resolved through the enclosingCustomTypeAdapterFactory, avoiding the JVM constructor-parameter limit for both scalar and container variants.JavaOkHttpGsonLargeOneOfTestcovering 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.