Replace @OptionalParameter with JSpecify's @Nullable

This commit removes OptionalParameter in favor of the nullness support
introduced in Spring Framework 7. The parameter of an action can now
be flagged as optional using JSpecify's @Nullable, and simplifies the
setup for those who are using JSpecify as only a single annotation is
required.

Closes gh-45390
This commit is contained in:
Stéphane Nicoll
2025-09-10 15:01:43 +02:00
parent ee83ff5f6a
commit d7c482aa16
30 changed files with 71 additions and 345 deletions
@@ -412,7 +412,7 @@ Operations on an endpoint receive input through their parameters.
When exposed over the web, the values for these parameters are taken from the URL's query parameters and from the JSON request body.
When exposed over JMX, the parameters are mapped to the parameters of the MBean's operations.
Parameters are required by default.
They can be made optional by annotating them with either javadoc:org.springframework.boot.actuate.endpoint.annotation.OptionalParameter[format=annotation] or JSpecify's javadoc:org.jspecify.annotations.Nullable[format=annotation].
They can be made optional by annotating them with JSpecify's javadoc:org.jspecify.annotations.Nullable[format=annotation].
Kotlin null safety is also supported.
You can map each root property in the JSON request body to a parameter of the endpoint.
@@ -544,7 +544,7 @@ When using Spring MVC or Spring Web Flux, operations that return a javadoc:org.s
==== Web Endpoint Security
An operation on a web endpoint or a web-specific endpoint extension can receive the current javadoc:java.security.Principal[] or javadoc:org.springframework.boot.actuate.endpoint.SecurityContext[] as a method parameter.
The former is typically used in conjunction with either javadoc:org.springframework.boot.actuate.endpoint.annotation.OptionalParameter[format=annotation] or javadoc:org.jspecify.annotations.Nullable[format=annotation] to provide different behavior for authenticated and unauthenticated users.
The former is typically used in conjunction with javadoc:org.jspecify.annotations.Nullable[format=annotation] to provide different behavior for authenticated and unauthenticated users.
The latter is typically used to perform authorization checks by using its `isUserInRole(String)` method.