Skip to content

Move @Valid onto list type arguments - #104

Open
mklocek wants to merge 1 commit into
mainfrom
fix-valid-on-containers
Open

mklocek wants to merge 1 commit into
mainfrom
fix-valid-on-containers

Conversation

@mklocek

@mklocek mklocek commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Hibernate Validator 9 deprecates @Valid on container fields, so the SDK logged HV000271: Using @Valid on a container (java.util.List) is deprecated whenever a request was validated. Validation itself still worked; this removes the warning.

Changes

  • Moved @Valid from List fields onto their element types (List<@Valid Address>, etc.) in MailtrapMail, MailtrapBatchMail, BatchEmailBase, InboundForwardRequest and InboundReplyRequest
  • Added a test checking that an invalid address inside the to list is still reported

Summary by CodeRabbit

  • Bug Fixes
    • Validation now checks each recipient, attachment, and batch email individually, reporting errors for invalid list entries.

Hibernate Validator 9 deprecates @Valid on container fields and logs
HV000271 at runtime. Put @Valid on the List element type instead, so
nested elements are still validated without the warning.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The request models place @Valid on collection elements for addresses, attachments, and batch mail requests. A test checks that an invalid second recipient produces an error at to[1].email.

Changes: Request validation

Layer / File(s) Summary
Element-level validation
src/main/java/io/mailtrap/model/request/emails/*, src/main/java/io/mailtrap/model/request/inbound/InboundForwardRequest.java, src/main/java/io/mailtrap/model/request/inbound/InboundReplyRequest.java, src/test/java/io/mailtrap/MailtrapValidatorTest.java
Email and inbound request models apply @Valid to collection elements. MailtrapMail.to retains @NotEmpty. The validator test checks the error path for an invalid second recipient.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: vitalii-t

Merge Risk: Minimal · up to fd905

This change moves nested validation onto list elements to avoid a Hibernate Validator 9 warning, and invalid recipients should still be reported. No concrete merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: @Valid moves from List fields onto the list element type arguments. The raw summary and PR objectives describe the same change across the five request classes. The tit…
Description check Passed The description states the motivation: Hibernate Validator 9 deprecates @Valid on container fields and logs HV000271, and this change removes that warning. It lists the changes to MailtrapMail, Mailtr…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: @Valid moves from List fields onto the list element type arguments. The raw summary and PR objectives describe the same change across the five request classes. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description states the motivation: Hibernate Validator 9 deprecates @Valid on container fields and logs HV000271, and this change removes that warning. It lists the changes to MailtrapMail, MailtrapBatchMail, BatchEmailBase, InboundForwardRequest, and InboundReplyRequest, and it notes the added test. The description does not follow the template's required sections: it has no 'How to test' checklist and no 'Images and GIFs' section. The Motivation heading is present but is not labeled as such. Those gaps are minor, so the check passes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ec3a9311-12b0-4468-9564-b97111dd1e85
Commits

Reviewing files that changed from the base of the PR and between d21eb18 and fd90590.

Files selected for processing: 6

  • src/main/java/io/mailtrap/model/request/emails/BatchEmailBase.java
  • src/main/java/io/mailtrap/model/request/emails/MailtrapBatchMail.java
  • src/main/java/io/mailtrap/model/request/emails/MailtrapMail.java
  • src/main/java/io/mailtrap/model/request/inbound/InboundForwardRequest.java
  • src/main/java/io/mailtrap/model/request/inbound/InboundReplyRequest.java
  • src/test/java/io/mailtrap/MailtrapValidatorTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@mklocek
mklocek enabled auto-merge December 4, 2026 07:27
@mklocek
mklocek disabled auto-merge December 4, 2026 07:27

This branch has not been deployed

No deployments
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.

2 participants