Skip to content

Commit 88b9c05

Browse files
committed
Refine null-safety in spring-test
See gh-32475
1 parent c7c9da5 commit 88b9c05

21 files changed

+39
-10
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void addInitParameter(String name, String value) {
9797
}
9898

9999
@Override
100+
@Nullable
100101
public String getInitParameter(String name) {
101102
Assert.notNull(name, "Parameter name must not be null");
102103
return this.initParameters.get(name);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ protected void checkActive() throws IllegalStateException {
383383
// ---------------------------------------------------------------------
384384

385385
@Override
386+
@Nullable
386387
public Object getAttribute(String name) {
387388
checkActive();
388389
return this.attributes.get(name);
@@ -637,6 +638,7 @@ public Enumeration<String> getParameterNames() {
637638
}
638639

639640
@Override
641+
@Nullable
640642
public String[] getParameterValues(String name) {
641643
Assert.notNull(name, "Parameter name must not be null");
642644
return this.parameters.get(name);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public int getMaxInactiveInterval() {
148148
}
149149

150150
@Override
151+
@Nullable
151152
public Object getAttribute(String name) {
152153
assertIsValid();
153154
Assert.notNull(name, "Attribute name must not be null");

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public Iterator<String> getFileNames() {
9696
}
9797

9898
@Override
99+
@Nullable
99100
public MultipartFile getFile(String name) {
100101
return this.multipartFiles.getFirst(name);
101102
}
@@ -117,6 +118,7 @@ public MultiValueMap<String, MultipartFile> getMultiFileMap() {
117118
}
118119

119120
@Override
121+
@Nullable
120122
public String getMultipartContentType(String paramOrFileName) {
121123
MultipartFile file = getFile(paramOrFileName);
122124
if (file != null) {
@@ -154,6 +156,7 @@ public HttpHeaders getRequestHeaders() {
154156
}
155157

156158
@Override
159+
@Nullable
157160
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
158161
MultipartFile file = getFile(paramOrFileName);
159162
if (file != null) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void addInitParameter(String name, String value) {
9393
}
9494

9595
@Override
96+
@Nullable
9697
public String getInitParameter(String name) {
9798
Assert.notNull(name, "Parameter name must not be null");
9899
return this.initParameters.get(name);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public void registerContext(String contextPath, ServletContext context) {
223223
}
224224

225225
@Override
226+
@Nullable
226227
public ServletContext getContext(String contextPath) {
227228
if (this.contextPath.equals(contextPath)) {
228229
return this;
@@ -375,6 +376,7 @@ public RequestDispatcher getRequestDispatcher(String path) {
375376
}
376377

377378
@Override
379+
@Nullable
378380
public RequestDispatcher getNamedDispatcher(String path) {
379381
return this.namedRequestDispatchers.get(path);
380382
}
@@ -464,6 +466,7 @@ public String getServerInfo() {
464466
}
465467

466468
@Override
469+
@Nullable
467470
public String getInitParameter(String name) {
468471
Assert.notNull(name, "Parameter name must not be null");
469472
return this.initParameters.get(name);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public void setAttribute(String name, String value) {
136136
}
137137

138138
@Override
139+
@Nullable
139140
public String getAttribute(String name) {
140141
return this.attributes.get(name);
141142
}

spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ public Optional<MediaType> contentType() {
569569
}
570570

571571
@Override
572+
@Nullable
572573
public InetSocketAddress host() {
573574
return delegate().getHost();
574575
}

spring-test/src/main/java/org/springframework/test/context/ApplicationContextFailureProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.test.context;
1818

1919
import org.springframework.context.ApplicationContext;
20+
import org.springframework.lang.Nullable;
2021

2122
/**
2223
* Strategy for components that process failures related to application contexts
@@ -41,6 +42,6 @@ public interface ApplicationContextFailureProcessor {
4142
* @param context the application context that did not load successfully
4243
* @param exception the exception thrown while loading the application context
4344
*/
44-
void processLoadFailure(ApplicationContext context, Throwable exception);
45+
void processLoadFailure(ApplicationContext context, @Nullable Throwable exception);
4546

4647
}

spring-test/src/main/java/org/springframework/test/context/SmartContextLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.test.context;
1818

1919
import org.springframework.context.ApplicationContext;
20-
import org.springframework.lang.Nullable;
2120

2221
/**
2322
* Strategy interface for loading an {@link ApplicationContext} for an integration
@@ -157,7 +156,7 @@ public interface SmartContextLoader extends ContextLoader {
157156
*/
158157
@Override
159158
@SuppressWarnings("deprecation")
160-
default String[] processLocations(Class<?> clazz, @Nullable String... locations) {
159+
default String[] processLocations(Class<?> clazz, String... locations) {
161160
throw new UnsupportedOperationException("""
162161
SmartContextLoader does not support the ContextLoader SPI. \
163162
Call processContextConfiguration(ContextConfigurationAttributes) instead.""");

0 commit comments

Comments
 (0)