[java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value - #24573
Merged
Conversation
wing328
marked this pull request as ready for review
August 3, 2026 09:36
Contributor
There was a problem hiding this comment.
1 issue found across 248 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AppleReq.java">
<violation number="1" location="samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AppleReq.java:32">
P3: The newly added `import com.google.gson.JsonNull;` in AppleReq.java is dead code — `JsonNull` is never referenced anywhere else in this file (it has no additionalProperties handling). Please gate the import emission in the Java pojo.mustache template on the same condition that produces the `JsonNull.INSTANCE` branch so regenerated samples don't carry an unused import.</violation>
</file>
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
| import com.google.gson.JsonDeserializer; | ||
| import com.google.gson.JsonElement; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonNull; |
Contributor
There was a problem hiding this comment.
P3: The newly added import com.google.gson.JsonNull; in AppleReq.java is dead code — JsonNull is never referenced anywhere else in this file (it has no additionalProperties handling). Please gate the import emission in the Java pojo.mustache template on the same condition that produces the JsonNull.INSTANCE branch so regenerated samples don't carry an unused import.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AppleReq.java, line 32:
<comment>The newly added `import com.google.gson.JsonNull;` in AppleReq.java is dead code — `JsonNull` is never referenced anywhere else in this file (it has no additionalProperties handling). Please gate the import emission in the Java pojo.mustache template on the same condition that produces the `JsonNull.INSTANCE` branch so regenerated samples don't carry an unused import.</comment>
<file context>
@@ -29,6 +29,7 @@
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.JsonNull;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
</file context>
Closed
5 tasks
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.
based on #24395
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Handle null values in additionalProperties for the Java
okhttp-gsongenerator. We now emitJsonNullduring serialization and add the needed import to prevent runtime errors when additionalProperties contain nulls.pojo.mustache: importcom.google.gson.JsonNulland addJsonNull.INSTANCEwhengson.toJsonTree(value)isisJsonNull().okhttp-gsonsamples to include the new import and null-handling logic.Written for commit f4a6a57. Summary will update on new commits.