fix(java): batch Gson model adapter registration
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#testOkHttpGsonBatchesModelAdapterRegistrationsverifies 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
FilesMetadatavariants 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.