fix(java): avoid oversized Gson oneOf constructors

AN
12h ago
+124-3

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.