[Java][Spring] useRecords: no @NotNull on records without bean validation

Merged
SE
1d ago
+28-3

#25131 removed @NotNull and its import from classes when useBeanValidation is off. The record template from #25200 still printed the annotation, so with useRecords and useBeanValidation=false a record with a required property stopped compiling. Records now follow classes there. With bean validation on, or useRecords off, the output is unchanged.

@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim

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 the Java Spring record template emitting @NotNull on required fields when useBeanValidation is off, which produced records that did not compile because the annotation import was missing. Records now match the classes behavior and emit no bean validation annotations when validation is disabled. Output is unchanged when bean validation is on or useRecords is off.

Adds regression tests covering record generation with and without bean validation.