Skip to content

Commit 70ec5a0

Browse files
committed
Add nullability annotations to module/spring-boot-session
See gh-46587
1 parent 56db1a4 commit 70ec5a0

File tree

8 files changed

+32
-11
lines changed

8 files changed

+32
-11
lines changed

module/spring-boot-session/src/main/java/org/springframework/boot/session/autoconfigure/SessionAutoConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ DefaultCookieSerializer cookieSerializer(ServerProperties serverProperties,
7979
map.from(cookie::getHttpOnly).to(cookieSerializer::setUseHttpOnlyCookie);
8080
map.from(cookie::getSecure).to(cookieSerializer::setUseSecureCookie);
8181
map.from(cookie::getMaxAge).asInt(Duration::getSeconds).to(cookieSerializer::setCookieMaxAge);
82-
map.from(cookie::getSameSite).as(SameSite::attributeValue).to(cookieSerializer::setSameSite);
82+
setSameSite(map, cookie, cookieSerializer);
8383
map.from(cookie::getPartitioned).to(cookieSerializer::setPartitioned);
8484
cookieSerializerCustomizers.orderedStream().forEach((customizer) -> customizer.customize(cookieSerializer));
8585
return cookieSerializer;
8686
}
8787

88+
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct
89+
// nullability
90+
private void setSameSite(PropertyMapper map, Cookie cookie, DefaultCookieSerializer cookieSerializer) {
91+
map.from(cookie::getSameSite).as(SameSite::attributeValue).to(cookieSerializer::setSameSite);
92+
}
93+
8894
@Configuration(proxyBeanMethods = false)
8995
@ConditionalOnClass(RememberMeServices.class)
9096
static class RememberMeServicesConfiguration {

module/spring-boot-session/src/main/java/org/springframework/boot/session/autoconfigure/SessionProperties.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Set;
2424
import java.util.function.Supplier;
2525

26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.boot.context.properties.ConfigurationProperties;
2729
import org.springframework.boot.convert.DurationUnit;
2830
import org.springframework.boot.web.servlet.DispatcherType;
@@ -43,15 +45,15 @@ public class SessionProperties {
4345
* Session timeout. If a duration suffix is not specified, seconds will be used.
4446
*/
4547
@DurationUnit(ChronoUnit.SECONDS)
46-
private Duration timeout;
48+
private @Nullable Duration timeout;
4749

4850
private Servlet servlet = new Servlet();
4951

50-
public Duration getTimeout() {
52+
public @Nullable Duration getTimeout() {
5153
return this.timeout;
5254
}
5355

54-
public void setTimeout(Duration timeout) {
56+
public void setTimeout(@Nullable Duration timeout) {
5557
this.timeout = timeout;
5658
}
5759

module/spring-boot-session/src/main/java/org/springframework/boot/session/autoconfigure/SessionRepositoryFilterConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.stream.Collectors;
2121

2222
import jakarta.servlet.DispatcherType;
23+
import org.jspecify.annotations.Nullable;
2324

2425
import org.springframework.beans.factory.ListableBeanFactory;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -52,7 +53,7 @@ DelegatingFilterProxyRegistrationBean sessionRepositoryFilterRegistration(Sessio
5253
return registration;
5354
}
5455

55-
private EnumSet<DispatcherType> getDispatcherTypes(SessionProperties sessionProperties) {
56+
private @Nullable EnumSet<DispatcherType> getDispatcherTypes(SessionProperties sessionProperties) {
5657
SessionProperties.Servlet servletProperties = sessionProperties.getServlet();
5758
if (servletProperties.getFilterDispatcherTypes() == null) {
5859
return null;

module/spring-boot-session/src/main/java/org/springframework/boot/session/autoconfigure/endpoint/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring Session endpoint.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.session.autoconfigure.endpoint;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-session/src/main/java/org/springframework/boot/session/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring Session.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.session.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-session/src/main/java/org/springframework/boot/session/endpoint/ReactiveSessionsEndpoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.session.endpoint;
1818

19+
import org.jspecify.annotations.Nullable;
1920
import reactor.core.publisher.Mono;
2021

2122
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
@@ -41,15 +42,15 @@ public class ReactiveSessionsEndpoint {
4142

4243
private final ReactiveSessionRepository<? extends Session> sessionRepository;
4344

44-
private final ReactiveFindByIndexNameSessionRepository<? extends Session> indexedSessionRepository;
45+
private final @Nullable ReactiveFindByIndexNameSessionRepository<? extends Session> indexedSessionRepository;
4546

4647
/**
4748
* Create a new {@link ReactiveSessionsEndpoint} instance.
4849
* @param sessionRepository the session repository
4950
* @param indexedSessionRepository the indexed session repository
5051
*/
5152
public ReactiveSessionsEndpoint(ReactiveSessionRepository<? extends Session> sessionRepository,
52-
ReactiveFindByIndexNameSessionRepository<? extends Session> indexedSessionRepository) {
53+
@Nullable ReactiveFindByIndexNameSessionRepository<? extends Session> indexedSessionRepository) {
5354
Assert.notNull(sessionRepository, "'sessionRepository' must not be null");
5455
this.sessionRepository = sessionRepository;
5556
this.indexedSessionRepository = indexedSessionRepository;

module/spring-boot-session/src/main/java/org/springframework/boot/session/endpoint/SessionsEndpoint.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Map;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
2224
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
2325
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
@@ -40,22 +42,22 @@ public class SessionsEndpoint {
4042

4143
private final SessionRepository<? extends Session> sessionRepository;
4244

43-
private final FindByIndexNameSessionRepository<? extends Session> indexedSessionRepository;
45+
private final @Nullable FindByIndexNameSessionRepository<? extends Session> indexedSessionRepository;
4446

4547
/**
4648
* Create a new {@link SessionsEndpoint} instance.
4749
* @param sessionRepository the session repository
4850
* @param indexedSessionRepository the indexed session repository
4951
*/
5052
public SessionsEndpoint(SessionRepository<? extends Session> sessionRepository,
51-
FindByIndexNameSessionRepository<? extends Session> indexedSessionRepository) {
53+
@Nullable FindByIndexNameSessionRepository<? extends Session> indexedSessionRepository) {
5254
Assert.notNull(sessionRepository, "'sessionRepository' must not be null");
5355
this.sessionRepository = sessionRepository;
5456
this.indexedSessionRepository = indexedSessionRepository;
5557
}
5658

5759
@ReadOperation
58-
public SessionsDescriptor sessionsForUsername(String username) {
60+
public @Nullable SessionsDescriptor sessionsForUsername(String username) {
5961
if (this.indexedSessionRepository == null) {
6062
return null;
6163
}
@@ -64,7 +66,7 @@ public SessionsDescriptor sessionsForUsername(String username) {
6466
}
6567

6668
@ReadOperation
67-
public SessionDescriptor getSession(@Selector String sessionId) {
69+
public @Nullable SessionDescriptor getSession(@Selector String sessionId) {
6870
Session session = this.sessionRepository.findById(sessionId);
6971
if (session == null) {
7072
return null;

module/spring-boot-session/src/main/java/org/springframework/boot/session/endpoint/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Actuator endpoint for Spring Session.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.session.endpoint;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)