fix(java): avoid oversized Gson oneOf constructors
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 withClassFormatErrorand passes with the fix.- Generated and compiled a 260-variant client including array and map variants; its adapter loads.
- Existing
okhttp-gson-oneOf-arraysample 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
FilesMetadatavariants 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
oneOfmodels are resolved through the enclosingCustomTypeAdapterFactory, avoiding the JVM constructor-parameter limit for both scalar and container variants. - Adds
JavaOkHttpGsonLargeOneOfTestcovering 2, 100, 101, and 260 variants with runtime compilation, adapter loading, and JSON round trips, including array and map variants.