Skip to content

Commit

Permalink
Fix nullability warnings and javadoc-triggered package cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jul 17, 2019
1 parent 56eadff commit 94e3210
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void deactivatePatternCache() {


@Override
public boolean isPattern(String path) {
public boolean isPattern(@Nullable String path) {
if (path == null) {
return false;
}
Expand Down Expand Up @@ -207,10 +207,10 @@ public boolean matchStart(String pattern, String path) {
* 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
*/
protected boolean doMatch(String pattern, String path, boolean fullMatch,
protected boolean doMatch(String pattern, @Nullable String path, boolean fullMatch,
@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;
}

Expand All @@ -220,7 +220,6 @@ protected boolean doMatch(String pattern, String path, boolean fullMatch,
}

String[] pathDirs = tokenizePath(path);

int pattIdxStart = 0;
int pattIdxEnd = pattDirs.length - 1;
int pathIdxStart = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand All @@ -26,13 +26,12 @@
* 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
* {@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 Rossen Stoyanchev
* @since 4.0
*
* @see org.springframework.messaging.handler.annotation.MessageMapping
* @see org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.annotation.Target;

import org.springframework.messaging.Message;
import org.springframework.messaging.simp.annotation.SendToUser;

/**
* Annotation for mapping a {@link Message} onto a message-handling method by
Expand Down Expand Up @@ -65,11 +64,11 @@
* authenticated user.</li>
* </ul>
*
* <p>How the return value is handled depends on the processing scenario.
* For STOMP over WebSocket, it is turned into a message and sent to a default
* response destination or to a custom destination specified with an
* {@link SendTo @SendTo} or {@link SendToUser @SendToUser} annotation.
* For RSocket, the response is used to reply to the stream request.
* <p>How the return value is handled depends on the processing scenario. For
* STOMP over WebSocket, it is turned into a message and sent to a default response
* destination or to a custom destination specified with an {@link SendTo @SendTo}
* or {@link org.springframework.messaging.simp.annotation.SendToUser @SendToUser}
* annotation. For RSocket, the response is used to reply to the stream request.
*
* <p>Specializations of this annotation including
* {@link org.springframework.messaging.simp.annotation.SubscribeMapping @SubscribeMapping} or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
class DefaultClientResponderFactory implements ClientResponderFactory, ClientResponderFactory.Config {

@Nullable
private List<Object> handlers;

@Nullable
Expand All @@ -52,9 +53,10 @@ class DefaultClientResponderFactory implements ClientResponderFactory, ClientRes
@Nullable
private ArgumentResolverConfigurer argumentResolverConfigurer;


@Override
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);
return this;
}
Expand Down Expand Up @@ -89,9 +91,10 @@ public ClientResponderFactory.Config argumentResolver(ArgumentResolverConfigurer
return this;
}


@Override
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();
messageHandler.setHandlers(this.handlers);
if (this.strategies != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ public String getContentAsString() throws UnsupportedEncodingException {
* @see #getContentAsString()
*/
public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException {
return isCharset() ?
return (isCharset() && this.characterEncoding != null ?
this.content.toString(this.characterEncoding) :
this.content.toString(fallbackCharset.name());
this.content.toString(fallbackCharset.name()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ protected String serializeForm(MultiValueMap<String, Object> formData, Charset c
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 {

// If the supplied content type is null, fall back to multipart/form-data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ public ControllerAdviceBean(String beanName, BeanFactory beanFactory) {
public ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice) {
Assert.hasText(beanName, "Bean name must contain text");
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory
+ "] does not contain specified controller advice bean '" + beanName + "'");
Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory +
"] does not contain specified controller advice bean '" + beanName + "'");

this.beanOrName = beanName;
this.beanType = getBeanType(beanName, beanFactory);
this.beanTypePredicate = (controllerAdvice != null ? createBeanTypePredicate(controllerAdvice)
: createBeanTypePredicate(this.beanType));
this.beanTypePredicate = (controllerAdvice != null ? createBeanTypePredicate(controllerAdvice) :
createBeanTypePredicate(this.beanType));
this.beanFactory = beanFactory;
}

Expand All @@ -140,8 +140,11 @@ public int getOrder() {
if (resolvedBean instanceof Ordered) {
this.order = ((Ordered) resolvedBean).getOrder();
}
else if (this.beanType != null) {
this.order = OrderUtils.getOrder(this.beanType, Ordered.LOWEST_PRECEDENCE);
}
else {
this.order = OrderUtils.getOrder(getBeanType(), Ordered.LOWEST_PRECEDENCE);
this.order = Ordered.LOWEST_PRECEDENCE;
}
}
return this.order;
Expand Down Expand Up @@ -236,18 +239,19 @@ public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext c
return adviceBeans;
}

@Nullable
private static Class<?> getBeanType(String beanName, BeanFactory beanFactory) {
Class<?> beanType = beanFactory.getType(beanName);
return (beanType != null ? ClassUtils.getUserClass(beanType) : null);
}

private static HandlerTypePredicate createBeanTypePredicate(Class<?> beanType) {
private static HandlerTypePredicate createBeanTypePredicate(@Nullable Class<?> beanType) {
ControllerAdvice controllerAdvice = (beanType != null ?
AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class) : null);
return createBeanTypePredicate(controllerAdvice);
}

private static HandlerTypePredicate createBeanTypePredicate(ControllerAdvice controllerAdvice) {
private static HandlerTypePredicate createBeanTypePredicate(@Nullable ControllerAdvice controllerAdvice) {
if (controllerAdvice != null) {
return HandlerTypePredicate.builder()
.basePackage(controllerAdvice.basePackages())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ public String getContentAsString() throws UnsupportedEncodingException {
* @since 5.2
* @see #getContentAsString()
*/

public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException {
return isCharset() ?
return (isCharset() && this.characterEncoding != null ?
this.content.toString(this.characterEncoding) :
this.content.toString(fallbackCharset.name());
this.content.toString(fallbackCharset.name()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void setEngine(ScriptEngine engine) {

/**
* See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation.
* @since 5.2
*/
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) {
this.engineSupplier = engineSupplier;
Expand Down Expand Up @@ -276,8 +277,9 @@ protected ScriptEngine createEngineFromName(String engineName) {
}

private ScriptEngine createEngineFromSupplier() {
Assert.state(this.engineSupplier != null, "No engine supplier available");
ScriptEngine engine = this.engineSupplier.get();
if (this.renderFunction != null && engine != null) {
if (this.renderFunction != null) {
Assert.isInstanceOf(Invocable.class, engine,
"ScriptEngine must implement Invocable when 'renderFunction' is specified");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void setEngine(ScriptEngine engine) {

/**
* See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation.
* @since 5.2
*/
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) {
this.engineSupplier = engineSupplier;
Expand Down Expand Up @@ -286,9 +287,8 @@ protected ScriptEngine getEngine() {
engines = new HashMap<>(4);
enginesHolder.set(engines);
}
String name = (this.engineName != null ? this.engineName : this.engineSupplier.getClass().getSimpleName());
Object engineKey = (!ObjectUtils.isEmpty(this.scripts) ?
new EngineKey(name, this.scripts) : name);
String name = (this.engineName != null ? this.engineName : "");
Object engineKey = (!ObjectUtils.isEmpty(this.scripts) ? new EngineKey(name, this.scripts) : name);
ScriptEngine engine = engines.get(engineKey);
if (engine == null) {
if (this.engineName != null) {
Expand All @@ -308,18 +308,22 @@ protected ScriptEngine getEngine() {
}
}

protected ScriptEngine createEngineFromName(@Nullable String engineName) {
if (this.scriptEngineManager == null) {
this.scriptEngineManager = new ScriptEngineManager(obtainApplicationContext().getClassLoader());
protected ScriptEngine createEngineFromName(String engineName) {
ScriptEngineManager scriptEngineManager = this.scriptEngineManager;
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);
return engine;
}

private ScriptEngine createEngineFromSupplier() {
Assert.state(this.engineSupplier != null, "No engine supplier available");
ScriptEngine engine = this.engineSupplier.get();
if (this.renderFunction != null && engine != null) {
if (this.renderFunction != null) {
Assert.isInstanceOf(Invocable.class, engine,
"ScriptEngine must implement Invocable when 'renderFunction' is specified");
}
Expand Down

0 comments on commit 94e3210

Please sign in to comment.