Nullability refinements on private and static methods

Based on IntelliJ IDEA 2017.3 introspection results.

Issue: SPR-15756
This commit is contained in:
Juergen Hoeller
2017-09-22 18:22:12 +02:00
parent 60f47f4489
commit 7ae59d0c2a
88 changed files with 319 additions and 300 deletions

View File

@@ -334,15 +334,12 @@ class DefaultWebClient implements WebClient {
}
private HttpHeaders initHeaders() {
if (CollectionUtils.isEmpty(defaultHeaders) && CollectionUtils.isEmpty(this.headers)) {
return new HttpHeaders();
if (CollectionUtils.isEmpty(this.headers)) {
return (defaultHeaders != null ? defaultHeaders : new HttpHeaders());
}
else if (CollectionUtils.isEmpty(defaultHeaders)) {
return this.headers;
}
else if (CollectionUtils.isEmpty(this.headers)) {
return defaultHeaders;
}
else {
HttpHeaders result = new HttpHeaders();
result.putAll(this.headers);
@@ -356,15 +353,12 @@ class DefaultWebClient implements WebClient {
}
private MultiValueMap<String, String> initCookies() {
if (CollectionUtils.isEmpty(defaultCookies) && CollectionUtils.isEmpty(this.cookies)) {
return new LinkedMultiValueMap<>(0);
if (CollectionUtils.isEmpty(this.cookies)) {
return (defaultCookies != null ? defaultCookies : new LinkedMultiValueMap<>(0));
}
else if (CollectionUtils.isEmpty(defaultCookies)) {
return this.cookies;
}
else if (CollectionUtils.isEmpty(this.cookies)) {
return defaultCookies;
}
else {
MultiValueMap<String, String> result = new LinkedMultiValueMap<>();
result.putAll(this.cookies);
@@ -379,9 +373,11 @@ class DefaultWebClient implements WebClient {
}
}
private static class DefaultResponseSpec implements ResponseSpec {
private static final StatusHandler DEFAULT_STATUS_HANDLER = new StatusHandler(HttpStatus::isError, DefaultResponseSpec::createResponseException);
private static final StatusHandler DEFAULT_STATUS_HANDLER =
new StatusHandler(HttpStatus::isError, DefaultResponseSpec::createResponseException);
private final Mono<ClientResponse> responseMono;

View File

@@ -50,7 +50,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
* same number of conditions so they may be compared and combined.
* It is acceptable to provide {@code null} conditions.
*/
public CompositeRequestCondition(@Nullable RequestCondition<?>... requestConditions) {
public CompositeRequestCondition(RequestCondition<?>... requestConditions) {
this.requestConditions = wrap(requestConditions);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,12 +38,13 @@ import org.springframework.web.server.ServerWebExchange;
*/
public final class RequestConditionHolder extends AbstractRequestCondition<RequestConditionHolder> {
@Nullable
private final RequestCondition<Object> condition;
/**
* Create a new holder to wrap the given request condition.
* @param requestCondition the condition to hold, may be {@code null}
* @param requestCondition the condition to hold (may be {@code null})
*/
@SuppressWarnings("unchecked")
public RequestConditionHolder(@Nullable RequestCondition<?> requestCondition) {
@@ -86,23 +87,12 @@ public final class RequestConditionHolder extends AbstractRequestCondition<Reque
return this;
}
else {
assertEqualConditionTypes(other);
assertEqualConditionTypes(this.condition, other.condition);
RequestCondition<?> combined = (RequestCondition<?>) this.condition.combine(other.condition);
return new RequestConditionHolder(combined);
}
}
/**
* Ensure the held request conditions are of the same type.
*/
private void assertEqualConditionTypes(RequestConditionHolder other) {
Class<?> clazz = this.condition.getClass();
Class<?> otherClazz = other.condition.getClass();
if (!clazz.equals(otherClazz)) {
throw new ClassCastException("Incompatible request conditions: " + clazz + " and " + otherClazz);
}
}
/**
* Get the matching condition for the held request condition wrap it in a
* new RequestConditionHolder instance. Or otherwise if this is an empty
@@ -134,9 +124,20 @@ public final class RequestConditionHolder extends AbstractRequestCondition<Reque
return -1;
}
else {
assertEqualConditionTypes(other);
assertEqualConditionTypes(this.condition, other.condition);
return this.condition.compareTo(other.condition, exchange);
}
}
/**
* Ensure the held request conditions are of the same type.
*/
private void assertEqualConditionTypes(RequestCondition<?> cond1, RequestCondition<?> cond2) {
Class<?> clazz = cond1.getClass();
Class<?> otherClazz = cond2.getClass();
if (!clazz.equals(otherClazz)) {
throw new ClassCastException("Incompatible request conditions: " + clazz + " vs " + otherClazz);
}
}
}

View File

@@ -124,6 +124,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
* @see #getCustomTypeCondition(Class)
* @see #getCustomMethodCondition(Method)
*/
@Nullable
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class ?