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
@@ -27,7 +27,6 @@ import org.jspecify.annotations.Nullable;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.OptionalParameter;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.cache.Cache;
@@ -82,8 +81,7 @@ public class CachesEndpoint {
* {@code cacheManager} was provided to identify a unique candidate
*/
@ReadOperation
public @Nullable CacheEntryDescriptor cache(@Selector String cache,
@OptionalParameter @Nullable String cacheManager) {
public @Nullable CacheEntryDescriptor cache(@Selector String cache, @Nullable String cacheManager) {
return extractUniqueCacheEntry(cache, getCacheEntries((name) -> name.equals(cache), isNameMatch(cacheManager)));
}
@@ -105,7 +103,7 @@ public class CachesEndpoint {
* {@code cacheManager} was provided to identify a unique candidate
*/
@DeleteOperation
public boolean clearCache(@Selector String cache, @OptionalParameter @Nullable String cacheManager) {
public boolean clearCache(@Selector String cache, @Nullable String cacheManager) {
CacheEntryDescriptor entry = extractUniqueCacheEntry(cache,
getCacheEntries((name) -> name.equals(cache), isNameMatch(cacheManager)));
return (entry != null && clearCache(entry));
@@ -19,7 +19,6 @@ package org.springframework.boot.cache.actuate.endpoint;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
import org.springframework.boot.actuate.endpoint.annotation.OptionalParameter;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
@@ -42,8 +41,7 @@ public class CachesEndpointWebExtension {
}
@ReadOperation
public WebEndpointResponse<CacheEntryDescriptor> cache(@Selector String cache,
@OptionalParameter @Nullable String cacheManager) {
public WebEndpointResponse<CacheEntryDescriptor> cache(@Selector String cache, @Nullable String cacheManager) {
try {
CacheEntryDescriptor entry = this.delegate.cache(cache, cacheManager);
int status = (entry != null) ? WebEndpointResponse.STATUS_OK : WebEndpointResponse.STATUS_NOT_FOUND;
@@ -55,8 +53,7 @@ public class CachesEndpointWebExtension {
}
@DeleteOperation
public WebEndpointResponse<Void> clearCache(@Selector String cache,
@OptionalParameter @Nullable String cacheManager) {
public WebEndpointResponse<Void> clearCache(@Selector String cache, @Nullable String cacheManager) {
try {
boolean cleared = this.delegate.clearCache(cache, cacheManager);
int status = (cleared ? WebEndpointResponse.STATUS_NO_CONTENT : WebEndpointResponse.STATUS_NOT_FOUND);