From 2b1976ce6f10b491437e5c0d49fe05921ba53478 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 26 Oct 2018 16:01:15 -0400 Subject: [PATCH] Core Sonar fixes * Polishing according PR comments --- .../IntegrationMessageHeaderAccessor.java | 2 +- .../channel/AbstractExecutorChannel.java | 6 +++-- .../channel/AbstractMessageChannel.java | 10 ++++++--- .../integration/channel/ChannelPurger.java | 6 +++-- .../integration/channel/PriorityChannel.java | 3 ++- .../channel/PublishSubscribeChannel.java | 3 ++- .../config/xml/ScatterGatherParser.java | 4 +++- .../context/IntegrationObjectSupport.java | 6 +---- .../core/ErrorMessagePublisher.java | 5 +++-- .../integration/dsl/IntegrationFlows.java | 3 ++- .../endpoint/AbstractPollingEndpoint.java | 2 +- .../gateway/GatewayMessageHandler.java | 5 +++-- .../GatewayMethodInboundMessageMapper.java | 22 ++++++++++++------- .../gateway/GatewayProxyFactoryBean.java | 4 +++- .../gateway/MessagingGatewaySupport.java | 1 + .../integration/leader/AbstractCandidate.java | 6 +++-- .../mapping/AbstractHeaderMapper.java | 1 + .../support/DefaultErrorMessageStrategy.java | 7 +++++- .../integration/support/MutableMessage.java | 6 +++-- .../support/MutableMessageHeaders.java | 2 ++ .../micrometer/MicrometerMetricsCaptor.java | 2 +- .../support/utils/IntegrationUtils.java | 11 +++++++--- ...TransactionSynchronizationFactoryBean.java | 8 ++++++- .../transformer/ContentEnricher.java | 4 ++-- .../config/XmppHeaderEnricherParserTests.java | 3 ++- 25 files changed, 88 insertions(+), 44 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java b/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java index 03dfa00c9d..11c2593d75 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java @@ -69,7 +69,7 @@ public class IntegrationMessageHeaderAccessor extends MessageHeaderAccessor { private Set readOnlyHeaders = new HashSet<>(); - public IntegrationMessageHeaderAccessor(Message message) { + public IntegrationMessageHeaderAccessor(@Nullable Message message) { super(message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java index 42d3f60f22..0023355b7a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-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. @@ -24,6 +24,7 @@ import java.util.concurrent.Executor; import org.springframework.integration.dispatcher.AbstractDispatcher; import org.springframework.integration.support.MessagingExceptionWrapper; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; @@ -60,7 +61,7 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne protected volatile int executorInterceptorsSize; - public AbstractExecutorChannel(Executor executor) { + public AbstractExecutorChannel(@Nullable Executor executor) { this.executor = executor; } @@ -171,6 +172,7 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne } } + @Nullable private Message applyBeforeHandle(Message message, Deque interceptorStack) { Message theMessage = message; for (ChannelInterceptor interceptor : AbstractExecutorChannel.this.interceptors.interceptors) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index 5b2f58997d..66b18e4e57 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -554,7 +554,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport @Override public void destroy() throws Exception { - this.meters.forEach(t -> t.remove()); + this.meters.forEach(MeterFacade::remove); } /** @@ -566,7 +566,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport protected final List interceptors = new CopyOnWriteArrayList(); - private volatile int size; + private int size; public ChannelInterceptorList(Log logger) { this.logger = logger; @@ -594,17 +594,19 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport this.interceptors.add(index, interceptor); } + @Nullable public Message preSend(Message message, MessageChannel channel, Deque interceptorStack) { if (this.size > 0) { for (ChannelInterceptor interceptor : this.interceptors) { + Message previous = message; message = interceptor.preSend(message, channel); if (message == null) { if (this.logger.isDebugEnabled()) { this.logger.debug(interceptor.getClass().getSimpleName() + " returned null from preSend, i.e. precluding the send."); } - afterSendCompletion(null, channel, false, null, interceptorStack); + afterSendCompletion(previous, channel, false, null, interceptorStack); return null; } interceptorStack.add(interceptor); @@ -648,6 +650,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport return true; } + @Nullable public Message postReceive(Message message, MessageChannel channel) { if (this.size > 0) { for (ChannelInterceptor interceptor : this.interceptors) { @@ -688,6 +691,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport } } + @Nullable public ChannelInterceptor remove(int index) { ChannelInterceptor removed = this.interceptors.remove(index); if (removed != null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/ChannelPurger.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/ChannelPurger.java index 44b407d958..9b131657e9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/ChannelPurger.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/ChannelPurger.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. @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.integration.core.MessageSelector; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -38,6 +39,7 @@ import org.springframework.util.Assert; * place. Such messages will not be included in the returned list. * * @author Mark Fisher + * @author Gary Russell */ public class ChannelPurger { @@ -50,7 +52,7 @@ public class ChannelPurger { this(null, channels); } - public ChannelPurger(MessageSelector selector, QueueChannel... channels) { + public ChannelPurger(@Nullable MessageSelector selector, QueueChannel... channels) { Assert.notEmpty(channels, "at least one channel is required"); if (channels.length == 1) { Assert.notNull(channels[0], "channel must not be null"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/PriorityChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/PriorityChannel.java index 6817265e68..ba05858660 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/PriorityChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/PriorityChannel.java @@ -24,6 +24,7 @@ import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.integration.store.MessageGroupQueue; import org.springframework.integration.store.PriorityCapableChannelMessageStore; import org.springframework.integration.util.UpperBound; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -84,7 +85,7 @@ public class PriorityChannel extends QueueChannel { * @param capacity The capacity. * @param comparator The comparator. */ - public PriorityChannel(int capacity, Comparator> comparator) { + public PriorityChannel(int capacity, @Nullable Comparator> comparator) { super(new PriorityBlockingQueue<>(11, new SequenceFallbackComparator(comparator))); this.upperBound = new UpperBound(capacity); this.useMessageStore = false; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/PublishSubscribeChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/PublishSubscribeChannel.java index 27333600b7..495498efe9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/PublishSubscribeChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/PublishSubscribeChannel.java @@ -22,6 +22,7 @@ import org.springframework.integration.context.IntegrationProperties; import org.springframework.integration.dispatcher.BroadcastingDispatcher; import org.springframework.integration.support.channel.BeanFactoryChannelResolver; import org.springframework.integration.util.ErrorHandlingTaskExecutor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ErrorHandler; @@ -49,7 +50,7 @@ public class PublishSubscribeChannel extends AbstractExecutorChannel { * the message sender's thread. * @param executor The executor. */ - public PublishSubscribeChannel(Executor executor) { + public PublishSubscribeChannel(@Nullable Executor executor) { super(executor); this.dispatcher = new BroadcastingDispatcher(executor); } 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 710703ce21..5e8f819577 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 @@ -98,9 +98,11 @@ public class ScatterGatherParser extends AbstractConsumerEndpointParser { } catch (ParserConfigurationException e) { parserContext.getReaderContext().error(e.getMessage(), element); + // NOSONAR below to prevent a false positive in SONAR for a null gatherer } } - gathererDefinition = GATHERER_PARSER.parse(gatherer, new ParserContext(parserContext.getReaderContext(), + gathererDefinition = GATHERER_PARSER.parse(gatherer, // NOSONAR + new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), scatterGatherDefinition)); String gathererId = id + ".gatherer"; if (gatherer != null && gatherer.hasAttribute(ID_ATTRIBUTE)) { 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 84cb5588ac..2e8152c9cf 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 @@ -227,11 +227,7 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo public ConversionService getConversionService() { if (this.conversionService == null && this.beanFactory != null) { - synchronized (this) { - if (this.conversionService == null) { - this.conversionService = IntegrationUtils.getConversionService(this.beanFactory); - } - } + this.conversionService = IntegrationUtils.getConversionService(this.beanFactory); if (this.conversionService == null && this.logger.isDebugEnabled()) { this.logger.debug("Unable to attempt conversion of Message payload types. Component '" + this.getComponentName() + "' has no explicit ConversionService reference, " + 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 713e45d59b..6ef96d80c0 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 @@ -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. @@ -27,6 +27,7 @@ import org.springframework.integration.support.DefaultErrorMessageStrategy; import org.springframework.integration.support.ErrorMessageStrategy; import org.springframework.integration.support.ErrorMessageUtils; import org.springframework.integration.support.channel.BeanFactoryChannelResolver; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessagingException; @@ -144,7 +145,7 @@ public class ErrorMessagePublisher implements BeanFactoryAware { * @param failedMessage the message. * @param throwable the throwable. */ - public void publish(Message inputMessage, Message failedMessage, Throwable throwable) { + public void publish(@Nullable Message inputMessage, Message failedMessage, Throwable throwable) { publish(throwable, ErrorMessageUtils.getAttributeAccessor(inputMessage, failedMessage)); } 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 0ce3a3e992..bd494734ec 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 @@ -32,6 +32,7 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean; import org.springframework.integration.gateway.GatewayProxyFactoryBean; import org.springframework.integration.gateway.MessagingGatewaySupport; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; @@ -326,7 +327,7 @@ public final class IntegrationFlows { * @param beanName the bean name to be used for registering bean for the gateway proxy * @return new {@link IntegrationFlowBuilder}. */ - public static IntegrationFlowBuilder from(Class serviceInterface, String beanName) { + public static IntegrationFlowBuilder from(Class serviceInterface, @Nullable String beanName) { final DirectChannel gatewayRequestChannel = new DirectChannel(); GatewayProxyFactoryBean gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean(serviceInterface); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractPollingEndpoint.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractPollingEndpoint.java index f8e755cf68..07e7bf3ae7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractPollingEndpoint.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractPollingEndpoint.java @@ -341,7 +341,7 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement failedMessage = ((IntegrationResourceHolder) resource).getMessage(); } } - throw new MessagingException(failedMessage, e); + throw new MessagingException(failedMessage, e); // NOSONAR (null failedMessage) } } finally { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java index f054f815b8..bcaad52712 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-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. @@ -92,7 +92,8 @@ public class GatewayMessageHandler extends AbstractReplyProducingMessageHandler BeanFactory beanFactory = getBeanFactory(); if (beanFactory instanceof ConfigurableListableBeanFactory) { - ((ConfigurableListableBeanFactory) beanFactory).initializeBean(this.gatewayProxyFactoryBean, null); + ((ConfigurableListableBeanFactory) beanFactory).initializeBean(this.gatewayProxyFactoryBean, + getComponentName() + "#gpfb"); } try { this.exchanger = (RequestReplyExchanger) this.gatewayProxyFactoryBean.getObject(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java index 91d7b60bf9..c073eb3be5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java @@ -118,20 +118,25 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper headerExpressions) { + GatewayMethodInboundMessageMapper(Method method, @Nullable Map headerExpressions) { this(method, headerExpressions, null, null, null); } - GatewayMethodInboundMessageMapper(Method method, Map headerExpressions, - Map globalHeaderExpressions, MethodArgsMessageMapper mapper, - MessageBuilderFactory messageBuilderFactory) { + GatewayMethodInboundMessageMapper(Method method, + @Nullable Map headerExpressions, + @Nullable Map globalHeaderExpressions, + @Nullable MethodArgsMessageMapper mapper, + @Nullable MessageBuilderFactory messageBuilderFactory) { this(method, headerExpressions, globalHeaderExpressions, null, mapper, messageBuilderFactory); } - GatewayMethodInboundMessageMapper(Method method, Map headerExpressions, - Map globalHeaderExpressions, Map headers, - MethodArgsMessageMapper mapper, - MessageBuilderFactory messageBuilderFactory) { + GatewayMethodInboundMessageMapper(Method method, + @Nullable Map headerExpressions, + @Nullable Map globalHeaderExpressions, + @Nullable Map headers, + @Nullable MethodArgsMessageMapper mapper, + @Nullable MessageBuilderFactory messageBuilderFactory) { + Assert.notNull(method, "method must not be null"); this.method = method; this.headerExpressions = headerExpressions; @@ -262,6 +267,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper will run on the calling thread"); @@ -474,6 +475,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint } } + @Nullable private Object invokeGatewayMethod(MethodInvocation invocation, boolean runningOnCallerThread) throws Exception { if (!this.initialized) { this.afterPropertiesSet(); 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 bc225cc0a6..11a838bf14 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 @@ -471,6 +471,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint } @SuppressWarnings("unchecked") + @Nullable private Object doSendAndReceive(Object object, boolean shouldConvert) { this.initializeIfNecessary(); Assert.notNull(object, "request must not be null"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/leader/AbstractCandidate.java b/spring-integration-core/src/main/java/org/springframework/integration/leader/AbstractCandidate.java index 8eab8f474f..469e3d4ebb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/leader/AbstractCandidate.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/leader/AbstractCandidate.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-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. @@ -18,12 +18,14 @@ package org.springframework.integration.leader; import java.util.UUID; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** * Base implementation of a {@link Candidate}. * * @author Janne Valkealahti + * @author Gary Russell * */ public abstract class AbstractCandidate implements Candidate { @@ -47,7 +49,7 @@ public abstract class AbstractCandidate implements Candidate { * @param id the identifier * @param role the role */ - public AbstractCandidate(String id, String role) { + public AbstractCandidate(@Nullable String id, @Nullable String role) { this.id = StringUtils.hasText(id) ? id : UUID.randomUUID().toString(); this.role = StringUtils.hasText(role) ? role : DEFAULT_ROLE; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java index e4291491d4..da844b33c2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java @@ -280,6 +280,7 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe } @SuppressWarnings("unchecked") + @Nullable protected V getHeaderIfAvailable(Map headers, String name, Class type) { Object value = headers.get(name); if (value == null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/DefaultErrorMessageStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/support/DefaultErrorMessageStrategy.java index 2a2b4b1e87..6adfda61c0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/DefaultErrorMessageStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/DefaultErrorMessageStrategy.java @@ -40,7 +40,12 @@ public class DefaultErrorMessageStrategy implements ErrorMessageStrategy { public ErrorMessage buildErrorMessage(Throwable throwable, @Nullable AttributeAccessor attributes) { Object inputMessage = attributes == null ? null : attributes.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY); - return new ErrorMessage(throwable, inputMessage instanceof Message ? (Message) inputMessage : null); + if (inputMessage instanceof Message) { + return new ErrorMessage(throwable, (Message) inputMessage); + } + else { + return new ErrorMessage(throwable); + } } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java index 05d01e53eb..944e4a1b8e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.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. @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Map; import org.springframework.integration.store.SimpleMessageStore; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.util.Assert; @@ -60,7 +61,7 @@ public class MutableMessage implements Message, Serializable { this(payload, (Map) null); } - public MutableMessage(T payload, Map headers) { + public MutableMessage(T payload, @Nullable Map headers) { this(payload, new MutableMessageHeaders(headers)); } @@ -85,6 +86,7 @@ public class MutableMessage implements Message, Serializable { return this.headers.getRawHeaders(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(getClass().getSimpleName()); sb.append(" [payload="); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessageHeaders.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessageHeaders.java index 318fc38993..4200962cb5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessageHeaders.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessageHeaders.java @@ -74,6 +74,7 @@ public class MutableMessageHeaders extends MessageHeaders { return super.getRawHeaders().remove(key); } + @Nullable private static UUID extractId(@Nullable Map headers) { if (headers != null && headers.containsKey(MessageHeaders.ID)) { Object id = headers.get(MessageHeaders.ID); @@ -92,6 +93,7 @@ public class MutableMessageHeaders extends MessageHeaders { return null; } + @Nullable private static Long extractTimestamp(@Nullable Map headers) { if (headers != null && headers.containsKey(MessageHeaders.TIMESTAMP)) { Object timestamp = headers.get(MessageHeaders.TIMESTAMP); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java index e83d4c9491..72dd0ebe8a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java @@ -102,7 +102,7 @@ public class MicrometerMetricsCaptor implements MetricsCaptor { } } - private class MicroSample implements SampleFacade { + private static class MicroSample implements SampleFacade { private final Timer.Sample sample; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/utils/IntegrationUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/support/utils/IntegrationUtils.java index 12fbeb3ff6..e4d07ba251 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/utils/IntegrationUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/utils/IntegrationUtils.java @@ -52,7 +52,8 @@ public final class IntegrationUtils { /** * Should be set to TRUE on CI plans and framework developer systems. */ - public static final boolean fatalWhenNoBeanFactory = Boolean.valueOf(System.getenv("SI_FATAL_WHEN_NO_BEANFACTORY")); + public static final boolean fatalWhenNoBeanFactory = + Boolean.valueOf(System.getenv("SI_FATAL_WHEN_NO_BEANFACTORY")); private IntegrationUtils() { super(); @@ -154,7 +155,9 @@ public final class IntegrationUtils { * @return the wrapper, if necessary, or the original exception. * @since 5.0.4 */ - public static RuntimeException wrapInDeliveryExceptionIfNecessary(Message message, Supplier text, Exception e) { + public static RuntimeException wrapInDeliveryExceptionIfNecessary(Message message, Supplier text, + Exception e) { + RuntimeException runtimeException = (e instanceof RuntimeException) ? (RuntimeException) e : new MessageDeliveryException(message, text.get(), e); @@ -175,7 +178,9 @@ public final class IntegrationUtils { * @return the wrapper, if necessary, or the original exception. * @since 5.0.4 */ - public static RuntimeException wrapInHandlingExceptionIfNecessary(Message message, Supplier text, Exception e) { + public static RuntimeException wrapInHandlingExceptionIfNecessary(Message message, Supplier text, + Exception e) { + RuntimeException runtimeException = (e instanceof RuntimeException) ? (RuntimeException) e : new MessageHandlingException(message, text.get(), e); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java index 54a19eb0a2..75f5dcec90 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java @@ -16,6 +16,8 @@ package org.springframework.integration.transaction; +import java.util.concurrent.atomic.AtomicInteger; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -33,6 +35,7 @@ import org.springframework.util.StringUtils; * from JavaConfig to populate {@link DefaultTransactionSynchronizationFactory} bean. * * @author Artem Bilan + * @author Gary Russell * @since 4.0 */ public class TransactionSynchronizationFactoryBean implements FactoryBean, @@ -40,6 +43,8 @@ public class TransactionSynchronizationFactoryBean implements FactoryBean { - Message message = invocation.getArgument(0); + Message message = invocation.getArgument(0); String chatToUser = (String) message.getHeaders().get(XmppHeaders.TO); assertNotNull(chatToUser); assertEquals("test1@example.org", chatToUser);