diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java index 093f8334423..756e30cd11d 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java @@ -149,7 +149,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc @Override protected T getBean(Class type) { - Assert.state(this.beanFactory != null, "BeanFactory required for resolution of [" + type + "]"); + Assert.state(this.beanFactory != null, () -> "BeanFactory required for resolution of [" + type + "]"); try { return this.beanFactory.getBean(type); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index 9e86e3f4643..9ce163be5bd 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -443,12 +443,12 @@ public class AnnotatedElementUtils { * @param annotationType the annotation type to find (never {@code null}) * @return the set of all merged repeatable {@code Annotations} found, * or an empty set if none were found + * @throws IllegalArgumentException if the {@code element} or {@code annotationType} + * is {@code null}, or if the container type cannot be resolved * @since 4.3 * @see #getMergedAnnotation(AnnotatedElement, Class) * @see #getAllMergedAnnotations(AnnotatedElement, Class) * @see #getMergedRepeatableAnnotations(AnnotatedElement, Class, Class) - * @throws IllegalArgumentException if the {@code element} or {@code annotationType} - * is {@code null}, or if the container type cannot be resolved */ public static Set getMergedRepeatableAnnotations(AnnotatedElement element, Class annotationType) { @@ -474,13 +474,13 @@ public class AnnotatedElementUtils { * {@link java.lang.annotation.Repeatable} * @return the set of all merged repeatable {@code Annotations} found, * or an empty set if none were found - * @since 4.3 - * @see #getMergedAnnotation(AnnotatedElement, Class) - * @see #getAllMergedAnnotations(AnnotatedElement, Class) * @throws IllegalArgumentException if the {@code element} or {@code annotationType} * is {@code null}, or if the container type cannot be resolved * @throws AnnotationConfigurationException if the supplied {@code containerType} * is not a valid container annotation for the supplied {@code annotationType} + * @since 4.3 + * @see #getMergedAnnotation(AnnotatedElement, Class) + * @see #getAllMergedAnnotations(AnnotatedElement, Class) */ public static Set getMergedRepeatableAnnotations(AnnotatedElement element, Class annotationType, @Nullable Class containerType) { @@ -729,12 +729,12 @@ public class AnnotatedElementUtils { * @param annotationType the annotation type to find (never {@code null}) * @return the set of all merged repeatable {@code Annotations} found, * or an empty set if none were found + * @throws IllegalArgumentException if the {@code element} or {@code annotationType} + * is {@code null}, or if the container type cannot be resolved * @since 4.3 * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #findAllMergedAnnotations(AnnotatedElement, Class) * @see #findMergedRepeatableAnnotations(AnnotatedElement, Class, Class) - * @throws IllegalArgumentException if the {@code element} or {@code annotationType} - * is {@code null}, or if the container type cannot be resolved */ public static Set findMergedRepeatableAnnotations(AnnotatedElement element, Class annotationType) { @@ -760,13 +760,13 @@ public class AnnotatedElementUtils { * {@link java.lang.annotation.Repeatable} * @return the set of all merged repeatable {@code Annotations} found, * or an empty set if none were found - * @since 4.3 - * @see #findMergedAnnotation(AnnotatedElement, Class) - * @see #findAllMergedAnnotations(AnnotatedElement, Class) * @throws IllegalArgumentException if the {@code element} or {@code annotationType} * is {@code null}, or if the container type cannot be resolved * @throws AnnotationConfigurationException if the supplied {@code containerType} * is not a valid container annotation for the supplied {@code annotationType} + * @since 4.3 + * @see #findMergedAnnotation(AnnotatedElement, Class) + * @see #findAllMergedAnnotations(AnnotatedElement, Class) */ public static Set findMergedRepeatableAnnotations(AnnotatedElement element, Class annotationType, @Nullable Class containerType) { @@ -1280,9 +1280,9 @@ public class AnnotatedElementUtils { * annotation for the supplied repeatable {@code annotationType} (i.e., * that it declares a {@code value} attribute that holds an array of the * {@code annotationType}). - * @since 4.3 * @throws AnnotationConfigurationException if the supplied {@code containerType} * is not a valid container annotation for the supplied {@code annotationType} + * @since 4.3 */ private static void validateContainerType(Class annotationType, Class containerType) { @@ -1305,9 +1305,6 @@ public class AnnotatedElementUtils { } } - /** - * @since 4.3 - */ private static Set postProcessAndSynthesizeAggregatedResults(AnnotatedElement element, Class annotationType, List aggregatedResults) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java index 7239c3d8f29..74a882a62c3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java @@ -147,7 +147,7 @@ class DefaultMvcResult implements MvcResult { " was not set during the specified timeToWait=" + timeToWait); } Object result = this.asyncResult.get(); - Assert.state(result != RESULT_NONE, "Async result for handler [" + this.handler + "] was not set"); + Assert.state(result != RESULT_NONE, () -> "Async result for handler [" + this.handler + "] was not set"); return this.asyncResult.get(); } @@ -160,7 +160,7 @@ class DefaultMvcResult implements MvcResult { try { return this.asyncDispatchLatch.await(timeout, TimeUnit.MILLISECONDS); } - catch (InterruptedException e) { + catch (InterruptedException ex) { return false; } } diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java index 905e21d3784..67dfb3ea054 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java @@ -80,7 +80,7 @@ public interface ServerWebExchange { @SuppressWarnings("unchecked") default T getRequiredAttribute(String name) { T value = getAttribute(name); - Assert.notNull(value, "Required attribute '" + name + "' is missing."); + Assert.notNull(value, () -> "Required attribute '" + name + "' is missing."); return value; } diff --git a/spring-web/src/main/java/org/springframework/web/server/WebSession.java b/spring-web/src/main/java/org/springframework/web/server/WebSession.java index 6fe7e1cc2aa..c1231ba6bf8 100644 --- a/spring-web/src/main/java/org/springframework/web/server/WebSession.java +++ b/spring-web/src/main/java/org/springframework/web/server/WebSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -71,7 +71,7 @@ public interface WebSession { @SuppressWarnings("unchecked") default T getRequiredAttribute(String name) { T value = getAttribute(name); - Assert.notNull(value, "Required attribute '" + name + "' is missing."); + Assert.notNull(value, () -> "Required attribute '" + name + "' is missing."); return value; } @@ -116,13 +116,19 @@ public interface WebSession { Mono invalidate(); /** - * Save the session persisting attributes (e.g. if stored remotely) and also - * sending the session id to the client if the session is new. - *

Note that a session must be started explicitly via {@link #start()} or - * implicitly by adding attributes or otherwise this method has no effect. + * Save the session through the {@code WebSessionStore} as follows: + *

    + *
  • If the session is new (i.e. created but never persisted), it must have + * been started explicitly via {@link #start()} or implicitly by adding + * attributes, or otherwise this method should have no effect. + *
  • If the session was retrieved through the {@code WebSessionStore}, + * the implementation for this method must check whether the session was + * {@link #invalidate() invalidated} and if so return an error. + *
+ *

Note that this method is not intended for direct use by applications. + * Instead it is automatically invoked just before the response is + * committed. * @return {@code Mono} to indicate completion with success or error - *

Typically this method should be automatically invoked just before the - * response is committed so applications don't have to by default. */ Mono save(); diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java index 5d42d49324c..01dd2756e2a 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java @@ -42,20 +42,18 @@ import org.springframework.web.server.session.DefaultWebSessionManager; import org.springframework.web.server.session.WebSessionManager; /** - * This builder has two purposes. + * This builder has two purposes: * - *

One is to assemble a processing chain that consists of a target - * {@link WebHandler}, then decorated with a set of {@link WebFilter}'s, then - * further decorated with a set of {@link WebExceptionHandler}'s. + *

One is to assemble a processing chain that consists of a target {@link WebHandler}, + * then decorated with a set of {@link WebFilter WebFilters}, then further decorated with + * a set of {@link WebExceptionHandler WebExceptionHandlers}. * - *

The second purpose is to adapt the resulting processing chain to an - * {@link HttpHandler} -- the lowest level reactive HTTP handling abstraction, - * which can then be used with any of the supported runtimes. The adaptation - * is done with the help of {@link HttpWebHandlerAdapter}. + *

The second purpose is to adapt the resulting processing chain to an {@link HttpHandler}: + * the lowest-level reactive HTTP handling abstraction which can then be used with any of the + * supported runtimes. The adaptation is done with the help of {@link HttpWebHandlerAdapter}. * - *

The processing chain can be assembled manually via builder methods, or - * detected from Spring configuration via - * {@link #applicationContext(ApplicationContext)}, or a mix of both. + *

The processing chain can be assembled manually via builder methods, or detected from + * a Spring {@link ApplicationContext} via {@link #applicationContext}, or a mix of both. * * @author Rossen Stoyanchev * @author Sebastien Deleuze @@ -240,13 +238,12 @@ public class WebHttpHandlerBuilder { } /** - * Whether a {@code WebSessionManager} is configured or not, either - * detected from an {@code ApplicationContext} or explicitly configured via - * {@link #sessionManager(WebSessionManager)}. + * Whether a {@code WebSessionManager} is configured or not, either detected from an + * {@code ApplicationContext} or explicitly configured via {@link #sessionManager}. * @since 5.0.9 */ public boolean hasSessionManager() { - return this.sessionManager != null; + return (this.sessionManager != null); } /** @@ -260,13 +257,12 @@ public class WebHttpHandlerBuilder { /** - * Whether a {@code ServerCodecConfigurer} is configured or not, either - * detected from an {@code ApplicationContext} or explicitly configured via - * {@link #codecConfigurer(ServerCodecConfigurer)}. + * Whether a {@code ServerCodecConfigurer} is configured or not, either detected from an + * {@code ApplicationContext} or explicitly configured via {@link #codecConfigurer}. * @since 5.0.9 */ public boolean hasCodecConfigurer() { - return this.codecConfigurer != null; + return (this.codecConfigurer != null); } /** @@ -280,13 +276,12 @@ public class WebHttpHandlerBuilder { } /** - * Whether a {@code LocaleContextResolver} is configured or not, either - * detected from an {@code ApplicationContext} or explicitly configured via - * {@link #localeContextResolver(LocaleContextResolver)}. + * Whether a {@code LocaleContextResolver} is configured or not, either detected from an + * {@code ApplicationContext} or explicitly configured via {@link #localeContextResolver}. * @since 5.0.9 */ public boolean hasLocaleContextResolver() { - return this.localeContextResolver != null; + return (this.localeContextResolver != null); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java index bcd8f75ed05..66c67b170eb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java @@ -244,7 +244,7 @@ public class RedirectView extends AbstractUrlBasedView { while (found) { String name = matcher.group(1); Object value = (model.containsKey(name) ? model.get(name) : uriVariables.get(name)); - Assert.notNull(value, "No value for URI variable '" + name + "'"); + Assert.notNull(value, () -> "No value for URI variable '" + name + "'"); result.append(targetUrl.substring(endLastMatch, matcher.start())); result.append(encodeUriVariable(value.toString())); endLastMatch = matcher.end(); @@ -283,7 +283,7 @@ public class RedirectView extends AbstractUrlBasedView { } /** - * Send a redirect back to the HTTP client + * Send a redirect back to the HTTP client. * @param targetUrl the target URL to redirect to * @param exchange current exchange */ diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java index d98d5b38fd4..4576bfc3f00 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java @@ -111,8 +111,8 @@ class ReactiveTypeHandler { /** * Process the given reactive return value and decide whether to adapt it * to a {@link ResponseBodyEmitter} or a {@link DeferredResult}. - * @return an emitter for streaming or {@code null} if handled internally - * with a {@link DeferredResult}. + * @return an emitter for streaming, or {@code null} if handled internally + * with a {@link DeferredResult} */ @Nullable public ResponseBodyEmitter handleValue(Object returnValue, MethodParameter returnType, @@ -120,7 +120,7 @@ class ReactiveTypeHandler { Assert.notNull(returnValue, "Expected return value"); ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass()); - Assert.state(adapter != null, "Unexpected return value: " + returnValue); + Assert.state(adapter != null, () -> "Unexpected return value: " + returnValue); ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric(); Class elementClass = elementType.resolve(Object.class); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java index 65bd02fd042..a0f59b58000 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -120,7 +120,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @Override public BeanDefinition parse(Element element, ParserContext context) { - Object source = context.extractSource(element); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); context.pushContainingComponent(compDefinition); @@ -151,19 +150,18 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) { RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source); String pathAttribute = endpointElem.getAttribute("path"); - Assert.state(StringUtils.hasText(pathAttribute), "Invalid (no path mapping)"); - List paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ",")); - for (String path : paths) { + Assert.hasText(pathAttribute, "Invalid (no path mapping)"); + for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) { path = path.trim(); - Assert.state(StringUtils.hasText(path), "Invalid path attribute: " + pathAttribute); + Assert.hasText(path, () -> "Invalid path attribute: " + pathAttribute); if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) { - path = path.endsWith("/") ? path + "**" : path + "/**"; + path = (path.endsWith("/") ? path + "**" : path + "/**"); } urlMap.put(path, requestHandler); } } - Map scopeMap = Collections.singletonMap("websocket", new SimpSessionScope()); + Map scopeMap = Collections.singletonMap("websocket", new SimpSessionScope()); RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class); scopeConfigurer.getPropertyValues().add("scopes", scopeMap); registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source); @@ -243,6 +241,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { } } } + ConstructorArgumentValues cargs = new ConstructorArgumentValues(); if (executor != null) { executor.getPropertyValues().add("threadNamePrefix", name + "-"); @@ -250,6 +249,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { registerBeanDefByName(executorName, executor, context, source); cargs.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName)); } + RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, cargs, null); ManagedList interceptors = new ManagedList<>(); if (element != null) { @@ -441,6 +441,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { // Should not happen throw new IllegalStateException("Neither nor elements found."); } + registerBeanDef(brokerDef, context, source); return brokerDef; } @@ -660,20 +661,20 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { context.registerComponent(new BeanComponentDefinition(beanDef, name)); } + private static class DecoratingFactoryBean implements FactoryBean { private final WebSocketHandler handler; private final List factories; - private DecoratingFactoryBean(WebSocketHandler handler, List factories) { this.handler = handler; this.factories = factories; } @Override - public WebSocketHandler getObject() throws Exception { + public WebSocketHandler getObject() { WebSocketHandler result = this.handler; for (WebSocketHandlerDecoratorFactory factory : this.factories) { result = factory.decorate(result);