Skip to content

Commit 4420c92

Browse files
committed
Adapt Kotlin null-safety with Spring Framework changes
Closes gh-47428
1 parent da8eac3 commit 4420c92

File tree

1 file changed

+3
-8
lines changed
  • documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features

1 file changed

+3
-8
lines changed

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ It deals with `null` values at compile time rather than deferring the problem to
3838
This helps to eliminate a common source of bugs without paying the cost of wrappers like javadoc:java.util.Optional[].
3939
Kotlin also allows using functional constructs with nullable values as described in this https://www.baeldung.com/kotlin-null-safety[comprehensive guide to null-safety in Kotlin].
4040

41-
Although Java does not allow one to express null-safety in its type system, Spring Framework, Spring Data, and Reactor now provide null-safety of their API through tooling-friendly annotations.
42-
By default, types from Java APIs used in Kotlin are recognized as {url-kotlin-docs}/java-interop.html#null-safety-and-platform-types[platform types] for which null-checks are relaxed.
43-
{url-kotlin-docs}/java-interop.html#nullability-annotations[Kotlin's support for nullability annotations] provides null-safety for the annotated APIs like Spring's one in Kotlin.
41+
Although Java does not let you express null-safety in its type-system, most Spring projects
42+
provide {url-spring-framework-docs}/core/null-safety.html[null-safety] via https://jspecify.dev/[JSpecify] annotations.
4443

45-
The https://jspecify.dev[JSpecify] strict checks are https://kotlinlang.org/docs/whatsnew21.html#change-of-jspecify-nullability-mismatch-diagnostics-severity-to-strict[enabled by default], while the JSR 305 checks can be configured by adding the `-Xjsr305` compiler flag with the following options: `-Xjsr305={strict|warn|ignore}`.
46-
The default behavior is the same as `-Xjsr305=warn`.
47-
The `strict` value is required to have null-safety taken in account in Kotlin types inferred from Spring API but should be used with the knowledge that Spring API nullability declaration could evolve even between minor releases and more checks may be added in the future).
48-
49-
WARNING: Be aware that Spring Boot's own API is {url-github-issues}/10712[not yet annotated].
44+
As of Kotlin 2.1, Kotlin enforces strict handling of nullability annotations from the `org.jspecify.annotations` package.
5045

5146

5247

0 commit comments

Comments
 (0)