Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SimpleMailMessage nullability annotations #29139

Closed
wants to merge 2 commits into from

Conversation

stgerhardt
Copy link
Contributor

Fixes the nullability annotations in SimpleMailMessage so the set*(...) methods have their parameters marked as @Nullable.

These method parameters had no annotations and when SimpleMailMessage is used from Kotlin with -Xjsr305=strict enabled, the set*(...) methods were treated as being marked @NonNull. This also meant Kotlin would not see matched pairs of get/set methods as var properties, so calling message.text = "Text" would not compile in Kotlin.

Adds tests in SimpleMailMessageJsr305ComplianceTests.kt that verify the nullability annotations for SimpleMailMessage are correct. This file will actually fail to compile if the nullability annotations are missing, causing the tests to fail.

Also modifies spring-context-support.gradle to force the Kotlin test code to compile with -Xjsr305=strict, enabling the test code to work properly.

@stgerhardt
Copy link
Contributor Author

Apologies for the force push on my fork - forgot to set my git command line email properly and wanted to fix it.

Fixes the nullability annotations in `SimpleMailMessage` so the
`set*(...)` methods have their parameters marked as `@Nullable`.

These method parameters had no annotations and when `SimpleMailMessage`
is used from Kotlin with `-Xjsr305=strict` enabled, the `set*(...)`
methods were treated as being marked `@NonNull`. This also meant Kotlin
would not see matched pairs of get/set methods as `var` properties, so
calling `message.text = "Text"` would not compile in Kotlin.

Adds tests in `SimpleMailMessageJsr305ComplianceTests.kt` that verify
the nullability annotations for `SimpleMailMessage` are correct. This
file will actually fail to compile if the nullability annotations are
missing, causing the tests to fail.

Also modifies `spring-context-support.gradle` to force the Kotlin test
code to compile with `-Xjsr305=strict`, enabling the test code to work
properly.
Improves test code in `SimpleMailMessageJsr305ComplianceTests.kt`. Adds
more comments and greatly simplified the unsafe vararg call helper
function compared to its initial implementation. Adds a few extra tests
as well.
@sdeleuze sdeleuze self-assigned this Sep 23, 2022
@sdeleuze sdeleuze added this to the 5.3.24 milestone Sep 23, 2022
@sdeleuze sdeleuze added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 23, 2022
sdeleuze pushed a commit to sdeleuze/spring-framework that referenced this pull request Nov 2, 2022
@sdeleuze sdeleuze closed this in fded79d Nov 2, 2022
@sdeleuze
Copy link
Contributor

sdeleuze commented Nov 2, 2022

Merged via fded79d without the testFunction method. Thanks for the Kotlin tests, but for the sake of consistency and since we intend to introduce later globally null-safety validation during the build, I did not introduce them.

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) theme: kotlin An issue related to Kotlin support type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants