Skip to content

Commit a16e8c3

Browse files
committed
Refine null-safety in spring-webmvc
See gh-32475
1 parent 52b8c71 commit a16e8c3

31 files changed

+41
-2
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
8686

8787

8888
@Override
89+
@Nullable
8990
public BeanDefinition parse(Element element, ParserContext context) {
9091
Object source = context.extractSource(element);
9192

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
6060

6161

6262
@Override
63+
@Nullable
6364
@SuppressWarnings("unchecked")
6465
public BeanDefinition parse(Element element, ParserContext parserContext) {
6566
Object source = parserContext.extractSource(element);

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.beans.factory.xml.BeanDefinitionParser;
3030
import org.springframework.beans.factory.xml.ParserContext;
3131
import org.springframework.core.Ordered;
32+
import org.springframework.lang.Nullable;
3233
import org.springframework.util.xml.DomUtils;
3334
import org.springframework.web.servlet.view.BeanNameViewResolver;
3435
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
@@ -68,6 +69,7 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser {
6869

6970

7071
@Override
72+
@Nullable
7173
public BeanDefinition parse(Element element, ParserContext context) {
7274
Object source = context.extractSource(element);
7375
context.pushContainingComponent(new CompositeComponentDefinition(element.getTagName(), source));

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> excep
160160
}
161161

162162
@Override
163+
@Nullable
163164
public Validator getValidator() {
164165
Validator selected = null;
165166
for (WebMvcConfigurer configurer : this.delegates) {

spring-webmvc/src/main/java/org/springframework/web/servlet/function/AbstractServerResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public MultiValueMap<String, Cookie> cookies() {
8282
}
8383

8484
@Override
85+
@Nullable
8586
public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response,
8687
Context context) throws ServletException, IOException {
8788

spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ public T entity() {
264264
}
265265

266266
@Override
267+
@Nullable
267268
protected ModelAndView writeToInternal(HttpServletRequest servletRequest,
268269
HttpServletResponse servletResponse, Context context)
269270
throws ServletException, IOException {
@@ -363,6 +364,7 @@ public CompletionStageEntityResponse(HttpStatusCode statusCode, HttpHeaders head
363364
}
364365

365366
@Override
367+
@Nullable
366368
protected ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
367369
Context context) throws ServletException, IOException {
368370

@@ -416,6 +418,7 @@ public PublisherEntityResponse(HttpStatusCode statusCode, HttpHeaders headers,
416418
}
417419

418420
@Override
421+
@Nullable
419422
protected ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
420423
Context context) throws ServletException, IOException {
421424

spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerResponseBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.http.HttpMethod;
3636
import org.springframework.http.HttpStatusCode;
3737
import org.springframework.http.MediaType;
38+
import org.springframework.lang.Nullable;
3839
import org.springframework.util.Assert;
3940
import org.springframework.util.LinkedMultiValueMap;
4041
import org.springframework.util.MultiValueMap;
@@ -229,6 +230,7 @@ public WriteFunctionResponse(HttpStatusCode statusCode, HttpHeaders headers, Mul
229230
}
230231

231232
@Override
233+
@Nullable
232234
protected ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response,
233235
Context context) throws Exception {
234236

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ protected boolean hasCorsConfigurationSource(Object handler) {
483483
}
484484

485485
@Override
486+
@Nullable
486487
protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) {
487488
CorsConfiguration corsConfig = super.getCorsConfiguration(handler, request);
488489
if (handler instanceof HandlerMethod handlerMethod) {
@@ -600,6 +601,7 @@ public List<T> getMappingsByDirectPath(String urlPath) {
600601
/**
601602
* Return handler methods by mapping name. Thread-safe for concurrent use.
602603
*/
604+
@Nullable
603605
public List<HandlerMethod> getHandlerMethodsByMappingName(String mappingName) {
604606
return this.nameLookup.get(mappingName);
605607
}

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ public void setAttribute(String name, Object value) {
500500
}
501501

502502
@Override
503+
@Nullable
503504
public Object getAttribute(String name) {
504505
return this.attributes.get(name);
505506
}
@@ -532,6 +533,7 @@ private static class LookupPathMatchableHandlerMapping implements MatchableHandl
532533
}
533534

534535
@Override
536+
@Nullable
535537
public PathPatternParser getPatternParser() {
536538
return this.delegate.getPatternParser();
537539
}

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/FixedLocaleResolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public Locale getLocale() {
8888
return getDefaultLocale();
8989
}
9090
@Override
91+
@Nullable
9192
public TimeZone getTimeZone() {
9293
return getDefaultTimeZone();
9394
}

0 commit comments

Comments
 (0)