[java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value#24395
Open
chetan26 wants to merge 2 commits into
Open
[java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value#24395chetan26 wants to merge 2 commits into
chetan26 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 248 files
Note: This PR contains a large number of files. cubic only reviews up to 200 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
Re-trigger cubic
chetan26
force-pushed
the
chet-fix/issue-24393
branch
from
July 23, 2026 17:30
e706e24 to
a5d0787
Compare
chetan26
commented
Jul 24, 2026
| else { | ||
| JsonElement jsonElement = gson.toJsonTree(entry.getValue()); | ||
| if (jsonElement.isJsonArray()) { | ||
| if (jsonElement.isJsonNull()) { |
Contributor
There was a problem hiding this comment.
@chetan26 I have started the AI code review. It will take a few minutes to complete.
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.
Title:
[java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value
Body:
PR checklist
./mvnw clean package
./bin/generate-samples.sh ./bin/configs/*.yaml
./bin/utils/export_docs_generators.sh
Commit all changed files.
masterDescription
Follow-up to #14404 / #17812.
That fix made
pojo.mustache's generatedCustomTypeAdapterFactory.write()handle JSON arrays inadditionalProperties, but theelsebranch still callsgetAsJsonObject()unconditionally:If an
additionalProperties: truemodel has an undeclared-property entry whose value isnull(e.g. an unknown field the server returned as JSONnull),gson.toJsonTree(null)returnsJsonNull.INSTANCE, and.getAsJsonObject()on that throws:java.lang.IllegalStateException: Not a JSON Object: null at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:90)This adds an
isJsonNull()check ahead of the array/object branches, mirroring the same pattern #17812 used for arrays:Fixes #24393
How to validate
Regenerated all
java-okhttp-gson*sample configs (bin/configs/java-okhttp*.yaml) — diff is uniform and confined to theadditionalPropertiesblock (newJsonNullimport + theisJsonNull()branch) in every model that hasadditionalProperties: true.Compiled the regenerated
samples/client/petstore/java/okhttp-gsonproject (mvn compile) — builds clean.Ran the existing
JavaClientCodegenTestsuite: 263/263 passed, no regressions.Verified end-to-end against the regenerated
AdditionalPropertiesClass: toJson()no longer throws for a null-valued additional property.Summary by cubic
Fix crash in generated
CustomTypeAdapterFactory.write()for Javaokhttp-gsonmodels whenadditionalPropertiescontainsnull. Nulls are now serialized asJsonNullto avoidIllegalStateException.isJsonNull()branch and writeJsonNull.INSTANCEbefore array/object handling inadditionalPropertiesinpojo.mustache.java-okhttp-gson*samples (addsJsonNullimport and null branch); remove unused imports; samples compile and existing tests pass.Written for commit a5d0787. Summary will update on new commits.