Fix consistency with Nullability Usage

Issue gh-18564
This commit is contained in:
Robert Winch 2026-01-22 14:48:05 -06:00
parent ab3298e917
commit d7fbf3673a
No known key found for this signature in database
20 changed files with 32 additions and 46 deletions

View File

@ -278,7 +278,7 @@ public class LogoutSpecTests {
private static class InMemorySecurityContextRepository implements ServerSecurityContextRepository {
@Nullable private SecurityContext savedContext;
private @Nullable SecurityContext savedContext;
@Override
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
@ -291,7 +291,7 @@ public class LogoutSpecTests {
return Mono.justOrEmpty(this.savedContext);
}
@Nullable private SecurityContext getSavedContext() {
private @Nullable SecurityContext getSavedContext() {
return this.savedContext;
}

View File

@ -36,7 +36,7 @@ public class OneTimeTokenAuthenticationToken extends AbstractAuthenticationToken
@Serial
private static final long serialVersionUID = -8691636031126328365L;
private @Nullable final Object principal;
private final @Nullable Object principal;
private @Nullable String tokenValue;

View File

@ -32,7 +32,7 @@ public class MethodInvocationResult {
private final MethodInvocation methodInvocation;
private @Nullable final Object result;
private final @Nullable Object result;
/**
* Construct a {@link MethodInvocationResult} with the provided parameters

View File

@ -40,7 +40,6 @@ import tools.jackson.databind.json.JsonMapper;
import org.springframework.aop.Pointcut;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.NonNull;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.TestAuthentication;
@ -445,7 +444,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
}
@Override
public int compareTo(@NonNull User that) {
public int compareTo(User that) {
return this.id.compareTo(that.getId());
}
@ -455,7 +454,6 @@ public class AuthorizationAdvisorProxyFactoryTests {
List<User> users = List.of(new User("1", "first", "last"));
@NonNull
@Override
public Iterator<User> iterator() {
return this.users.iterator();

View File

@ -25,7 +25,6 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.aop.Pointcut;
import org.springframework.lang.NonNull;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.TestAuthentication;
@ -193,7 +192,7 @@ public class ReactiveAuthorizationAdvisorProxyFactoryTests {
}
@Override
public int compareTo(@NonNull User that) {
public int compareTo(User that) {
return this.id.compareTo(that.getId());
}
@ -207,7 +206,6 @@ public class ReactiveAuthorizationAdvisorProxyFactoryTests {
return Flux.fromIterable(this.users);
}
@NonNull
@Override
public Iterator<User> iterator() {
return this.users.iterator();

View File

@ -18,8 +18,9 @@ package org.springframework.security.messaging.util.matcher;
import java.util.Collections;
import org.jspecify.annotations.Nullable;
import org.springframework.http.server.PathContainer;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;

View File

@ -46,7 +46,6 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.objenesis.ObjenesisException;
import org.springframework.objenesis.SpringObjenesis;
import org.springframework.util.Assert;
@ -649,7 +648,6 @@ public final class ResolvableMethod {
}
@Override
@Nullable
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) {
if (ReflectionUtils.isObjectMethod(method)) {
return ReflectionUtils.invokeMethod(method, object, args);
@ -661,7 +659,6 @@ public final class ResolvableMethod {
}
@Override
@Nullable
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
}

View File

@ -21,8 +21,8 @@ import java.util.List;
import io.rsocket.SocketAcceptor;
import io.rsocket.metadata.WellKnownMimeType;
import io.rsocket.plugins.SocketAcceptorInterceptor;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.security.rsocket.api.PayloadInterceptor;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
@ -38,8 +38,7 @@ public class PayloadSocketAcceptorInterceptor implements SocketAcceptorIntercept
private final List<PayloadInterceptor> interceptors;
@Nullable
private MimeType defaultDataMimeType;
private @Nullable MimeType defaultDataMimeType;
private MimeType defaultMetadataMimeType = MimeTypeUtils
.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());

View File

@ -24,6 +24,7 @@ import jakarta.servlet.Filter;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
@ -33,7 +34,6 @@ import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.log.LogMessage;
import org.springframework.lang.NonNull;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.StringUtils;

View File

@ -508,7 +508,7 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
private final String filterSection;
@Nullable private String filterName;
private @Nullable String filterName;
private int chainPosition;

View File

@ -126,7 +126,7 @@ public abstract class AbstractAuthenticationProcessingFilter extends GenericFilt
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
@Nullable protected ApplicationEventPublisher eventPublisher;
protected @Nullable ApplicationEventPublisher eventPublisher;
protected AuthenticationDetailsSource<HttpServletRequest, ?> authenticationDetailsSource = new WebAuthenticationDetailsSource();

View File

@ -18,9 +18,9 @@ package org.springframework.security.web.authentication;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -100,8 +100,7 @@ public class UsernamePasswordAuthenticationFilter extends AbstractAuthentication
* @return the password that will be presented in the <code>Authentication</code>
* request token to the <code>AuthenticationManager</code>
*/
@Nullable
protected String obtainPassword(HttpServletRequest request) {
protected @Nullable String obtainPassword(HttpServletRequest request) {
return request.getParameter(this.passwordParameter);
}
@ -112,8 +111,7 @@ public class UsernamePasswordAuthenticationFilter extends AbstractAuthentication
* @return the username that will be presented in the <code>Authentication</code>
* request token to the <code>AuthenticationManager</code>
*/
@Nullable
protected String obtainUsername(HttpServletRequest request) {
protected @Nullable String obtainUsername(HttpServletRequest request) {
return request.getParameter(this.usernameParameter);
}

View File

@ -17,8 +17,8 @@
package org.springframework.security.web.authentication.ott;
import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.security.authentication.ott.GenerateOneTimeTokenRequest;
/**
@ -35,7 +35,6 @@ public interface GenerateOneTimeTokenRequestResolver {
* @param request {@link HttpServletRequest} to resolve
* @return {@link GenerateOneTimeTokenRequest}
*/
@Nullable
GenerateOneTimeTokenRequest resolve(HttpServletRequest request);
@Nullable GenerateOneTimeTokenRequest resolve(HttpServletRequest request);
}

View File

@ -20,7 +20,8 @@ import java.util.Collections;
import java.util.Map;
import java.util.regex.Pattern;
import org.springframework.lang.NonNull;
import org.jspecify.annotations.NonNull;
import org.springframework.security.web.server.csrf.CsrfToken;
import org.springframework.web.reactive.result.view.RequestDataValueProcessor;
import org.springframework.web.server.ServerWebExchange;

View File

@ -109,9 +109,9 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
private final WebHandler handler;
@Nullable private final ObservationWebFilter currentFilter;
private final @Nullable ObservationWebFilter currentFilter;
@Nullable private final ObservationWebFilterChain chain;
private final @Nullable ObservationWebFilterChain chain;
/**
* Public constructor with the list of filters and the target handler to use.

View File

@ -20,10 +20,10 @@ import java.security.cert.X509Certificate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.NonNull;
import reactor.core.publisher.Mono;
import org.springframework.http.server.reactive.SslInfo;
import org.springframework.lang.NonNull;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;

View File

@ -23,12 +23,12 @@ import java.util.Optional;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.log.LogMessage;
import org.springframework.http.HttpMethod;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.security.authentication.AccountStatusUserDetailsChecker;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -217,8 +217,8 @@ public class SwitchUserWebFilter implements WebFilter {
return exchange.getRequest().getQueryParams().getFirst(SPRING_SECURITY_SWITCH_USERNAME_KEY);
}
@NonNull
private Mono<Authentication> attemptSwitchUser(Authentication currentAuthentication, @Nullable String userName) {
private @NonNull Mono<Authentication> attemptSwitchUser(Authentication currentAuthentication,
@Nullable String userName) {
Assert.notNull(userName, "The userName can not be null.");
this.logger.debug(LogMessage.format("Attempting to switch to user [%s]", userName));
return this.userDetailsService.findByUsername(userName)
@ -227,8 +227,7 @@ public class SwitchUserWebFilter implements WebFilter {
.map((userDetails) -> createSwitchUserToken(userDetails, currentAuthentication));
}
@NonNull
private Authentication attemptExitUser(Authentication currentAuthentication) {
private @NonNull Authentication attemptExitUser(Authentication currentAuthentication) {
Optional<Authentication> sourceAuthentication = extractSourceAuthentication(currentAuthentication);
if (sourceAuthentication.isEmpty()) {
this.logger.debug("Failed to find original user");

View File

@ -19,11 +19,11 @@ package org.springframework.security.web.servlet.util.matcher;
import java.util.Objects;
import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.RequestPath;
import org.springframework.lang.Nullable;
import org.springframework.security.web.access.intercept.RequestAuthorizationContext;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

View File

@ -18,9 +18,9 @@ package org.springframework.security.web.util.matcher;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@ -36,8 +36,7 @@ public class DispatcherTypeRequestMatcher implements RequestMatcher {
private final DispatcherType dispatcherType;
@Nullable
private final HttpMethod httpMethod;
private final @Nullable HttpMethod httpMethod;
/**
* Creates an instance which matches requests with the provided {@link DispatcherType}

View File

@ -28,7 +28,6 @@ import jakarta.servlet.Servlet;
import jakarta.servlet.ServletRegistration;
import jakarta.servlet.ServletSecurityElement;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.DispatcherServlet;
public class MockServletContext extends org.springframework.mock.web.MockServletContext {
@ -41,15 +40,13 @@ public class MockServletContext extends org.springframework.mock.web.MockServlet
return servletContext;
}
@NonNull
@Override
public ServletRegistration.Dynamic addServlet(@NonNull String servletName, Class<? extends Servlet> clazz) {
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> clazz) {
ServletRegistration.Dynamic dynamic = new MockServletRegistration(servletName, clazz);
this.registrations.put(servletName, dynamic);
return dynamic;
}
@NonNull
@Override
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
return this.registrations;