Skip to content

Commit cc0f644

Browse files
committed
Enable Null Checking with JSpecify
Closes gh-3637
2 parents 492bf5c + 49b692f commit cc0f644

File tree

68 files changed

+832
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+832
-118
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ configurations {
5757
}
5858

5959
dependencies {
60+
implementation libs.spring.nullability
6061
implementation 'com.google.code.gson:gson:2.13.2'
6162
implementation 'net.sourceforge.saxon:saxon:9.1.0.8'
6263
implementation 'org.yaml:snakeyaml:1.33'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id 'io.spring.nullability'
3+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ io-spring-security-release-plugin = "io.spring.gradle:spring-security-release-pl
4242
org-springframework-boot-spring-boot-gradle-plugin = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "org-springframework-boot" }
4343
io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.47"
4444
io-spring-nohttp-nohttp-checkstyle = "io.spring.nohttp:nohttp-checkstyle:0.0.11"
45+
spring-nullability = "io.spring.nullability:io.spring.nullability.gradle.plugin:0.0.10"

spring-session-core/spring-session-core.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
plugins {
2+
id 'session-nullability'
3+
}
4+
15
apply plugin: 'io.spring.convention.spring-module'
26

37
description = "Spring Session"

spring-session-core/src/main/java/org/springframework/session/MapSession.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.Set;
2626
import java.util.UUID;
2727

28+
import org.jspecify.annotations.Nullable;
29+
2830
/**
2931
* <p>
3032
* A {@link Session} implementation that is backed by a {@link java.util.Map}. The
@@ -188,7 +190,7 @@ boolean isExpired(Instant now) {
188190

189191
@Override
190192
@SuppressWarnings("unchecked")
191-
public <T> T getAttribute(String attributeName) {
193+
public <T> @Nullable T getAttribute(String attributeName) {
192194
return (T) this.sessionAttrs.get(attributeName);
193195
}
194196

@@ -198,7 +200,7 @@ public Set<String> getAttributeNames() {
198200
}
199201

200202
@Override
201-
public void setAttribute(String attributeName, Object attributeValue) {
203+
public void setAttribute(String attributeName, @Nullable Object attributeValue) {
202204
if (attributeValue == null) {
203205
removeAttribute(attributeName);
204206
}

spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.time.Duration;
2020
import java.util.Map;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.session.events.SessionDeletedEvent;
2325
import org.springframework.session.events.SessionExpiredEvent;
2426
import org.springframework.util.Assert;
@@ -79,7 +81,7 @@ public void save(MapSession session) {
7981
}
8082

8183
@Override
82-
public MapSession findById(String id) {
84+
public @Nullable MapSession findById(String id) {
8385
Session saved = this.sessions.get(id);
8486
if (saved == null) {
8587
return null;

spring-session-core/src/main/java/org/springframework/session/PrincipalNameIndexResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.session;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.expression.Expression;
2022
import org.springframework.expression.spel.standard.SpelExpressionParser;
2123

@@ -47,7 +49,7 @@ public PrincipalNameIndexResolver(String indexName) {
4749
super(indexName);
4850
}
4951

50-
public String resolveIndexValueFor(S session) {
52+
public @Nullable String resolveIndexValueFor(S session) {
5153
String principalName = session.getAttribute(getIndexName());
5254
if (principalName != null) {
5355
return principalName;

spring-session-core/src/main/java/org/springframework/session/Session.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.time.Instant;
2121
import java.util.Set;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
/**
2426
* Provides a way to identify a user in an agnostic way. This allows the session to be
2527
* used by an HttpSession, WebSocket Session, or even non web related sessions.
@@ -51,7 +53,7 @@ public interface Session {
5153
* @return the Object associated with the specified name or null if no Object is
5254
* associated to that name
5355
*/
54-
<T> T getAttribute(String attributeName);
56+
<T> @Nullable T getAttribute(String attributeName);
5557

5658
/**
5759
* Return the session attribute value or if not present raise an

spring-session-core/src/main/java/org/springframework/session/SessionRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.session;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* A repository interface for managing {@link Session} instances.
2123
*
@@ -59,7 +61,7 @@ public interface SessionRepository<S extends Session> {
5961
* @return the {@link Session} by the {@link Session#getId()} or null if no
6062
* {@link Session} is found.
6163
*/
62-
S findById(String id);
64+
@Nullable S findById(String id);
6365

6466
/**
6567
* Deletes the {@link Session} with the given {@link Session#getId()} or does nothing

spring-session-core/src/main/java/org/springframework/session/SingleIndexResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Collections;
2020
import java.util.Map;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.util.Assert;
2325

2426
/**
@@ -42,7 +44,7 @@ protected String getIndexName() {
4244
return this.indexName;
4345
}
4446

45-
public abstract String resolveIndexValueFor(S session);
47+
public abstract @Nullable String resolveIndexValueFor(S session);
4648

4749
public final Map<String, String> resolveIndexesFor(S session) {
4850
String indexValue = resolveIndexValueFor(session);

0 commit comments

Comments
 (0)