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 7c8fe9ba5d..e876b37702 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-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -68,12 +68,12 @@ import org.springframework.util.StringUtils; */ public class ReloadableResourceBundleExpressionSource implements ExpressionSource, ResourceLoaderAware { + private static final Log LOGGER = LogFactory.getLog(ReloadableResourceBundleExpressionSource.class); + private static final String PROPERTIES_SUFFIX = ".properties"; private static final String XML_SUFFIX = ".xml"; - private static final Log LOGGER = LogFactory.getLog(ReloadableResourceBundleExpressionSource.class); - /** * Cache to hold filename lists per Locale @@ -211,7 +211,7 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc * @param cacheSeconds The cache seconds. */ public void setCacheSeconds(int cacheSeconds) { - this.cacheMillis = (cacheSeconds * 1000); + this.cacheMillis = (cacheSeconds * 1000); // NOSONAR } /** @@ -324,8 +324,7 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc return filenames; } } - List filenames = new ArrayList<>(7); - filenames.addAll(calculateFilenamesForLocale(basename, locale)); + List filenames = new ArrayList<>(calculateFilenamesForLocale(basename, locale)); if (this.fallbackToSystemLocale && !locale.equals(Locale.getDefault())) { List fallbackFilenames = calculateFilenamesForLocale(basename, Locale.getDefault()); for (String fallbackFilename : fallbackFilenames) { @@ -359,7 +358,7 @@ public class ReloadableResourceBundleExpressionSource implements ExpressionSourc * @return the List of filenames to check */ private List calculateFilenamesForLocale(String basename, Locale locale) { - List result = new ArrayList<>(3); + List result = new ArrayList<>(); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java index a63d436b9c..73e94b3fc7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 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. @@ -170,11 +170,8 @@ public class IdempotentReceiverInterceptor extends AbstractHandleMessageAdvice { } private MessageChannel obtainDiscardChannel() { - if (this.discardChannel == null) { - if (this.discardChannelName != null) { - this.discardChannel = getChannelResolver() - .resolveDestination(this.discardChannelName); - } + if (this.discardChannel == null && this.discardChannelName != null) { + this.discardChannel = getChannelResolver().resolveDestination(this.discardChannelName); } return this.discardChannel; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerCircuitBreakerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerCircuitBreakerAdvice.java index a03f018834..df86312a91 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerCircuitBreakerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerCircuitBreakerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,9 +36,19 @@ import org.springframework.messaging.MessagingException; */ public class RequestHandlerCircuitBreakerAdvice extends AbstractRequestHandlerAdvice { - private volatile int threshold = 5; + /** + * A default failures threshold as {@value DEFAULT_THRESHOLD}. + */ + public static final int DEFAULT_THRESHOLD = 5; - private volatile long halfOpenAfter = 1000; + /** + * A half-open duration as {@value DEFAULT_HALF_OPEN_AFTER} . + */ + public static final int DEFAULT_HALF_OPEN_AFTER = 1000; + + private int threshold = DEFAULT_THRESHOLD; + + private long halfOpenAfter = DEFAULT_HALF_OPEN_AFTER; private final ConcurrentMap metadataMap = new ConcurrentHashMap<>(); @@ -101,6 +111,7 @@ public class RequestHandlerCircuitBreakerAdvice extends AbstractRequestHandlerAd private AtomicInteger getFailures() { return this.failures; } + } /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerRetryAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerRetryAdvice.java index 95c2dfb892..666b9a42c4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerRetryAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RequestHandlerRetryAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,17 +37,18 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Artem Bilan + * * @since 2.2 */ public class RequestHandlerRetryAdvice extends AbstractRequestHandlerAdvice implements RetryListener { + private static final ThreadLocal> MESSAGE_HOLDER = new ThreadLocal<>(); + private RetryTemplate retryTemplate = new RetryTemplate(); private RecoveryCallback recoveryCallback; - private static final ThreadLocal> messageHolder = new ThreadLocal>(); - // Stateless unless a state generator is provided private volatile RetryStateGenerator retryStateGenerator = message -> null; @@ -78,9 +79,8 @@ public class RequestHandlerRetryAdvice extends AbstractRequestHandlerAdvice @Override protected Object doInvoke(final ExecutionCallback callback, Object target, final Message message) { - RetryState retryState = null; - retryState = this.retryStateGenerator.determineRetryState(message); - messageHolder.set(message); + RetryState retryState = this.retryStateGenerator.determineRetryState(message); + MESSAGE_HOLDER.set(message); try { return this.retryTemplate.execute(context -> callback.cloneAndExecute(), this.recoveryCallback, retryState); @@ -98,13 +98,13 @@ public class RequestHandlerRetryAdvice extends AbstractRequestHandlerAdvice throw new ThrowableHolderException(e); } finally { - messageHolder.remove(); + MESSAGE_HOLDER.remove(); } } @Override public boolean open(RetryContext context, RetryCallback callback) { - context.setAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY, messageHolder.get()); + context.setAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY, MESSAGE_HOLDER.get()); return true; } 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 3e3cefce03..52f166af83 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 @@ -128,7 +128,6 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe * Provide the header names that should be mapped to a response * from a {@link MessageHeaders}. *

The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched. - * * @param replyHeaderNames The reply header names. */ public void setReplyHeaderNames(String... replyHeaderNames) { @@ -141,7 +140,7 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe * standard header prefix. * @param standardHeaderPrefix the prefix for standard headers. * @param headerNames the collection of header names to map. - * @return the deafault {@link HeaderMatcher} instance. + * @return the default {@link HeaderMatcher} instance. */ protected HeaderMatcher createDefaultHeaderMatcher(String standardHeaderPrefix, Collection headerNames) { return new ContentBasedHeaderMatcher(true, headerNames); @@ -401,6 +400,7 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe /** * Strategy interface to determine if a given header name matches. + * * @since 4.1 */ @FunctionalInterface @@ -427,11 +427,12 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe * A content-based {@link HeaderMatcher} that matches if the specified * header is contained within a list of candidates. The case of the * header does not matter. + * * @since 4.1 */ protected static class ContentBasedHeaderMatcher implements HeaderMatcher { - private static final Log logger = LogFactory.getLog(HeaderMatcher.class); + private static final Log LOGGER = LogFactory.getLog(HeaderMatcher.class); private final boolean match; @@ -446,13 +447,13 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe @Override public boolean matchHeader(String headerName) { boolean result = (this.match == containsIgnoreCase(headerName)); - if (result && logger.isDebugEnabled()) { + if (result && LOGGER.isDebugEnabled()) { StringBuilder message = new StringBuilder("headerName=[{0}] WILL be mapped, "); if (!this.match) { message.append("not "); } message.append("found in {1}"); - logger.debug(MessageFormat.format(message.toString(), headerName, this.content)); + LOGGER.debug(MessageFormat.format(message.toString(), headerName, this.content)); } return result; } @@ -471,12 +472,14 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe /** * A pattern-based {@link HeaderMatcher} that matches if the specified * header matches one of the specified simple patterns. - * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String) + * * @since 4.1 + * + * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String) */ protected static class PatternBasedHeaderMatcher implements HeaderMatcher { - private static final Log logger = LogFactory.getLog(HeaderMatcher.class); + private static final Log LOGGER = LogFactory.getLog(HeaderMatcher.class); private final Collection patterns = new ArrayList<>(); @@ -493,8 +496,8 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe String header = headerName.toLowerCase(); for (String pattern : this.patterns) { if (PatternMatchUtils.simpleMatch(pattern, header)) { - if (logger.isDebugEnabled()) { - logger.debug(MessageFormat.format( + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(MessageFormat.format( "headerName=[{0}] WILL be mapped, matched pattern={1}", headerName, pattern)); } return true; @@ -509,12 +512,14 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe * A pattern-based {@link HeaderMatcher} that matches if the specified * header matches the specified simple pattern. *

The {@code negate == true} state indicates if the matching should be treated as "not matched". - * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String) + * * @since 4.3 + * + * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String) */ protected static class SinglePatternBasedHeaderMatcher implements HeaderMatcher { - private static final Log logger = LogFactory.getLog(HeaderMatcher.class); + private static final Log LOGGER = LogFactory.getLog(HeaderMatcher.class); private final String pattern; @@ -534,8 +539,8 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe public boolean matchHeader(String headerName) { String header = headerName.toLowerCase(); if (PatternMatchUtils.simpleMatch(this.pattern, header)) { - if (logger.isDebugEnabled()) { - logger.debug(MessageFormat.format( + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(MessageFormat.format( "headerName=[{0}] WILL be mapped, matched pattern={1}", headerName, this.pattern)); } return true; @@ -553,11 +558,12 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe /** * A prefix-based {@link HeaderMatcher} that matches if the specified * header starts with a configurable prefix. + * * @since 4.1 */ protected static class PrefixBasedMatcher implements HeaderMatcher { - private static final Log logger = LogFactory.getLog(HeaderMatcher.class); + private static final Log LOGGER = LogFactory.getLog(HeaderMatcher.class); private final boolean match; @@ -571,13 +577,13 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe @Override public boolean matchHeader(String headerName) { boolean result = (this.match == headerName.startsWith(this.prefix)); - if (result && logger.isDebugEnabled()) { + if (result && LOGGER.isDebugEnabled()) { StringBuilder message = new StringBuilder("headerName=[{0}] WILL be mapped, "); if (!this.match) { message.append("does not "); } message.append("start with [{1}]"); - logger.debug(MessageFormat.format(message.toString(), headerName, this.prefix)); + LOGGER.debug(MessageFormat.format(message.toString(), headerName, this.prefix)); } return result; } @@ -587,11 +593,12 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe /** * A composite {@link HeaderMatcher} that matches if one of provided * {@link HeaderMatcher}s matches to the {@code headerName}. + * * @since 4.1 */ protected static class CompositeHeaderMatcher implements HeaderMatcher { - private static final Log logger = LogFactory.getLog(HeaderMatcher.class); + private static final Log LOGGER = LogFactory.getLog(HeaderMatcher.class); private final Collection matchers; @@ -613,8 +620,8 @@ public abstract class AbstractHeaderMapper implements RequestReplyHeaderMappe return true; } } - if (logger.isDebugEnabled()) { - logger.debug(MessageFormat.format("headerName=[{0}] WILL NOT be mapped", headerName)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(MessageFormat.format("headerName=[{0}] WILL NOT be mapped", headerName)); } return false; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/selector/MetadataStoreSelector.java b/spring-integration-core/src/main/java/org/springframework/integration/selector/MetadataStoreSelector.java index efcc998fc5..4ec2ac066e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/selector/MetadataStoreSelector.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/selector/MetadataStoreSelector.java @@ -114,7 +114,8 @@ public class MetadataStoreSelector implements MessageSelector { ? this.valueStrategy.processMessage(message) : (timestamp == null ? "0" : Long.toString(timestamp)); - if (this.compareValues == null) { + BiPredicate predicate = this.compareValues; + if (predicate == null) { return this.metadataStore.putIfAbsent(key, value) == null; } else { @@ -123,7 +124,7 @@ public class MetadataStoreSelector implements MessageSelector { if (oldValue == null) { return this.metadataStore.putIfAbsent(key, value) == null; } - if (this.compareValues.test(oldValue, value)) { // NOSONAR (null dereference) + if (predicate.test(oldValue, value)) { return this.metadataStore.replace(key, oldValue, value); } return false; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/AbstractIntegrationMessageBuilder.java b/spring-integration-core/src/main/java/org/springframework/integration/support/AbstractIntegrationMessageBuilder.java index 7bb1b0e72b..557508e90a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/AbstractIntegrationMessageBuilder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/AbstractIntegrationMessageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 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. @@ -46,7 +46,7 @@ public abstract class AbstractIntegrationMessageBuilder { return setHeader(IntegrationMessageHeaderAccessor.EXPIRATION_DATE, expirationDate); } - public AbstractIntegrationMessageBuilder setExpirationDate(Date expirationDate) { + public AbstractIntegrationMessageBuilder setExpirationDate(@Nullable Date expirationDate) { if (expirationDate != null) { return setHeader(IntegrationMessageHeaderAccessor.EXPIRATION_DATE, expirationDate.getTime()); } @@ -62,7 +62,7 @@ public abstract class AbstractIntegrationMessageBuilder { public AbstractIntegrationMessageBuilder pushSequenceDetails(Object correlationId, int sequenceNumber, int sequenceSize) { - Object incomingCorrelationId = this.getCorrelationId(); + Object incomingCorrelationId = getCorrelationId(); List> incomingSequenceDetails = getSequenceDetails(); if (incomingCorrelationId != null) { if (incomingSequenceDetails == null) { @@ -92,8 +92,8 @@ public abstract class AbstractIntegrationMessageBuilder { incomingSequenceDetails = new ArrayList<>(incomingSequenceDetails); } List sequenceDetails = incomingSequenceDetails.remove(incomingSequenceDetails.size() - 1); - Assert.state(sequenceDetails.size() == 3, "Wrong sequence details (not created by MessageBuilder?): " - + sequenceDetails); + Assert.state(sequenceDetails.size() == 3, // NOSONAR + () -> "Wrong sequence details (not created by MessageBuilder?): " + sequenceDetails); setCorrelationId(sequenceDetails.get(0)); Integer sequenceNumber = (Integer) sequenceDetails.get(1); Integer sequenceSize = (Integer) sequenceDetails.get(2); @@ -166,10 +166,13 @@ public abstract class AbstractIntegrationMessageBuilder { @Nullable protected abstract List> getSequenceDetails(); + @Nullable protected abstract Object getCorrelationId(); + @Nullable protected abstract Object getSequenceNumber(); + @Nullable protected abstract Object getSequenceSize(); public abstract T getPayload(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java index baa21d0ff1..6c6fde2e31 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,7 +48,7 @@ import org.springframework.util.ObjectUtils; */ public final class MessageBuilder extends AbstractIntegrationMessageBuilder { - private static final Log logger = LogFactory.getLog(MessageBuilder.class); + private static final Log LOGGER = LogFactory.getLog(MessageBuilder.class); private final T payload; @@ -93,7 +93,6 @@ public final class MessageBuilder extends AbstractIntegrationMessageBuilder The type of the payload. * @return A MessageBuilder. @@ -160,8 +159,8 @@ public final class MessageBuilder extends AbstractIntegrationMessageBuilder implements Message, Serializable { @Override public int hashCode() { - return this.headers.hashCode() * 23 + ObjectUtils.nullSafeHashCode(this.payload); + return this.headers.hashCode() * 23 + ObjectUtils.nullSafeHashCode(this.payload); // NOSONAR } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java b/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java index 3c609c87c8..9dc5d9fa77 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 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. @@ -59,13 +59,13 @@ import org.springframework.util.MultiValueMap; public class SmartLifecycleRoleController implements ApplicationListener, ApplicationContextAware { + private static final Log LOGGER = LogFactory.getLog(SmartLifecycleRoleController.class); + private static final String IN_ROLE = " in role "; - private static final Log logger = LogFactory.getLog(SmartLifecycleRoleController.class); + private final MultiValueMap lifecycles = new LinkedMultiValueMap<>(); - private final MultiValueMap lifecycles = new LinkedMultiValueMap(); - - private final MultiValueMap lazyLifecycles = new LinkedMultiValueMap(); + private final MultiValueMap lazyLifecycles = new LinkedMultiValueMap<>(); private ApplicationContext applicationContext; @@ -87,10 +87,10 @@ public class SmartLifecycleRoleController implements ApplicationListener lifcycles) { - lifcycles.forEach((role, values) -> values.forEach(lifecycle -> addLifecycleToRole(role, lifecycle))); + public SmartLifecycleRoleController(MultiValueMap lifecycles) { + lifecycles.forEach((role, values) -> values.forEach(lifecycle -> addLifecycleToRole(role, lifecycle))); } @Override @@ -163,8 +163,8 @@ public class SmartLifecycleRoleController implements ApplicationListener(componentsInRole); componentsInRole.sort(Comparator.comparingInt(Phased::getPhase)); - if (logger.isDebugEnabled()) { - logger.debug("Starting " + componentsInRole + IN_ROLE + role); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Starting " + componentsInRole + IN_ROLE + role); } componentsInRole.forEach(lifecycle -> { @@ -172,13 +172,13 @@ public class SmartLifecycleRoleController implements ApplicationListener(componentsInRole); componentsInRole.sort((o1, o2) -> Integer.compare(o2.getPhase(), o1.getPhase())); - if (logger.isDebugEnabled()) { - logger.debug("Stopping " + componentsInRole + IN_ROLE + role); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Stopping " + componentsInRole + IN_ROLE + role); } componentsInRole.forEach(lifecycle -> { @@ -204,13 +204,13 @@ public class SmartLifecycleRoleController implements ApplicationListener headersToEncode) { try { byte[] headers = this.objectMapper.writeValueAsBytes(headersToEncode); - ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + headers.length + payload.length]); + ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + headers.length + payload.length]); // NOSONAR buffer.putInt(headers.length); buffer.put(headers); buffer.putInt(payload.length); @@ -247,16 +247,16 @@ public class EmbeddedJsonHeadersMessageMapper implements BytesMessageMapper { @Nullable private Message decodeNativeFormat(byte[] bytes, @Nullable Map headersToAdd) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(bytes); - if (buffer.remaining() > 4) { + if (buffer.remaining() > 4) { // NOSONAR int headersLen = buffer.getInt(); - if (headersLen >= 0 && headersLen < buffer.remaining() - 4) { - buffer.position(headersLen + 4); + if (headersLen >= 0 && headersLen < buffer.remaining() - 4) { // NOSONAR + buffer.position(headersLen + 4); // NOSONAR int payloadLen = buffer.getInt(); if (payloadLen != buffer.remaining()) { return null; } else { - buffer.position(4); + buffer.position(4); // NOSONAR @SuppressWarnings("unchecked") Map headers = this.objectMapper.readValue(bytes, buffer.position(), headersLen, Map.class); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonPresent.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonPresent.java index 47b7cf3f8d..c95464624d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonPresent.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonPresent.java @@ -27,20 +27,24 @@ import org.springframework.util.ClassUtils; */ public final class JacksonPresent { - private static final ClassLoader classLoader = JacksonPresent.class.getClassLoader(); + private static final ClassLoader CLASS_LOADER = ClassUtils.getDefaultClassLoader(); private static final boolean jackson2Present = - ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && - ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader); + ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", CLASS_LOADER) && + ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", CLASS_LOADER); private static final boolean jacksonPresent = - ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", classLoader) && - ClassUtils.isPresent("org.codehaus.jackson.JsonGenerator", classLoader); + ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", CLASS_LOADER) && + ClassUtils.isPresent("org.codehaus.jackson.JsonGenerator", CLASS_LOADER); public static boolean isJackson2Present() { return jackson2Present; } + /** + * @deprecated Jackson 1.x is not supported any more. Use Jackson 2.x. + */ + @Deprecated public static boolean isJacksonPresent() { return jacksonPresent; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java index 118204d0b1..deaa8d9c89 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,6 +18,7 @@ package org.springframework.integration.transformer; import java.util.Collection; +import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.context.Lifecycle; import org.springframework.integration.IntegrationPattern; @@ -29,8 +30,7 @@ import org.springframework.util.Assert; /** * A reply-producing {@link org.springframework.messaging.MessageHandler} - * that delegates to a - * {@link Transformer} instance to modify the received {@link Message} + * that delegates to a {@link Transformer} instance to modify the received {@link Message} * and sends the result to its output channel. * * @author Mark Fisher @@ -42,11 +42,9 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan private final Transformer transformer; - /** * Create a {@link MessageTransformingHandler} instance that delegates to * the provided {@link Transformer}. - * * @param transformer The transformer. */ public MessageTransformingHandler(Transformer transformer) { @@ -58,8 +56,9 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan @Override public String getComponentType() { - return (this.transformer instanceof NamedComponent) ? - ((NamedComponent) this.transformer).getComponentType() : "transformer"; + return (this.transformer instanceof NamedComponent) + ? ((NamedComponent) this.transformer).getComponentType() + : "transformer"; } @Override @@ -77,8 +76,9 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan @Override protected void doInit() { - if (this.getBeanFactory() != null && this.transformer instanceof BeanFactoryAware) { - ((BeanFactoryAware) this.transformer).setBeanFactory(this.getBeanFactory()); + BeanFactory beanFactory = getBeanFactory(); + if (beanFactory != null && this.transformer instanceof BeanFactoryAware) { + ((BeanFactoryAware) this.transformer).setBeanFactory(beanFactory); } populateNotPropagatedHeadersIfAny(); @@ -118,11 +118,10 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan return this.transformer.transform(message); } catch (Exception e) { - if (e instanceof MessageTransformationException) { + if (e instanceof MessageTransformationException) { // NOSONAR throw (MessageTransformationException) e; } - throw new MessageTransformationException(message, - "Failed to transform Message in " + this, e); + throw new MessageTransformationException(message, "Failed to transform Message in " + this, e); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java index c6462849bb..39c0ada359 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java @@ -98,8 +98,8 @@ public class SyslogToMapTransformer extends AbstractPayloadTransformer> 3; + int severity = facility & 0x7; // NOSONAR + facility = facility >> 3; // NOSONAR map.put(FACILITY, facility); map.put(SEVERITY, severity); String timestamp = matcher.group(2); // NOSONAR diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/CallerBlocksPolicy.java b/spring-integration-core/src/main/java/org/springframework/integration/util/CallerBlocksPolicy.java index ef1e4a0173..04ce42adcf 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/CallerBlocksPolicy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/CallerBlocksPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 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. @@ -31,18 +31,20 @@ import org.apache.commons.logging.LogFactory; * case a {@link RejectedExecutionException} is thrown. * * @author Gary Russell + * @author Artem Bilan + * * @since 3.0.3 * */ public class CallerBlocksPolicy implements RejectedExecutionHandler { - private static final Log logger = LogFactory.getLog(CallerBlocksPolicy.class); + private static final Log LOGGER = LogFactory.getLog(CallerBlocksPolicy.class); private final long maxWait; /** - * @param maxWait The maximum time to wait for a queue slot to be - * available, in milliseconds. + * Construct instance based on the provided maximum wait time. + * @param maxWait The maximum time to wait for a queue slot to be available, in milliseconds. */ public CallerBlocksPolicy(long maxWait) { this.maxWait = maxWait; @@ -53,15 +55,13 @@ public class CallerBlocksPolicy implements RejectedExecutionHandler { if (!executor.isShutdown()) { try { BlockingQueue queue = executor.getQueue(); - if (logger.isDebugEnabled()) { - logger.debug("Attempting to queue task execution for " + this.maxWait + " milliseconds"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Attempting to queue task execution for " + this.maxWait + " milliseconds"); } if (!queue.offer(r, this.maxWait, TimeUnit.MILLISECONDS)) { throw new RejectedExecutionException("Max wait time expired to queue task"); } - if (logger.isDebugEnabled()) { - logger.debug("Task execution queued"); - } + LOGGER.debug("Task execution queued"); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/DynamicPeriodicTrigger.java b/spring-integration-core/src/main/java/org/springframework/integration/util/DynamicPeriodicTrigger.java index 39a93fb263..95ce697104 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/DynamicPeriodicTrigger.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/DynamicPeriodicTrigger.java @@ -145,7 +145,7 @@ public class DynamicPeriodicTrigger implements Trigger { final int prime = 31; int result = 1; result = prime * result + ((this.duration == null) ? 0 : this.duration.hashCode()); - result = prime * result + (this.fixedRate ? 1231 : 1237); + result = prime * result + (this.fixedRate ? 1231 : 1237); // NOSONAR result = prime * result + ((this.initialDuration == null) ? 0 : this.initialDuration.hashCode()); return result; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java b/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java index 010038cf94..d38965721b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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 java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,6 +38,8 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Sergey Bogatyrev + * @author Artem Bilan + * * @since 2.2 * */ @@ -91,7 +94,8 @@ public class SimplePool implements Pool { int delta = poolSize - this.poolSize.get(); this.targetPoolSize.addAndGet(delta); if (this.logger.isDebugEnabled()) { - this.logger.debug(String.format("Target pool size changed by %d, now %d", delta, this.targetPoolSize.get())); + this.logger.debug(String.format("Target pool size changed by %d, now %d", delta, + this.targetPoolSize.get())); } if (delta > 0) { this.poolSize.addAndGet(delta); @@ -111,7 +115,8 @@ public class SimplePool implements Pool { } } if (delta < 0 && this.logger.isDebugEnabled()) { - this.logger.debug(String.format("Pool is overcommitted by %d; items will be removed when returned", -delta)); + this.logger.debug(String.format("Pool is overcommitted by %d; items will be removed when returned", + -delta)); } } @@ -175,7 +180,7 @@ public class SimplePool implements Pool { if (permitted) { this.permits.release(); } - if (e instanceof PoolItemNotAvailableException) { + if (e instanceof PoolItemNotAvailableException) { // NOSONAR throw (PoolItemNotAvailableException) e; } throw new PoolItemNotAvailableException("Failed to obtain pooled item", e); @@ -216,18 +221,14 @@ public class SimplePool implements Pool { if (this.inUse.contains(item)) { if (this.poolSize.get() > this.targetPoolSize.get()) { this.poolSize.decrementAndGet(); - if (item != null) { - doRemoveItem(item); - } + doRemoveItem(item); } else { if (this.logger.isDebugEnabled()) { this.logger.debug("Releasing " + item + " back to the pool"); } - if (item != null) { - this.available.add(item); - this.inUse.remove(item); - } + this.available.add(item); + this.inUse.remove(item); this.permits.release(); } } @@ -286,5 +287,7 @@ public class SimplePool implements Pool { * @param item The item. */ void removedFromPool(T item); + } + }