Skip to content

fix(jaxrs): correct add/remove methods for JsonNullable<List<T>> fields#23258

Open
TheNevim wants to merge 2 commits intoOpenAPITools:masterfrom
TheNevim:master
Open

fix(jaxrs): correct add/remove methods for JsonNullable<List<T>> fields#23258
TheNevim wants to merge 2 commits intoOpenAPITools:masterfrom
TheNevim:master

Conversation

@TheNevim
Copy link

@TheNevim TheNevim commented Mar 15, 2026

Summary

This PR fixes the incorrect implementation of add and remove helper methods generated for JsonNullable<List> fields in JAX-RS models.

The generated code incorrectly treated the field as an ArrayList, while the actual type is JsonNullable<List>. This resulted in compilation errors in the generated models.

The fix updates the generated methods to correctly handle the JsonNullable wrapper and operate on the underlying list.

Changes

  • Corrected add and remove helper method implementations for JsonNullable<List> fields
  • Ensured proper access to the underlying list within JsonNullable
  • Fixed compilation errors in generated JAX-RS models

Result

Generated models now compile correctly and properly support add and remove operations for JsonNullable<List> fields.

Related Issue

Fixes #23251

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)

Summary by cubic

Fixes generated add/remove/put helpers for JsonNullable<List<T>> and JsonNullable<Map<String, T>> in JAX-RS models so they compile and correctly update the wrapped collections.

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

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 1 file

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="modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache:177">
P1: JsonNullable collection/map helpers incorrectly assume `isPresent()` implies non-null wrapped container, leading to NPE when wrapper is present with null (`JsonNullable.of(null)`).</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@TheNevim TheNevim requested a review from wing328 March 19, 2026 06:32
@wing328
Copy link
Member

wing328 commented Mar 20, 2026

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@TheNevim
Copy link
Author

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@wing328 Thanks for the notice, the commit should now be connected to my account.

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.

[BUG] [JAVA] [JAX-RS] Incorrect implementation of add/remove methods for JsonNullable<List<T>> fields in generated models

2 participants