Skip to content

Commit

Permalink
Perform NullAway build-time checks in spring-webmvc
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Mar 22, 2024
1 parent cf88100 commit 0e7aba4
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/spring-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ tasks.withType(JavaCompile).configureEach {
disableAllChecks = true
option("NullAway:CustomContractAnnotations", "org.springframework.lang.Contract")
option("NullAway:AnnotatedPackages", "org.springframework.core,org.springframework.expression," +
"org.springframework.web.reactive")
"org.springframework.web.reactive,org.springframework.web.servlet")
option("NullAway:UnannotatedSubPackages", "org.springframework.instrument,org.springframework.context.index," +
"org.springframework.asm,org.springframework.cglib,org.springframework.objenesis," +
"org.springframework.javapoet,org.springframework.aot.nativex.substitution")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public ResourceChainRegistration(boolean cacheResources) {
this(cacheResources, (cacheResources ? new ConcurrentMapCache(DEFAULT_CACHE_NAME) : null));
}

@SuppressWarnings("NullAway")
public ResourceChainRegistration(boolean cacheResources, @Nullable Cache cache) {
Assert.isTrue(!cacheResources || cache != null, "'cache' is required when cacheResources=true");
if (cacheResources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletReques
}
}

@SuppressWarnings("NullAway")
private void addMatchingMappings(Collection<T> mappings, List<Match> matches, HttpServletRequest request) {
for (T mapping : mappings) {
T match = getMatchingMapping(mapping, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected Object getHandlerInternal(HttpServletRequest request) throws Exception
* @since 5.3
*/
@Nullable
@SuppressWarnings("NullAway")
protected Object lookupHandler(
RequestPath path, String lookupPath, HttpServletRequest request) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public RequestMatchResult(String pattern, String lookupPath, PathMatcher pathMat
* {@link PathMatcher#extractUriTemplateVariables}.
* @return a map with URI template variables
*/
@SuppressWarnings("ConstantConditions")
@SuppressWarnings({"ConstantConditions", "NullAway"})
public Map<String, String> extractUriTemplateVariables() {
return (this.pathPattern != null ?
this.pathPattern.matchAndExtract(this.lookupPathContainer).getUriVariables() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public int hashCode() {
return this.hashCode;
}

@SuppressWarnings("ConstantConditions")
@SuppressWarnings({"ConstantConditions", "NullAway"})
private static int calculateHashCode(
@Nullable PathPatternsRequestCondition pathPatterns, @Nullable PatternsRequestCondition patterns,
RequestMethodsRequestCondition methods, ParamsRequestCondition params, HeadersRequestCondition headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private class ConcurrentResultHandlerMethod extends ServletInvocableHandlerMetho

private final MethodParameter returnType;

@SuppressWarnings("NullAway")
public ConcurrentResultHandlerMethod(@Nullable Object result, ConcurrentResultMethodParameter returnType) {
super((Callable<Object>) () -> {
if (result instanceof Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private int getEndPathIndex(String lookupPath) {
* @return the resolved public URL path, or {@code null} if unresolved
*/
@Nullable
@SuppressWarnings("NullAway")
public final String getForLookupPath(String lookupPath) {
// Clean duplicate slashes or pathWithinPattern won't match lookupPath
String previous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ protected final String createTargetUrl(Map<String, Object> model, HttpServletReq
String url = getUrl();
Assert.state(url != null, "'url' not set");

if (this.contextRelative && getUrl().startsWith("/")) {
if (this.contextRelative && url.startsWith("/")) {
// Do not apply context path to relative URLs.
targetUrl.append(getContextPath(request));
}
targetUrl.append(getUrl());
targetUrl.append(url);

String enc = this.encodingScheme;
if (enc == null) {
Expand Down

0 comments on commit 0e7aba4

Please sign in to comment.