Skip to content

Commit 292959e

Browse files
committed
Improve nullability for getSession(*) in MockHttpServletRequest
Closes gh-36926
1 parent 5383520 commit 292959e

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
import org.springframework.http.HttpHeaders;
6868
import org.springframework.http.MediaType;
69+
import org.springframework.lang.Contract;
6970
import org.springframework.util.Assert;
7071
import org.springframework.util.LinkedCaseInsensitiveMap;
7172
import org.springframework.util.LinkedMultiValueMap;
@@ -1311,6 +1312,7 @@ public void setSession(HttpSession session) {
13111312
}
13121313

13131314
@Override
1315+
@Contract("true -> !null")
13141316
public @Nullable HttpSession getSession(boolean create) {
13151317
checkActive();
13161318
// Reset session if invalidated.
@@ -1325,7 +1327,7 @@ public void setSession(HttpSession session) {
13251327
}
13261328

13271329
@Override
1328-
public @Nullable HttpSession getSession() {
1330+
public HttpSession getSession() {
13291331
return getSession(true);
13301332
}
13311333

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
import org.springframework.http.HttpHeaders;
6868
import org.springframework.http.MediaType;
69+
import org.springframework.lang.Contract;
6970
import org.springframework.util.Assert;
7071
import org.springframework.util.LinkedCaseInsensitiveMap;
7172
import org.springframework.util.LinkedMultiValueMap;
@@ -1311,6 +1312,7 @@ public void setSession(HttpSession session) {
13111312
}
13121313

13131314
@Override
1315+
@Contract("true -> !null")
13141316
public @Nullable HttpSession getSession(boolean create) {
13151317
checkActive();
13161318
// Reset session if invalidated.
@@ -1325,7 +1327,7 @@ public void setSession(HttpSession session) {
13251327
}
13261328

13271329
@Override
1328-
public @Nullable HttpSession getSession() {
1330+
public HttpSession getSession() {
13291331
return getSession(true);
13301332
}
13311333

0 commit comments

Comments
 (0)