Fix nullability warnings and javadoc-triggered package cycles

This commit is contained in:
Juergen Hoeller 2019-07-17 22:34:07 +02:00
parent 56eadff34f
commit 94e3210ae7
10 changed files with 48 additions and 38 deletions

View File

@ -168,7 +168,7 @@ public class AntPathMatcher implements PathMatcher {
@Override @Override
public boolean isPattern(String path) { public boolean isPattern(@Nullable String path) {
if (path == null) { if (path == null) {
return false; return false;
} }
@ -207,10 +207,10 @@ public class AntPathMatcher implements PathMatcher {
* as far as the given base path goes is sufficient) * as far as the given base path goes is sufficient)
* @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't * @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
*/ */
protected boolean doMatch(String pattern, String path, boolean fullMatch, protected boolean doMatch(String pattern, @Nullable String path, boolean fullMatch,
@Nullable Map<String, String> uriTemplateVariables) { @Nullable Map<String, String> uriTemplateVariables) {
if ((path == null) || (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator))) { if (path == null || path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
return false; return false;
} }
@ -220,7 +220,6 @@ public class AntPathMatcher implements PathMatcher {
} }
String[] pathDirs = tokenizePath(path); String[] pathDirs = tokenizePath(path);
int pattIdxStart = 0; int pattIdxStart = 0;
int pattIdxEnd = pattDirs.length - 1; int pattIdxEnd = pattDirs.length - 1;
int pathIdxStart = 0; int pathIdxStart = 0;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,13 +26,12 @@ import java.lang.annotation.Target;
* Annotation that indicates a method parameter should be bound to a template variable * Annotation that indicates a method parameter should be bound to a template variable
* in a destination template string. Supported on message handling methods such as * in a destination template string. Supported on message handling methods such as
* {@link MessageMapping @MessageMapping}. * {@link MessageMapping @MessageMapping}.
* <p> *
* A {@code @DestinationVariable} template variable is always required. * <p>A {@code @DestinationVariable} template variable is always required.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0
*
* @see org.springframework.messaging.handler.annotation.MessageMapping * @see org.springframework.messaging.handler.annotation.MessageMapping
* @see org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler * @see org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler
*/ */

View File

@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.simp.annotation.SendToUser;
/** /**
* Annotation for mapping a {@link Message} onto a message-handling method by * Annotation for mapping a {@link Message} onto a message-handling method by
@ -65,11 +64,11 @@ import org.springframework.messaging.simp.annotation.SendToUser;
* authenticated user.</li> * authenticated user.</li>
* </ul> * </ul>
* *
* <p>How the return value is handled depends on the processing scenario. * <p>How the return value is handled depends on the processing scenario. For
* For STOMP over WebSocket, it is turned into a message and sent to a default * STOMP over WebSocket, it is turned into a message and sent to a default response
* response destination or to a custom destination specified with an * destination or to a custom destination specified with an {@link SendTo @SendTo}
* {@link SendTo @SendTo} or {@link SendToUser @SendToUser} annotation. * or {@link org.springframework.messaging.simp.annotation.SendToUser @SendToUser}
* For RSocket, the response is used to reply to the stream request. * annotation. For RSocket, the response is used to reply to the stream request.
* *
* <p>Specializations of this annotation including * <p>Specializations of this annotation including
* {@link org.springframework.messaging.simp.annotation.SubscribeMapping @SubscribeMapping} or * {@link org.springframework.messaging.simp.annotation.SubscribeMapping @SubscribeMapping} or

View File

@ -35,6 +35,7 @@ import org.springframework.util.RouteMatcher;
*/ */
class DefaultClientResponderFactory implements ClientResponderFactory, ClientResponderFactory.Config { class DefaultClientResponderFactory implements ClientResponderFactory, ClientResponderFactory.Config {
@Nullable
private List<Object> handlers; private List<Object> handlers;
@Nullable @Nullable
@ -52,9 +53,10 @@ class DefaultClientResponderFactory implements ClientResponderFactory, ClientRes
@Nullable @Nullable
private ArgumentResolverConfigurer argumentResolverConfigurer; private ArgumentResolverConfigurer argumentResolverConfigurer;
@Override @Override
public ClientResponderFactory handlers(Object... handlers) { public ClientResponderFactory handlers(Object... handlers) {
Assert.notEmpty(handlers, "handlers should not be empty"); Assert.notEmpty(handlers, "Handlers array must not be empty");
this.handlers = Arrays.asList(handlers); this.handlers = Arrays.asList(handlers);
return this; return this;
} }
@ -89,9 +91,10 @@ class DefaultClientResponderFactory implements ClientResponderFactory, ClientRes
return this; return this;
} }
@Override @Override
public void accept(RSocketFactory.ClientRSocketFactory clientRSocketFactory) { public void accept(RSocketFactory.ClientRSocketFactory clientRSocketFactory) {
Assert.notEmpty(this.handlers, "handlers should not be empty"); Assert.state(this.handlers != null, "No handlers set");
RSocketMessageHandler messageHandler = new RSocketMessageHandler(); RSocketMessageHandler messageHandler = new RSocketMessageHandler();
messageHandler.setHandlers(this.handlers); messageHandler.setHandlers(this.handlers);
if (this.strategies != null) { if (this.strategies != null) {

View File

@ -232,9 +232,9 @@ public class MockHttpServletResponse implements HttpServletResponse {
* @see #getContentAsString() * @see #getContentAsString()
*/ */
public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException { public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException {
return isCharset() ? return (isCharset() && this.characterEncoding != null ?
this.content.toString(this.characterEncoding) : this.content.toString(this.characterEncoding) :
this.content.toString(fallbackCharset.name()); this.content.toString(fallbackCharset.name()));
} }
@Override @Override

View File

@ -438,7 +438,8 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
return builder.toString(); return builder.toString();
} }
private void writeMultipart(MultiValueMap<String, Object> parts, MediaType contentType, HttpOutputMessage outputMessage) private void writeMultipart(
MultiValueMap<String, Object> parts, @Nullable MediaType contentType, HttpOutputMessage outputMessage)
throws IOException { throws IOException {
// If the supplied content type is null, fall back to multipart/form-data. // If the supplied content type is null, fall back to multipart/form-data.

View File

@ -110,13 +110,13 @@ public class ControllerAdviceBean implements Ordered {
public ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice) { public ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice) {
Assert.hasText(beanName, "Bean name must contain text"); Assert.hasText(beanName, "Bean name must contain text");
Assert.notNull(beanFactory, "BeanFactory must not be null"); Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory +
+ "] does not contain specified controller advice bean '" + beanName + "'"); "] does not contain specified controller advice bean '" + beanName + "'");
this.beanOrName = beanName; this.beanOrName = beanName;
this.beanType = getBeanType(beanName, beanFactory); this.beanType = getBeanType(beanName, beanFactory);
this.beanTypePredicate = (controllerAdvice != null ? createBeanTypePredicate(controllerAdvice) this.beanTypePredicate = (controllerAdvice != null ? createBeanTypePredicate(controllerAdvice) :
: createBeanTypePredicate(this.beanType)); createBeanTypePredicate(this.beanType));
this.beanFactory = beanFactory; this.beanFactory = beanFactory;
} }
@ -140,8 +140,11 @@ public class ControllerAdviceBean implements Ordered {
if (resolvedBean instanceof Ordered) { if (resolvedBean instanceof Ordered) {
this.order = ((Ordered) resolvedBean).getOrder(); this.order = ((Ordered) resolvedBean).getOrder();
} }
else if (this.beanType != null) {
this.order = OrderUtils.getOrder(this.beanType, Ordered.LOWEST_PRECEDENCE);
}
else { else {
this.order = OrderUtils.getOrder(getBeanType(), Ordered.LOWEST_PRECEDENCE); this.order = Ordered.LOWEST_PRECEDENCE;
} }
} }
return this.order; return this.order;
@ -236,18 +239,19 @@ public class ControllerAdviceBean implements Ordered {
return adviceBeans; return adviceBeans;
} }
@Nullable
private static Class<?> getBeanType(String beanName, BeanFactory beanFactory) { private static Class<?> getBeanType(String beanName, BeanFactory beanFactory) {
Class<?> beanType = beanFactory.getType(beanName); Class<?> beanType = beanFactory.getType(beanName);
return (beanType != null ? ClassUtils.getUserClass(beanType) : null); return (beanType != null ? ClassUtils.getUserClass(beanType) : null);
} }
private static HandlerTypePredicate createBeanTypePredicate(Class<?> beanType) { private static HandlerTypePredicate createBeanTypePredicate(@Nullable Class<?> beanType) {
ControllerAdvice controllerAdvice = (beanType != null ? ControllerAdvice controllerAdvice = (beanType != null ?
AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class) : null); AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class) : null);
return createBeanTypePredicate(controllerAdvice); return createBeanTypePredicate(controllerAdvice);
} }
private static HandlerTypePredicate createBeanTypePredicate(ControllerAdvice controllerAdvice) { private static HandlerTypePredicate createBeanTypePredicate(@Nullable ControllerAdvice controllerAdvice) {
if (controllerAdvice != null) { if (controllerAdvice != null) {
return HandlerTypePredicate.builder() return HandlerTypePredicate.builder()
.basePackage(controllerAdvice.basePackages()) .basePackage(controllerAdvice.basePackages())

View File

@ -231,11 +231,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
* @since 5.2 * @since 5.2
* @see #getContentAsString() * @see #getContentAsString()
*/ */
public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException { public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException {
return isCharset() ? return (isCharset() && this.characterEncoding != null ?
this.content.toString(this.characterEncoding) : this.content.toString(this.characterEncoding) :
this.content.toString(fallbackCharset.name()); this.content.toString(fallbackCharset.name()));
} }
@Override @Override

View File

@ -124,6 +124,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
/** /**
* See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation. * See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation.
* @since 5.2
*/ */
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) { public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) {
this.engineSupplier = engineSupplier; this.engineSupplier = engineSupplier;
@ -276,8 +277,9 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
} }
private ScriptEngine createEngineFromSupplier() { private ScriptEngine createEngineFromSupplier() {
Assert.state(this.engineSupplier != null, "No engine supplier available");
ScriptEngine engine = this.engineSupplier.get(); ScriptEngine engine = this.engineSupplier.get();
if (this.renderFunction != null && engine != null) { if (this.renderFunction != null) {
Assert.isInstanceOf(Invocable.class, engine, Assert.isInstanceOf(Invocable.class, engine,
"ScriptEngine must implement Invocable when 'renderFunction' is specified"); "ScriptEngine must implement Invocable when 'renderFunction' is specified");
} }

View File

@ -144,6 +144,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
/** /**
* See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation. * See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation.
* @since 5.2
*/ */
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) { public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) {
this.engineSupplier = engineSupplier; this.engineSupplier = engineSupplier;
@ -286,9 +287,8 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
engines = new HashMap<>(4); engines = new HashMap<>(4);
enginesHolder.set(engines); enginesHolder.set(engines);
} }
String name = (this.engineName != null ? this.engineName : this.engineSupplier.getClass().getSimpleName()); String name = (this.engineName != null ? this.engineName : "");
Object engineKey = (!ObjectUtils.isEmpty(this.scripts) ? Object engineKey = (!ObjectUtils.isEmpty(this.scripts) ? new EngineKey(name, this.scripts) : name);
new EngineKey(name, this.scripts) : name);
ScriptEngine engine = engines.get(engineKey); ScriptEngine engine = engines.get(engineKey);
if (engine == null) { if (engine == null) {
if (this.engineName != null) { if (this.engineName != null) {
@ -308,18 +308,22 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
} }
} }
protected ScriptEngine createEngineFromName(@Nullable String engineName) { protected ScriptEngine createEngineFromName(String engineName) {
if (this.scriptEngineManager == null) { ScriptEngineManager scriptEngineManager = this.scriptEngineManager;
this.scriptEngineManager = new ScriptEngineManager(obtainApplicationContext().getClassLoader()); if (scriptEngineManager == null) {
scriptEngineManager = new ScriptEngineManager(obtainApplicationContext().getClassLoader());
this.scriptEngineManager = scriptEngineManager;
} }
ScriptEngine engine = StandardScriptUtils.retrieveEngineByName(this.scriptEngineManager, engineName);
ScriptEngine engine = StandardScriptUtils.retrieveEngineByName(scriptEngineManager, engineName);
loadScripts(engine); loadScripts(engine);
return engine; return engine;
} }
private ScriptEngine createEngineFromSupplier() { private ScriptEngine createEngineFromSupplier() {
Assert.state(this.engineSupplier != null, "No engine supplier available");
ScriptEngine engine = this.engineSupplier.get(); ScriptEngine engine = this.engineSupplier.get();
if (this.renderFunction != null && engine != null) { if (this.renderFunction != null) {
Assert.isInstanceOf(Invocable.class, engine, Assert.isInstanceOf(Invocable.class, engine,
"ScriptEngine must implement Invocable when 'renderFunction' is specified"); "ScriptEngine must implement Invocable when 'renderFunction' is specified");
} }