Skip to content

[java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value - #24573

Merged
wing328 merged 4 commits into
masterfrom
chetan26-chet-fix/issue-24393
Aug 3, 2026
Merged

[java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value#24573
wing328 merged 4 commits into
masterfrom
chetan26-chet-fix/issue-24393

Conversation

@wing328

@wing328 wing328 commented Aug 3, 2026

Copy link
Copy Markdown
Member

based on #24395

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Handle null values in additionalProperties for the Java okhttp-gson generator. We now emit JsonNull during serialization and add the needed import to prevent runtime errors when additionalProperties contain nulls.

  • Bug Fixes
    • Update pojo.mustache: import com.google.gson.JsonNull and add JsonNull.INSTANCE when gson.toJsonTree(value) is isJsonNull().
    • Regenerate Java okhttp-gson samples to include the new import and null-handling logic.

Written for commit f4a6a57. Summary will update on new commits.

Review in cubic

@wing328 wing328 added this to the 7.25.0 milestone Aug 3, 2026
@wing328 wing328 changed the title Chetan26 chet fix/issue 24393 [java] fix CustomTypeAdapterFactory NPE-style crash on null additionalProperties value Aug 3, 2026
@wing328
wing328 marked this pull request as ready for review August 3, 2026 09:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@wing328
wing328 merged commit 26d186e into master Aug 3, 2026
476 of 530 checks passed
@wing328
wing328 deleted the chetan26-chet-fix/issue-24393 branch August 3, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants