Skip to content

[JAVA] fix jspecify in java builders and toIndentedString - #24601

Closed
jpfinne wants to merge 33 commits into
OpenAPITools:masterfrom
jpfinne:feature/java_jspecifyChainSetter
Closed

[JAVA] fix jspecify in java builders and toIndentedString#24601
jpfinne wants to merge 33 commits into
OpenAPITools:masterfrom
jpfinne:feature/java_jspecifyChainSetter

Conversation

@jpfinne

@jpfinne jpfinne commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fix some missing @Nullable annotations for java clients:

  • add in builders
  • add in toIndentedString()

Add a sample for openapiNullable

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

Fixes JSpecify nullability in generated Java and Spring Boot 4 code so builder chain setters and all‑args constructors accept @nullable where expected, including for fully qualified types and generics. Adds new openApiNullable/useOptional sample configs, updates workflows/tests/samples, and cleans up generated FILES lists.

  • New Features

    • Apply @Nullable in builder setters via new nullableArgument_builder for Java and Spring (respects useOptional and optionalAcceptNullable in Spring).
    • Add @Nullable to Spring all‑args constructors when useJspecify is enabled.
    • Mark toIndentedString(Object o) as @Nullable across Java templates and all library variants.
    • New sample configs: spring-boot-4-jspecify-openapiNullable, spring-boot-4-jspecify-useOptional, and java-restclient-springBoot4-jackson3-jspecify-openapiNullable; CI workflows include them.
  • Bug Fixes

    • Correct enum nullable handling by using nullableDatatypeWithEnum in nullableArgumentWithEnum.mustache.
    • Fix JSpecify annotation placement with generics using getLastIndex in AbstractJavaCodegen.
    • Update nullable_var_annotations and Spring nullableAnnotation logic to honor useJspecify, openApiNullable, and useOptional (split into default and JSpecify variants).
    • Exclude tests from generated .openapi-generator/FILES to reduce noise in CI.

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

Review in cubic

jpfinne added 30 commits May 11, 2026 14:26
* handling of @nullable List<java.time.Instant>
* add @nullable for Spring all arg constructor + chain setter (only if useJspecify)
@jpfinne jpfinne changed the title [JAVA] fix jspecify in java builders [JAVA] fix jspecify in java builders and toIndentedString Aug 4, 2026
jpfinne added 3 commits August 4, 2026 15:22
Fix for:
The following artifacts could not be resolved: org.apache.maven.plugins:maven-enforcer-plugin:pom:3.4.0 (absent): Could not transfer artifact org.apache.maven.plugins:maven-enforcer-plugin:pom:3.4.0 from/to central (https://repo.maven.apache.org/maven2): status code: 429, reason phrase: Too Many Requests (429)
@jpfinne jpfinne closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant