Skip to content

Use defensive Date copies for SimpleMailMessage sentDate#36626

Merged
sbrannen merged 1 commit intospring-projects:mainfrom
bebeis:refactor/simple-mail-message
Apr 8, 2026
Merged

Use defensive Date copies for SimpleMailMessage sentDate#36626
sbrannen merged 1 commit intospring-projects:mainfrom
bebeis:refactor/simple-mail-message

Conversation

@bebeis
Copy link
Copy Markdown
Contributor

@bebeis bebeis commented Apr 8, 2026

Summary

This PR updates SimpleMailMessage to use defensive Date copies for sentDate.

Currently, SimpleMailMessage already copies its recipient arrays in copy paths, but sentDate can still be shared across instances if it is not copied consistently. As a result, external mutation of a shared Date reference can affect message state unexpectedly.

Changes

This change makes sentDate handling consistent by using defensive Date copies in the relevant paths.

Specifically:

  • setSentDate(Date) stores a defensive copy
  • getSentDate() returns a defensive copy
  • the copy constructor copies sentDate independently
  • copyTo(MailMessage) passes an independent Date instance

Rationale

This is a narrow change intended to preserve the existing behavior of SimpleMailMessage while avoiding accidental state mutation through shared mutable Date references.

Tests

I also added regression tests covering:

  • mutation of the input Date after calling setSentDate
  • mutation of the Date returned by getSentDate
  • copy constructor isolation for sentDate
  • copyTo(MailMessage) isolation for sentDate

Use defensive Date copies for sentDate to avoid shared mutable state.

Apply consistent handling in setSentDate, getSentDate, the copy constructor, and copyTo.

Add regression tests for mutation safety and copy isolation.

Signed-off-by: Junseo Bae <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 8, 2026
@sbrannen sbrannen changed the title Use defensive Date copies for SimpleMailMessage sentDate Use defensive Date copies for SimpleMailMessage sentDate Apr 8, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Apr 8, 2026
@sbrannen sbrannen self-assigned this Apr 8, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 8, 2026
@sbrannen sbrannen added this to the 7.1.0-M1 milestone Apr 8, 2026
sbrannen added a commit that referenced this pull request Apr 8, 2026
@sbrannen sbrannen merged commit 4b0101a into spring-projects:main Apr 8, 2026
5 checks passed
sbrannen added a commit that referenced this pull request Apr 8, 2026
@sbrannen
Copy link
Copy Markdown
Member

sbrannen commented Apr 8, 2026

This has been merged into main in 4b0101a and slightly revised in e654b2e.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants