From 62fc7df693d7c225866fbc27cbeec1dce0b0cbbe Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 29 Nov 2018 16:29:34 -0500 Subject: [PATCH] Sonar Fixes Critical smells, packages `o.s.i.a*` to `f*`. Plus new smells caused by these changes. --- build.gradle | 2 +- .../AbstractSubscribableAmqpChannel.java | 11 +--- .../amqp/config/AmqpChannelFactoryBean.java | 7 ++- .../MessagePublishingErrorHandler.java | 10 ++-- .../integration/channel/QueueChannel.java | 34 ++++++----- ...ltConfiguringBeanFactoryPostProcessor.java | 2 +- .../GlobalChannelInterceptorInitializer.java | 15 +++-- .../config/IdGeneratorConfigurer.java | 7 ++- ...ntReceiverAutoProxyCreatorInitializer.java | 4 +- .../IntegrationConverterInitializer.java | 2 +- .../config/MessageHistoryRegistrar.java | 2 +- ...AbstractMethodAnnotationPostProcessor.java | 10 ++-- .../xml/AbstractConsumerEndpointParser.java | 6 +- .../integration/config/xml/ChainParser.java | 5 +- .../config/xml/ChannelInterceptorParser.java | 5 +- .../xml/GlobalChannelInterceptorParser.java | 5 +- .../config/xml/GlobalWireTapParser.java | 5 +- .../xml/HeaderEnricherParserSupport.java | 4 +- .../config/xml/IntegrationNamespaceUtils.java | 6 +- .../config/xml/ScatterGatherParser.java | 7 ++- .../xml/SpelPropertyAccessorsParser.java | 5 +- .../context/IntegrationObjectSupport.java | 3 - .../core/ErrorMessagePublisher.java | 13 ++-- .../integration/dsl/IntegrationFlows.java | 5 +- .../IntegrationFlowBeanPostProcessor.java | 4 +- .../endpoint/SourcePollingChannelAdapter.java | 3 - .../expression/ExpressionEvalMap.java | 3 + .../expression/ExpressionSource.java | 6 +- .../expression/ExpressionUtils.java | 9 ++- .../expression/FunctionExpression.java | 5 +- ...oadableResourceBundleExpressionSource.java | 59 +++++++++++-------- .../expression/SupplierExpression.java | 7 ++- .../integration/expression/package-info.java | 1 + .../AnnotationGatewayProxyFactoryBean.java | 10 +++- .../gateway/MessagingGatewaySupport.java | 1 + .../graph/IntegrationGraphServer.java | 4 +- .../router/AbstractMessageRouter.java | 12 ++-- .../integration/store/MessageGroupQueue.java | 2 + .../file/FileWritingMessageHandler.java | 5 +- ...eTailInboundChannelAdapterFactoryBean.java | 2 +- .../filters/ExpressionFileListFilter.java | 6 +- .../AbstractRemoteFileOutboundGateway.java | 4 +- .../FtpOutboundChannelAdapterParser.java | 4 +- .../ftp/config/FtpOutboundGatewayParser.java | 4 +- .../integration/ftp/dsl/FtpTests.java | 2 +- 45 files changed, 188 insertions(+), 140 deletions(-) diff --git a/build.gradle b/build.gradle index f3207ad41c..ec670037af 100644 --- a/build.gradle +++ b/build.gradle @@ -131,7 +131,7 @@ subprojects { subproject -> romeToolsVersion = '1.9.0' servletApiVersion = '4.0.0' smackVersion = '4.3.1' - springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.1.2.RELEASE' + springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.1.3.BUILD-SNAPSHOT' springDataJpaVersion = '2.1.3.RELEASE' springDataMongoVersion = '2.1.3.RELEASE' springDataRedisVersion = '2.1.3.RELEASE' diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java index b6a406fe5d..41c35a51ae 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java @@ -288,14 +288,9 @@ abstract class AbstractSubscribableAmqpChannel extends AbstractAmqpChannel Message messageToSend = null; try { Object converted = this.converter.fromMessage(message); - if (converted != null) { - messageToSend = (converted instanceof Message) ? (Message) converted - : buildMessage(message, converted); - this.dispatcher.dispatch(messageToSend); - } - else if (this.logger.isWarnEnabled()) { - this.logger.warn("MessageConverter returned null, no Message to dispatch"); - } + messageToSend = (converted instanceof Message) ? (Message) converted + : buildMessage(message, converted); + this.dispatcher.dispatch(messageToSend); } catch (MessageDispatchingException e) { String exceptionMessage = e.getMessage() + " for amqp-channel '" diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java index 426e542ff9..5cd3d341b2 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java @@ -46,6 +46,7 @@ import org.springframework.integration.amqp.channel.PollableAmqpChannel; import org.springframework.integration.amqp.channel.PublishSubscribeAmqpChannel; import org.springframework.integration.amqp.support.AmqpHeaderMapper; import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper; +import org.springframework.lang.Nullable; import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.interceptor.TransactionAttribute; @@ -152,7 +153,7 @@ public class AmqpChannelFactoryBean extends AbstractFactoryBean failedMessage = (actualThrowable instanceof MessagingException) ? ((MessagingException) actualThrowable).getFailedMessage() : null; if (getDefaultErrorChannel() == null && getChannelResolver() != null) { - setChannel(getChannelResolver().resolveDestination( + setChannel(getChannelResolver().resolveDestination(// NOSONAR not null IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)); } @@ -137,11 +137,11 @@ public class MessagePublishingErrorHandler extends ErrorMessagePublisher impleme if (errorChannelHeader instanceof MessageChannel) { return (MessageChannel) errorChannelHeader; } - Assert.isInstanceOf(String.class, errorChannelHeader, + Assert.isInstanceOf(String.class, errorChannelHeader, () -> "Unsupported error channel header type. Expected MessageChannel or String, but actual type is [" + - errorChannelHeader.getClass() + "]"); + errorChannelHeader.getClass() + "]"); // NOSONAR never null here if (getChannelResolver() != null) { - return getChannelResolver().resolveDestination((String) errorChannelHeader); + return getChannelResolver().resolveDestination((String) errorChannelHeader); // NOSONAR not null } else { return null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java index 24d61afd2a..db7a987907 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java @@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.support.management.QueueChannelManagement; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -116,19 +117,7 @@ public class QueueChannel extends AbstractPollableChannel implements QueueChanne return ((BlockingQueue>) this.queue).poll(timeout, TimeUnit.MILLISECONDS); } else { - Message message = this.queue.poll(); - if (message == null) { - long nanos = TimeUnit.MILLISECONDS.toNanos(timeout); - long deadline = System.nanoTime() + nanos; - while (message == null && nanos > 0) { - this.queueSemaphore.tryAcquire(nanos, TimeUnit.NANOSECONDS); // NOSONAR ok to ignore result - message = this.queue.poll(); - if (message == null) { - nanos = deadline - System.nanoTime(); - } - } - } - return message; + return pollNonBlockingQueue(timeout); } } if (timeout == 0) { @@ -141,7 +130,7 @@ public class QueueChannel extends AbstractPollableChannel implements QueueChanne else { Message message = this.queue.poll(); while (message == null) { - this.queueSemaphore.tryAcquire(50, TimeUnit.MILLISECONDS); + this.queueSemaphore.tryAcquire(50, TimeUnit.MILLISECONDS); // NOSONAR ok to ignore result message = this.queue.poll(); } return message; @@ -153,6 +142,23 @@ public class QueueChannel extends AbstractPollableChannel implements QueueChanne } } + @Nullable + private Message pollNonBlockingQueue(long timeout) throws InterruptedException { + Message message = this.queue.poll(); + if (message == null) { + long nanos = TimeUnit.MILLISECONDS.toNanos(timeout); + long deadline = System.nanoTime() + nanos; + while (message == null && nanos > 0) { + this.queueSemaphore.tryAcquire(nanos, TimeUnit.NANOSECONDS); // NOSONAR ok to ignore result + message = this.queue.poll(); + if (message == null) { + nanos = deadline - System.nanoTime(); + } + } + } + return message; + } + @Override public List> clear() { List> clearedMessages = new ArrayList<>(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java index d013796a0b..118091e857 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java @@ -160,7 +160,7 @@ class DefaultConfiguringBeanFactoryPostProcessor else { nullChannelDefinition = ((BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory()) - .getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); + .getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); // NOSONAR not null } if (!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) { throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/GlobalChannelInterceptorInitializer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/GlobalChannelInterceptorInitializer.java index 9ff505615c..75bbe10cb3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/GlobalChannelInterceptorInitializer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/GlobalChannelInterceptorInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-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. @@ -38,6 +38,7 @@ import org.springframework.util.CollectionUtils; * {@link org.springframework.context.annotation.Bean} methods are also processed. * * @author Artem Bilan + * @author Gary Russell * @since 4.0 */ public class GlobalChannelInterceptorInitializer implements IntegrationConfigurationInitializer { @@ -50,14 +51,18 @@ public class GlobalChannelInterceptorInitializer implements IntegrationConfigura BeanDefinition beanDefinition = registry.getBeanDefinition(beanName); if (beanDefinition instanceof AnnotatedBeanDefinition) { AnnotationMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata(); - Map annotationAttributes = metadata.getAnnotationAttributes(GlobalChannelInterceptor.class.getName()); - if (CollectionUtils.isEmpty(annotationAttributes) && beanDefinition.getSource() instanceof MethodMetadata) { + Map annotationAttributes = metadata + .getAnnotationAttributes(GlobalChannelInterceptor.class.getName()); + if (CollectionUtils.isEmpty(annotationAttributes) + && beanDefinition.getSource() instanceof MethodMetadata) { MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource(); - annotationAttributes = beanMethod.getAnnotationAttributes(GlobalChannelInterceptor.class.getName()); + annotationAttributes = + beanMethod.getAnnotationAttributes(GlobalChannelInterceptor.class.getName()); // NOSONAR not null } if (!CollectionUtils.isEmpty(annotationAttributes)) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorWrapper.class) + BeanDefinitionBuilder builder = BeanDefinitionBuilder + .genericBeanDefinition(GlobalChannelInterceptorWrapper.class) .addConstructorArgReference(beanName) .addPropertyValue("patterns", annotationAttributes.get("patterns")) .addPropertyValue("order", annotationAttributes.get("order")); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java index 7feed854b0..638a5676a4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IdGeneratorConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -48,6 +48,7 @@ public final class IdGeneratorConfigurer implements ApplicationListener returnType; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConverterInitializer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConverterInitializer.java index 8b2904fba6..eae95cf0f7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConverterInitializer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConverterInitializer.java @@ -54,7 +54,7 @@ public class IntegrationConverterInitializer implements IntegrationConfiguration if (!hasIntegrationConverter && beanDefinition.getSource() instanceof MethodMetadata) { MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource(); - hasIntegrationConverter = beanMethod.isAnnotated(IntegrationConverter.class.getName()); + hasIntegrationConverter = beanMethod.isAnnotated(IntegrationConverter.class.getName()); // NOSONAR never null } if (hasIntegrationConverter) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryRegistrar.java b/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryRegistrar.java index da0f88a9dc..336d2027d9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryRegistrar.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryRegistrar.java @@ -73,7 +73,7 @@ public class MessageHistoryRegistrar implements ImportBeanDefinitionRegistrar { if (propertyValue != null) { @SuppressWarnings("unchecked") Set currentComponentNamePatternsSet = (Set) propertyValue.getValue(); - currentComponentNamePatternsSet.add(componentNamePatterns); + currentComponentNamePatternsSet.add(componentNamePatterns); // NOSONAR never null } else { Set componentNamePatternsSet = new ManagedSet(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java index 81f6459f58..bb6c58a370 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java @@ -66,6 +66,7 @@ import org.springframework.integration.router.AbstractMessageRouter; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.integration.support.channel.BeanFactoryChannelResolver; import org.springframework.integration.util.MessagingAnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.PollableChannel; @@ -195,7 +196,7 @@ public abstract class AbstractMethodAnnotationPostProcessor H extractTypeIfPossible(Object targetObject, Class expectedType) { + protected H extractTypeIfPossible(@Nullable Object targetObject, Class expectedType) { if (targetObject == null) { return null; } @@ -486,9 +487,6 @@ public abstract class AbstractMethodAnnotationPostProcessor channelCandidateNames = - (Collection) caValues.getArgumentValue(0, Collection.class).getValue(); - channelCandidateNames.add(inputChannelName); + (Collection) caValues.getArgumentValue(0, Collection.class).getValue(); // NOSONAR see comment above + channelCandidateNames.add(inputChannelName); // NOSONAR } else { parserContext.getReaderContext().error("Failed to locate '" + diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java index 21c128a723..6677084649 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -49,6 +49,7 @@ import org.springframework.util.xml.DomUtils; * @author Oleg Zhurakousky * @author Artem Bilan * @author Gunnar Hillert + * @author Gary Russell */ public class ChainParser extends AbstractConsumerEndpointParser { @@ -147,7 +148,7 @@ public class ChainParser extends AbstractConsumerEndpointParser { } } - holder.getBeanDefinition().getPropertyValues().add("componentName", handlerComponentName); + holder.getBeanDefinition().getPropertyValues().add("componentName", handlerComponentName); // NOSONAR never null if (hasId) { BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java index c6ab991212..fe95889176 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 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. @@ -36,6 +36,7 @@ import org.springframework.beans.factory.xml.ParserContext; * * @author Mark Fisher * @author Oleg Zhurakousky + * @author Gary Russell */ public class ChannelInterceptorParser { @@ -60,7 +61,7 @@ public class ChannelInterceptorParser { if ("bean".equals(localName)) { BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); BeanDefinitionHolder holder = delegate.parseBeanDefinitionElement(childElement); - holder = delegate.decorateBeanDefinitionIfRequired(childElement, holder); + holder = delegate.decorateBeanDefinitionIfRequired(childElement, holder); // NOSONAR never null parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); interceptors.add(new RuntimeBeanReference(holder.getBeanName())); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java index 4e75124829..262c44b379 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -97,7 +97,8 @@ public class GlobalChannelInterceptorParser extends AbstractBeanDefinitionParser } else { BeanDefinition beanDef = delegate.parseCustomElement(child); - beanName = BeanDefinitionReaderUtils.generateBeanName(beanDef, parserContext.getRegistry()); + beanName = BeanDefinitionReaderUtils.generateBeanName(beanDef, // NOSONAR never null + parserContext.getRegistry()); } } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalWireTapParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalWireTapParser.java index aedccccdad..3208ca9f80 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalWireTapParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalWireTapParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -28,6 +28,7 @@ import org.springframework.beans.factory.xml.ParserContext; * * @author David Turanski * @author Artem Bilan + * @author Gary Russell * * @since 2.1 * @@ -50,7 +51,7 @@ public class GlobalWireTapParser extends GlobalChannelInterceptorParser { .iterator() .next() .getValue(); - return wireTapBean.getBeanName() + ".globalChannelInterceptor"; + return wireTapBean.getBeanName() + ".globalChannelInterceptor"; // NOSONAR never null } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java index 990a558893..b6315f1b02 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -209,7 +209,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar if (beanElement != null) { innerComponentDefinition = parserContext.getDelegate() .parseBeanDefinitionElement(beanElement) - .getBeanDefinition(); + .getBeanDefinition(); // NOSONAR never null } else if (isScript) { innerComponentDefinition = parserContext.getDelegate().parseCustomElement(scriptElement); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java index 70448144c7..26e4946238 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java @@ -318,7 +318,7 @@ public abstract class IntegrationNamespaceUtils { Element beanElement = childElements.get(0); BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(beanElement); - bdHolder = delegate.decorateBeanDefinitionIfRequired(beanElement, bdHolder); + bdHolder = delegate.decorateBeanDefinitionIfRequired(beanElement, bdHolder); // NOSONAR never null BeanDefinition inDef = bdHolder.getBeanDefinition(); innerComponentDefinition = new BeanComponentDefinition(inDef, bdHolder.getBeanName()); } @@ -514,7 +514,7 @@ public abstract class IntegrationNamespaceUtils { if ("bean".equals(localName)) { BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement( childElement, parentBeanDefinition); - parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); + parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); // NOSONAR never null adviceChain.add(new RuntimeBeanReference(holder.getBeanName())); } else if ("ref".equals(localName)) { @@ -636,7 +636,7 @@ public abstract class IntegrationNamespaceUtils { else { candidates = (ManagedMap) argumentValue.getValue(); } - candidates.put(handlerBeanName, channelName); + candidates.put(handlerBeanName, channelName); // NOSONAR never null } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ScatterGatherParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ScatterGatherParser.java index 5e8f819577..41b624f6a1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ScatterGatherParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ScatterGatherParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-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. @@ -36,6 +36,7 @@ import org.springframework.util.xml.DomUtils; * Parser for the <scatter-gather> element. * * @author Artem Bilan + * @author Gary Russell * @since 4.1 */ public class ScatterGatherParser extends AbstractConsumerEndpointParser { @@ -85,7 +86,7 @@ public class ScatterGatherParser extends AbstractConsumerEndpointParser { if (hasScatterer && scatterer.hasAttribute(ID_ATTRIBUTE)) { scattererId = scatterer.getAttribute(ID_ATTRIBUTE); } - parserContext.getRegistry().registerBeanDefinition(scattererId, scattererDefinition); + parserContext.getRegistry().registerBeanDefinition(scattererId, scattererDefinition); // NOSONAR not null builder.addConstructorArgValue(new RuntimeBeanReference(scattererId)); } @@ -108,7 +109,7 @@ public class ScatterGatherParser extends AbstractConsumerEndpointParser { if (gatherer != null && gatherer.hasAttribute(ID_ATTRIBUTE)) { gathererId = gatherer.getAttribute(ID_ATTRIBUTE); } - parserContext.getRegistry().registerBeanDefinition(gathererId, gathererDefinition); + parserContext.getRegistry().registerBeanDefinition(gathererId, gathererDefinition); // NOSONAR not null builder.addConstructorArgValue(new RuntimeBeanReference(gathererId)); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "gather-channel"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java index 1aa2e59f54..508037d32d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-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. @@ -37,6 +37,7 @@ import org.springframework.util.StringUtils; * Parser for the <spel-property-accessors> element. * * @author Artem Bilan + * @author Gary Russell * @since 3.0 */ public class SpelPropertyAccessorsParser implements BeanDefinitionParser { @@ -70,7 +71,7 @@ public class SpelPropertyAccessorsParser implements BeanDefinitionParser { } else if (delegate.nodeNameEquals(ele, BeanDefinitionParserDelegate.REF_ELEMENT)) { BeanReference propertyAccessorRef = (BeanReference) delegate.parsePropertySubElement(ele, null); - propertyAccessorName = propertyAccessorRef.getBeanName(); + propertyAccessorName = propertyAccessorRef.getBeanName(); // NOSONAR not null propertyAccessor = propertyAccessorRef; } else { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java index 2e8152c9cf..c2e23f8e5b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java @@ -297,9 +297,6 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo } if (targetObject instanceof Advised) { TargetSource targetSource = ((Advised) targetObject).getTargetSource(); - if (targetSource == null) { - return null; - } try { return extractTypeIfPossible(targetSource.getTarget(), expectedType); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java b/spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java index e2c17136d4..a8a3824993 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java @@ -181,9 +181,10 @@ public class ErrorMessagePublisher implements BeanFactoryAware { lastThrowable = payloadWhenNull(context); } else if (!(lastThrowable instanceof MessagingException)) { - lastThrowable = new MessagingException( - (Message) context.getAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY), - lastThrowable.getMessage(), lastThrowable); + Message message = (Message) context.getAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY); + lastThrowable = message == null + ? new MessagingException(lastThrowable.getMessage(), lastThrowable) + : new MessagingException(message, lastThrowable.getMessage(), lastThrowable); } return lastThrowable; } @@ -196,8 +197,10 @@ public class ErrorMessagePublisher implements BeanFactoryAware { * @see ErrorMessageUtils */ protected Throwable payloadWhenNull(AttributeAccessor context) { - return new MessagingException((Message) context.getAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY), - "No root cause exception available"); + Message message = (Message) context.getAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY); + return message == null + ? new MessagingException("No root cause exception available") + : new MessagingException(message, "No root cause exception available"); } private void populateChannel() { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlows.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlows.java index bd494734ec..8860a236af 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlows.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlows.java @@ -333,7 +333,9 @@ public final class IntegrationFlows { GatewayProxyFactoryBean gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean(serviceInterface); gatewayProxyFactoryBean.setDefaultRequestChannel(gatewayRequestChannel); - gatewayProxyFactoryBean.setBeanName(beanName); + if (beanName != null) { + gatewayProxyFactoryBean.setBeanName(beanName); + } return from(gatewayRequestChannel) .addComponent(gatewayProxyFactoryBean); @@ -353,6 +355,7 @@ public final class IntegrationFlows { private static IntegrationFlowBuilder from(MessagingGatewaySupport inboundGateway, IntegrationFlowBuilder integrationFlowBuilder) { + MessageChannel outputChannel = inboundGateway.getRequestChannel(); if (outputChannel == null) { outputChannel = new DirectChannel(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java index 448741c69d..e744bb7e25 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java @@ -351,8 +351,8 @@ public class IntegrationFlowBeanPostProcessor if (bean instanceof BeanNameAware) { ((BeanNameAware) bean).setBeanName(beanName); } - if (bean instanceof BeanClassLoaderAware) { - ((BeanClassLoaderAware) bean).setBeanClassLoader(this.beanFactory.getBeanClassLoader()); + if (bean instanceof BeanClassLoaderAware && this.beanFactory.getBeanClassLoader() != null) { + ((BeanClassLoaderAware) bean).setBeanClassLoader(this.beanFactory.getBeanClassLoader()); // NOSONAR } if (bean instanceof BeanFactoryAware) { ((BeanFactoryAware) bean).setBeanFactory(this.beanFactory); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java index 9bee1279fa..dc7fcbccb8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java @@ -268,9 +268,6 @@ public class SourcePollingChannelAdapter extends AbstractPollingEndpoint return target; } Advised advised = (Advised) target; - if (advised.getTargetSource() == null) { - return null; - } try { return extractProxyTarget(advised.getTargetSource().getTarget()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java index a1b4c5fbda..f8311e5842 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -61,6 +62,7 @@ import org.springframework.util.Assert; *

* * @author Artem Bilan + * @author Gary Russell * * @since 3.0 */ @@ -192,6 +194,7 @@ public final class ExpressionEvalMap extends AbstractMap { @FunctionalInterface public interface EvaluationCallback { + @Nullable Object evaluate(Expression expression); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java index d4afa8f9e9..3b8747f6db 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -19,16 +19,20 @@ package org.springframework.integration.expression; import java.util.Locale; import org.springframework.expression.Expression; +import org.springframework.lang.Nullable; /** * Strategy interface for retrieving Expressions. * * @author Mark Fisher + * @author Gary Russell + * * @since 2.0 */ @FunctionalInterface public interface ExpressionSource { + @Nullable Expression getExpression(String key, Locale locale); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionUtils.java index ad41aa4a94..7c28b236cb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionUtils.java @@ -36,6 +36,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeConverter; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.support.utils.IntegrationUtils; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -163,10 +164,12 @@ public final class ExpressionUtils { * @return the File. * @since 5.0 */ - public static File expressionToFile(Expression expression, EvaluationContext evaluationContext, Message message, - String name) { + public static File expressionToFile(Expression expression, EvaluationContext evaluationContext, + @Nullable Message message, String name) { File file; - Object value = expression.getValue(evaluationContext, message); + Object value = message == null + ? expression.getValue(evaluationContext) + : expression.getValue(evaluationContext, message); if (value == null) { throw new IllegalStateException(String.format("The provided %s expression (%s) must not evaluate to null.", name, expression.getExpressionString())); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/FunctionExpression.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/FunctionExpression.java index 9dda92857e..bb01c1b8d9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/FunctionExpression.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/FunctionExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-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. @@ -87,7 +87,8 @@ public class FunctionExpression implements Expression { @Override public Object getValue(EvaluationContext context) throws EvaluationException { - return getValue(context.getRootObject().getValue()); + Object root = context.getRootObject().getValue(); + return root == null ? getValue() : getValue(root); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/ReloadableResourceBundleExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/ReloadableResourceBundleExpressionSource.java index 3d4d1e7382..5043169e7c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/ReloadableResourceBundleExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/ReloadableResourceBundleExpressionSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -19,6 +19,7 @@ package org.springframework.integration.expression; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -37,6 +38,7 @@ import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; import org.springframework.expression.spel.SpelParserConfiguration; import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; @@ -240,13 +242,14 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc */ @Override public Expression getExpression(String key, Locale locale) { - String expressionString = this.getExpressionString(key, locale); + String expressionString = getExpressionString(key, locale); if (expressionString != null) { return this.parser.parseExpression(expressionString); } return null; } + @Nullable private String getExpressionString(String key, Locale locale) { if (this.cacheMillis < 0) { PropertiesHolder propHolder = getMergedProperties(locale); @@ -476,32 +479,15 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc InputStream is = resource.getInputStream(); Properties props = new Properties(); try { - if (resource.getFilename().endsWith(XML_SUFFIX)) { + String resourceFilename = resource.getFilename(); + if (resourceFilename != null && resourceFilename.endsWith(XML_SUFFIX)) { if (logger.isDebugEnabled()) { - logger.debug("Loading properties [" + resource.getFilename() + "]"); + logger.debug("Loading properties [" + resourceFilename + "]"); } this.propertiesPersister.loadFromXml(props, is); } else { - String encoding = null; - if (this.fileEncodings != null) { - encoding = this.fileEncodings.getProperty(filename); - } - if (encoding == null) { - encoding = this.defaultEncoding; - } - if (encoding != null) { - if (logger.isDebugEnabled()) { - logger.debug("Loading properties [" + resource.getFilename() + "] with encoding '" + encoding + "'"); - } - this.propertiesPersister.load(props, new InputStreamReader(is, encoding)); - } - else { - if (logger.isDebugEnabled()) { - logger.debug("Loading properties [" + resource.getFilename() + "]"); - } - this.propertiesPersister.load(props, is); - } + loadFromProperties(resource, filename, is, props, resourceFilename); } return props; } @@ -510,6 +496,32 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc } } + private void loadFromProperties(Resource resource, String filename, InputStream is, Properties props, + String resourceFilename) throws IOException, UnsupportedEncodingException { + String encoding = null; + if (this.fileEncodings != null) { + encoding = this.fileEncodings.getProperty(filename); + } + if (encoding == null) { + encoding = this.defaultEncoding; + } + if (encoding != null) { + if (logger.isDebugEnabled()) { + logger.debug("Loading properties [" + + (resourceFilename == null ? resource : resourceFilename) + + "] with encoding '" + encoding + "'"); + } + this.propertiesPersister.load(props, new InputStreamReader(is, encoding)); + } + else { + if (logger.isDebugEnabled()) { + logger.debug("Loading properties [" + (resourceFilename == null ? resource : resourceFilename) + + "]"); + } + this.propertiesPersister.load(props, is); + } + } + /** * Clear the resource bundle cache. @@ -570,6 +582,7 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc return this.refreshTimestamp; } + @Nullable public String getProperty(String code) { if (this.properties == null) { return null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/SupplierExpression.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/SupplierExpression.java index 71bb1ec9ec..d94f7feb99 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/SupplierExpression.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/SupplierExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-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. @@ -16,7 +16,7 @@ package org.springframework.integration.expression; -import org.boon.core.Supplier; +import java.util.function.Supplier; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; @@ -86,7 +86,8 @@ public class SupplierExpression implements Expression { @Override public Object getValue(EvaluationContext context) throws EvaluationException { - return getValue(context.getRootObject().getValue()); + Object root = context.getRootObject().getValue(); + return root == null ? getValue() : getValue(root); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/package-info.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/package-info.java index 46da20b571..06cd283d61 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/package-info.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/package-info.java @@ -1,4 +1,5 @@ /** * Provides classes supporting SpEL expressions. */ +@org.springframework.lang.NonNullApi package org.springframework.integration.expression; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java index bf9f56dbd7..864e587574 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java @@ -58,7 +58,7 @@ public class AnnotationGatewayProxyFactoryBean extends GatewayProxyFactoryBean { this.gatewayAttributes = gatewayAttributes; String id = gatewayAttributes.getString("name"); - if (!StringUtils.hasText(id)) { + if (StringUtils.hasText(id)) { setBeanName(id); } } @@ -88,11 +88,15 @@ public class AnnotationGatewayProxyFactoryBean extends GatewayProxyFactoryBean { String defaultRequestChannel = beanFactory.resolveEmbeddedValue(this.gatewayAttributes.getString("defaultRequestChannel")); - setDefaultRequestChannelName(defaultRequestChannel); + if (StringUtils.hasText(defaultRequestChannel)) { + setDefaultRequestChannelName(defaultRequestChannel); + } String defaultReplyChannel = beanFactory.resolveEmbeddedValue(this.gatewayAttributes.getString("defaultReplyChannel")); - setDefaultReplyChannelName(defaultReplyChannel); + if (StringUtils.hasText(defaultReplyChannel)) { + setDefaultReplyChannelName(defaultReplyChannel); + } String errorChannel = beanFactory.resolveEmbeddedValue(this.gatewayAttributes.getString("errorChannel")); setErrorChannelName(errorChannel); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java index 11a838bf14..f5c5f28f47 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java @@ -360,6 +360,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint * @return the channel. * @since 4.2 */ + @Nullable public MessageChannel getRequestChannel() { if (this.requestChannelName != null) { synchronized (this) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java index f9748a446f..41204293d8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java @@ -352,7 +352,9 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat private MessageGatewayNode gatewayNode(String name, MessagingGatewaySupport gateway) { String errorChannel = gateway.getErrorChannel() != null ? gateway.getErrorChannel().toString() : null; - String requestChannel = gateway.getRequestChannel() != null ? gateway.getRequestChannel().toString() : null; + String requestChannel = gateway.getRequestChannel() != null + ? gateway.getRequestChannel().toString() // NOSONAR not null + : null; return new MessageGatewayNode(this.nodeId.incrementAndGet(), name, gateway, requestChannel, errorChannel); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java index 81d365bf06..2387d7ccf8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java @@ -137,14 +137,12 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler imple } protected ConversionService getRequiredConversionService() { - if (this.getConversionService() == null) { - synchronized (this) { - if (getConversionService() == null) { - setConversionService(DefaultConversionService.getSharedInstance()); - } - } + ConversionService conversionService = getConversionService(); + if (conversionService == null) { + conversionService = DefaultConversionService.getSharedInstance(); + setConversionService(conversionService); } - return getConversionService(); + return conversionService; } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupQueue.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupQueue.java index d69b4aa462..ce4caf2a78 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupQueue.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupQueue.java @@ -349,6 +349,7 @@ public class MessageGroupQueue extends AbstractQueue> implements Bloc /** * It is assumed that the 'storeLock' is being held by the caller, otherwise * IllegalMonitorStateException may be thrown + * @return a message // TODO @Nullable */ protected Message doPoll() { Message message = this.messageGroupStore.pollMessageFromGroup(this.groupId); @@ -360,6 +361,7 @@ public class MessageGroupQueue extends AbstractQueue> implements Bloc * It is assumed that the 'storeLock' is being held by the caller, otherwise * IllegalMonitorStateException may be thrown * @param message the message to offer. + * @return true if offered. */ protected boolean doOffer(Message message) { boolean offered = false; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index ab26a4ce61..6be70aeef0 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -448,9 +448,8 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); if (this.destinationDirectoryExpression instanceof LiteralExpression) { - final File directory = - new File(this.destinationDirectoryExpression.getValue(this.evaluationContext, String.class)); - + final File directory = ExpressionUtils.expressionToFile(this.destinationDirectoryExpression, + this.evaluationContext, null, "destinationDirectoryExpression"); validateDestinationDirectory(directory, this.autoCreateDirectory); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java index ac8f56906b..a9f4a45c72 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java @@ -253,7 +253,7 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea adapter.setApplicationEventPublisher(this.applicationEventPublisher); } if (getBeanFactory() != null) { - adapter.setBeanFactory(getBeanFactory()); + adapter.setBeanFactory(getBeanFactory()); // NOSONAR never null } adapter.afterPropertiesSet(); this.adapter = adapter; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/ExpressionFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/ExpressionFileListFilter.java index 5a96b10c45..565c658332 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/ExpressionFileListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/ExpressionFileListFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-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. @@ -30,6 +30,7 @@ import org.springframework.util.Assert; * A SpEL expression based {@link AbstractFileListFilter} implementation. * * @author Artem Bilan + * @author Gary Russell * * @since 5.0 */ @@ -61,7 +62,8 @@ public class ExpressionFileListFilter extends AbstractFileListFilter @Override public boolean accept(F file) { - return this.expression.getValue(getEvaluationContext(), file, Boolean.class); + Boolean pass = this.expression.getValue(getEvaluationContext(), file, Boolean.class); + return pass == null ? false : pass; } private EvaluationContext getEvaluationContext() { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index 084a258b54..09b5bc38d7 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -536,7 +536,9 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply || Command.MGET.equals(this.command)) { Assert.notNull(this.localDirectoryExpression, "localDirectory must not be null"); if (this.localDirectoryExpression instanceof ValueExpression) { - File localDirectory = this.localDirectoryExpression.getValue(File.class); + File localDirectory = ExpressionUtils.expressionToFile(this.localDirectoryExpression, + ExpressionUtils.createStandardEvaluationContext(getBeanFactory()), null, + "localDirectoryExpression"); try { if (!localDirectory.exists()) { if (this.autoCreateLocalDirectory) { diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java index fad2ab0e94..196d8cc78c 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-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. @@ -54,7 +54,7 @@ public class FtpOutboundChannelAdapterParser extends RemoteFileOutboundChannelAd .iterator() .next() .getValue(); - templateDefinition.getPropertyValues() + templateDefinition.getPropertyValues() // NOSONAR never null .add("existsMode", FtpRemoteFileTemplate.ExistsMode.NLST); } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParser.java index d404f46285..76e506ab89 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParser.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. @@ -66,7 +66,7 @@ public class FtpOutboundGatewayParser extends AbstractRemoteFileOutboundGatewayP .iterator() .next() .getValue(); - templateDefinition.getPropertyValues() + templateDefinition.getPropertyValues() // NOSONAR never null .add("existsMode", FtpRemoteFileTemplate.ExistsMode.NLST); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "working-dir-expression", diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java index 6018c4cecc..3c5afaa274 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java @@ -217,7 +217,7 @@ public class FtpTests extends FtpTestSupport { assertNotNull(result); List localFiles = (List) result.getPayload(); // should have filtered ftpSource2.txt - assertEquals(2, localFiles.size()); + assertEquals("unexpected local files " + localFiles, 2, localFiles.size()); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),