Skip to content

Commit 0e7aba4

Browse files
committed
Perform NullAway build-time checks in spring-webmvc
See spring-projectsgh-32475
1 parent cf88100 commit 0e7aba4

File tree

9 files changed

+10
-5
lines changed

9 files changed

+10
-5
lines changed

gradle/spring-module.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ tasks.withType(JavaCompile).configureEach {
118118
disableAllChecks = true
119119
option("NullAway:CustomContractAnnotations", "org.springframework.lang.Contract")
120120
option("NullAway:AnnotatedPackages", "org.springframework.core,org.springframework.expression," +
121-
"org.springframework.web.reactive")
121+
"org.springframework.web.reactive,org.springframework.web.servlet")
122122
option("NullAway:UnannotatedSubPackages", "org.springframework.instrument,org.springframework.context.index," +
123123
"org.springframework.asm,org.springframework.cglib,org.springframework.objenesis," +
124124
"org.springframework.javapoet,org.springframework.aot.nativex.substitution")

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

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public ResourceChainRegistration(boolean cacheResources) {
6464
this(cacheResources, (cacheResources ? new ConcurrentMapCache(DEFAULT_CACHE_NAME) : null));
6565
}
6666

67+
@SuppressWarnings("NullAway")
6768
public ResourceChainRegistration(boolean cacheResources, @Nullable Cache cache) {
6869
Assert.isTrue(!cacheResources || cache != null, "'cache' is required when cacheResources=true");
6970
if (cacheResources) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletReques
442442
}
443443
}
444444

445+
@SuppressWarnings("NullAway")
445446
private void addMatchingMappings(Collection<T> mappings, List<Match> matches, HttpServletRequest request) {
446447
for (T mapping : mappings) {
447448
T match = getMatchingMapping(mapping, request);

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

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ protected Object getHandlerInternal(HttpServletRequest request) throws Exception
186186
* @since 5.3
187187
*/
188188
@Nullable
189+
@SuppressWarnings("NullAway")
189190
protected Object lookupHandler(
190191
RequestPath path, String lookupPath, HttpServletRequest request) throws Exception {
191192

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public RequestMatchResult(String pattern, String lookupPath, PathMatcher pathMat
9494
* {@link PathMatcher#extractUriTemplateVariables}.
9595
* @return a map with URI template variables
9696
*/
97-
@SuppressWarnings("ConstantConditions")
97+
@SuppressWarnings({"ConstantConditions", "NullAway"})
9898
public Map<String, String> extractUriTemplateVariables() {
9999
return (this.pathPattern != null ?
100100
this.pathPattern.matchAndExtract(this.lookupPathContainer).getUriVariables() :

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public int hashCode() {
490490
return this.hashCode;
491491
}
492492

493-
@SuppressWarnings("ConstantConditions")
493+
@SuppressWarnings({"ConstantConditions", "NullAway"})
494494
private static int calculateHashCode(
495495
@Nullable PathPatternsRequestCondition pathPatterns, @Nullable PatternsRequestCondition patterns,
496496
RequestMethodsRequestCondition methods, ParamsRequestCondition params, HeadersRequestCondition headers,

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ private class ConcurrentResultHandlerMethod extends ServletInvocableHandlerMetho
215215

216216
private final MethodParameter returnType;
217217

218+
@SuppressWarnings("NullAway")
218219
public ConcurrentResultHandlerMethod(@Nullable Object result, ConcurrentResultMethodParameter returnType) {
219220
super((Callable<Object>) () -> {
220221
if (result instanceof Exception exception) {

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ private int getEndPathIndex(String lookupPath) {
219219
* @return the resolved public URL path, or {@code null} if unresolved
220220
*/
221221
@Nullable
222+
@SuppressWarnings("NullAway")
222223
public final String getForLookupPath(String lookupPath) {
223224
// Clean duplicate slashes or pathWithinPattern won't match lookupPath
224225
String previous;

spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ protected final String createTargetUrl(Map<String, Object> model, HttpServletReq
328328
String url = getUrl();
329329
Assert.state(url != null, "'url' not set");
330330

331-
if (this.contextRelative && getUrl().startsWith("/")) {
331+
if (this.contextRelative && url.startsWith("/")) {
332332
// Do not apply context path to relative URLs.
333333
targetUrl.append(getContextPath(request));
334334
}
335-
targetUrl.append(getUrl());
335+
targetUrl.append(url);
336336

337337
String enc = this.encodingScheme;
338338
if (enc == null) {

0 commit comments

Comments
 (0)