Use defensive Date copies for SimpleMailMessage sentDate#36626
Merged
sbrannen merged 1 commit intospring-projects:mainfrom Apr 8, 2026
Merged
Use defensive Date copies for SimpleMailMessage sentDate#36626sbrannen merged 1 commit intospring-projects:mainfrom
Date copies for SimpleMailMessage sentDate#36626sbrannen merged 1 commit intospring-projects:mainfrom
Conversation
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]>
Date copies for SimpleMailMessage sentDate
sbrannen
added a commit
that referenced
this pull request
Apr 8, 2026
sbrannen
added a commit
that referenced
this pull request
Apr 8, 2026
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates
SimpleMailMessageto use defensiveDatecopies forsentDate.Currently,
SimpleMailMessagealready copies its recipient arrays in copy paths, butsentDatecan still be shared across instances if it is not copied consistently. As a result, external mutation of a sharedDatereference can affect message state unexpectedly.Changes
This change makes
sentDatehandling consistent by using defensiveDatecopies in the relevant paths.Specifically:
setSentDate(Date)stores a defensive copygetSentDate()returns a defensive copysentDateindependentlycopyTo(MailMessage)passes an independentDateinstanceRationale
This is a narrow change intended to preserve the existing behavior of
SimpleMailMessagewhile avoiding accidental state mutation through shared mutableDatereferences.Tests
I also added regression tests covering:
Dateafter callingsetSentDateDatereturned bygetSentDatesentDatecopyTo(MailMessage)isolation forsentDate