From 0bb901b286bd6c8038a79dad3e6421f7f025fb78 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 30 Apr 2019 13:57:13 -0400 Subject: [PATCH] Sonar fixes - printStackTrace in test mail server - Illegal throws - Large anon. classes * - indexOf char - stored external object * - ignored exceptional return values * - checkstyle --- .../aggregator/MessageGroupExpiredEvent.java | 4 +- .../config/MessagingGatewayRegistrar.java | 2 +- .../config/xml/AnnotationConfigParser.java | 67 ++++++++------- .../endpoint/ReactiveStreamsConsumer.java | 69 ++++++++-------- .../gateway/GatewayProxyFactoryBean.java | 6 +- .../advice/AbstractHandleMessageAdvice.java | 6 +- .../advice/AbstractRequestHandlerAdvice.java | 81 ++++++++++--------- .../PropertiesPersistingMetadataStore.java | 8 +- .../support/locks/PassThruLockRegistry.java | 77 +++++++++++------- .../AbstractRemoteFileOutboundGateway.java | 14 ++-- ...InboundFileSynchronizingMessageSource.java | 4 +- .../CachingClientConnectionFactory.java | 40 ++++----- .../RedisChannelPriorityMessageStore.java | 4 +- .../outbound/RSocketOutboundGateway.java | 6 -- .../channel/ChannelSecurityInterceptor.java | 5 +- .../inbound/StompInboundChannelAdapter.java | 61 +++++++------- .../stomp/support/StompHeaderMapper.java | 14 ++-- .../integration/test/mail/TestMailServer.java | 23 ++++-- .../test/rule/Log4j2LevelAdjuster.java | 24 +++--- 19 files changed, 280 insertions(+), 235 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java index f3bce8d997..8d6d6353aa 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java @@ -47,8 +47,8 @@ public class MessageGroupExpiredEvent extends IntegrationEvent { super(source); this.groupId = groupId; this.messageCount = messageCount; - this.lastModified = lastModified; - this.expired = expired; + this.lastModified = (Date) lastModified.clone(); + this.expired = (Date) expired.clone(); this.discarded = discarded; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingGatewayRegistrar.java b/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingGatewayRegistrar.java index ce4388938e..1c1add9dab 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingGatewayRegistrar.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingGatewayRegistrar.java @@ -163,7 +163,7 @@ public class MessagingGatewayRegistrar implements ImportBeanDefinitionRegistrar } String id = (String) gatewayAttributes.get("name"); if (!StringUtils.hasText(id)) { - id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf(".") + 1)); + id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf('.') + 1)); } gatewayProxyBuilder.addConstructorArgValue(serviceInterface); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java index fb37199573..465d76a016 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java @@ -35,42 +35,49 @@ import org.springframework.util.xml.DomUtils; * * @author Mark Fisher * @author Artem Bilan + * @author Gary Russell */ public class AnnotationConfigParser implements BeanDefinitionParser { @Override public BeanDefinition parse(final Element element, ParserContext parserContext) { - StandardAnnotationMetadata importingClassMetadata = - new StandardAnnotationMetadata(Object.class) { - - @Override - public Map getAnnotationAttributes(String annotationType) { - if (EnablePublisher.class.getName().equals(annotationType)) { - Element enablePublisherElement = - DomUtils.getChildElementByTagName(element, "enable-publisher"); - if (enablePublisherElement != null) { - Map attributes = new HashMap<>(); - attributes.put("defaultChannel", - enablePublisherElement.getAttribute("default-publisher-channel")); - attributes.put("proxyTargetClass", - enablePublisherElement.getAttribute("proxy-target-class")); - attributes.put("order", enablePublisherElement.getAttribute("order")); - return attributes; - } - else { - return null; - } - } - else { - return null; - } - } - - }; - - new IntegrationRegistrar().registerBeanDefinitions(importingClassMetadata, parserContext.getRegistry()); - + new IntegrationRegistrar().registerBeanDefinitions(new ExtendedAnnotationMetadata(Object.class, element), + parserContext.getRegistry()); return null; } + private static final class ExtendedAnnotationMetadata extends StandardAnnotationMetadata { + + private final Element element; + + ExtendedAnnotationMetadata(Class introspectedClass, Element element) { + super(introspectedClass); + this.element = element; + } + + @Override + public Map getAnnotationAttributes(String annotationType) { + if (EnablePublisher.class.getName().equals(annotationType)) { + Element enablePublisherElement = + DomUtils.getChildElementByTagName(this.element, "enable-publisher"); + if (enablePublisherElement != null) { + Map attributes = new HashMap<>(); + attributes.put("defaultChannel", + enablePublisherElement.getAttribute("default-publisher-channel")); + attributes.put("proxyTargetClass", + enablePublisherElement.getAttribute("proxy-target-class")); + attributes.put("order", enablePublisherElement.getAttribute("order")); + return attributes; + } + else { + return null; + } + } + else { + return null; + } + } + + } + } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/ReactiveStreamsConsumer.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/ReactiveStreamsConsumer.java index 9d76cfc278..1df8807c43 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/ReactiveStreamsConsumer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/ReactiveStreamsConsumer.java @@ -132,38 +132,7 @@ public class ReactiveStreamsConsumer extends AbstractEndpoint implements Integra if (this.lifecycleDelegate != null) { this.lifecycleDelegate.start(); } - this.publisher.subscribe(new BaseSubscriber>() { - - private final Subscriber> delegate = ReactiveStreamsConsumer.this.subscriber; - - @Override - public void hookOnSubscribe(Subscription s) { - this.delegate.onSubscribe(s); - ReactiveStreamsConsumer.this.subscription = s; - } - - @Override - public void hookOnNext(Message message) { - try { - this.delegate.onNext(message); - } - catch (Exception e) { - ReactiveStreamsConsumer.this.errorHandler.handleError(e); - hookOnError(e); - } - } - - @Override - public void hookOnError(Throwable t) { - this.delegate.onError(t); - } - - @Override - public void hookOnComplete() { - this.delegate.onComplete(); - } - - }); + this.publisher.subscribe(new DelegatingSubscriber()); } @Override @@ -176,6 +145,42 @@ public class ReactiveStreamsConsumer extends AbstractEndpoint implements Integra } } + private final class DelegatingSubscriber extends BaseSubscriber> { + + private final Subscriber> delegate = ReactiveStreamsConsumer.this.subscriber; + + DelegatingSubscriber() { + super(); + } + + @Override + public void hookOnSubscribe(Subscription s) { + this.delegate.onSubscribe(s); + ReactiveStreamsConsumer.this.subscription = s; + } + + @Override + public void hookOnNext(Message message) { + try { + this.delegate.onNext(message); + } + catch (Exception e) { + ReactiveStreamsConsumer.this.errorHandler.handleError(e); + hookOnError(e); + } + } + + @Override + public void hookOnError(Throwable t) { + this.delegate.onError(t); + } + + @Override + public void hookOnComplete() { + this.delegate.onComplete(); + } + + } private static final class MessageHandlerSubscriber implements CoreSubscriber>, Disposable, Lifecycle { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index b4c38b9dc1..4a57fe7867 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -465,7 +465,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint } @Nullable - protected Object doInvoke(MethodInvocation invocation, boolean runningOnCallerThread) throws Throwable { + protected Object doInvoke(MethodInvocation invocation, boolean runningOnCallerThread) throws Throwable { // NOSONAR Method method = invocation.getMethod(); if (AopUtils.isToStringMethod(method)) { return "gateway proxy for service interface [" + this.serviceInterface + "]"; @@ -474,7 +474,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint return invokeGatewayMethod(invocation, runningOnCallerThread); } catch (Throwable e) { //NOSONAR - ok to catch, rethrown below - this.rethrowExceptionCauseIfPossible(e, invocation.getMethod()); + rethrowExceptionCauseIfPossible(e, invocation.getMethod()); return null; // preceding call should always throw something } } @@ -538,7 +538,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint return (response != null) ? this.convert(response, returnType) : null; } - private void rethrowExceptionCauseIfPossible(Throwable originalException, Method method) throws Throwable { + private void rethrowExceptionCauseIfPossible(Throwable originalException, Method method) throws Throwable { // NOSONAR Class[] exceptionTypes = method.getExceptionTypes(); Throwable t = originalException; while (t != null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractHandleMessageAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractHandleMessageAdvice.java index 87d0116fdf..a5d25e8bf0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractHandleMessageAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractHandleMessageAdvice.java @@ -19,8 +19,6 @@ package org.springframework.integration.handler.advice; import java.lang.reflect.Method; import org.aopalliance.intercept.MethodInvocation; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.messaging.Message; @@ -37,10 +35,8 @@ import org.springframework.messaging.MessageHandler; */ public abstract class AbstractHandleMessageAdvice extends IntegrationObjectSupport implements HandleMessageAdvice { - protected final Log logger = LogFactory.getLog(this.getClass()); - @Override - public final Object invoke(MethodInvocation invocation) throws Throwable { + public final Object invoke(MethodInvocation invocation) throws Throwable { // NOSONAR Method method = invocation.getMethod(); Object invocationThis = invocation.getThis(); Object[] arguments = invocation.getArguments(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java index e3fa1f2907..15e7dddd37 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java @@ -64,42 +64,7 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp else { Message message = (Message) arguments[0]; try { - return doInvoke(new ExecutionCallback() { - - @Override - public Object execute() { - try { - return invocation.proceed(); - } - catch (Throwable e) { //NOSONAR - ok to catch; unwrapped and rethrown below - throw new ThrowableHolderException(e); - } - } - - @Override - public Object cloneAndExecute() { - try { - /* - * If we don't copy the invocation carefully it won't keep a reference to the other - * interceptors in the chain. - */ - if (invocation instanceof ProxyMethodInvocation) { - return ((ProxyMethodInvocation) invocation).invocableClone().proceed(); - } - else { - throw new IllegalStateException( - "MethodInvocation of the wrong type detected - this should not happen with Spring AOP," + - " so please raise an issue if you see this exception"); - } - } - catch (Exception e) { //NOSONAR - catch necessary so we can wrap Errors - throw new MessagingException(message, "Failed to handle", e); - } - catch (Throwable e) { //NOSONAR - ok to catch; unwrapped and rethrown below - throw new ThrowableHolderException(e); - } - } - }, invocationThis, message); + return doInvoke(new CallbackImpl(invocation), invocationThis, message); } catch (Exception e) { throw this.unwrapThrowableIfNecessary(e); @@ -172,6 +137,50 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp } + private static final class CallbackImpl implements ExecutionCallback { + + private final MethodInvocation invocation; + + CallbackImpl(MethodInvocation invocation) { + this.invocation = invocation; + } + + @Override + public Object execute() { + try { + return this.invocation.proceed(); + } + catch (Throwable e) { //NOSONAR - ok to catch; unwrapped and rethrown below + throw new ThrowableHolderException(e); + } + } + + @Override + public Object cloneAndExecute() { + try { + /* + * If we don't copy the invocation carefully it won't keep a reference to the other + * interceptors in the chain. + */ + if (this.invocation instanceof ProxyMethodInvocation) { + return ((ProxyMethodInvocation) this.invocation).invocableClone().proceed(); + } + else { + throw new IllegalStateException( + "MethodInvocation of the wrong type detected - this should not happen with Spring AOP," + + " so please raise an issue if you see this exception"); + } + } + catch (Exception e) { //NOSONAR - catch necessary so we can wrap Errors + throw new MessagingException((Message) this.invocation.getArguments()[0], "Failed to handle", e); + } + catch (Throwable e) { //NOSONAR - ok to catch; unwrapped and rethrown below + throw new ThrowableHolderException(e); + } + } + + } + @SuppressWarnings("serial") protected static final class ThrowableHolderException extends RuntimeException { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java b/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java index fc9310b656..5776c0646b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java @@ -93,11 +93,13 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor @Override public void afterPropertiesSet() { File baseDir = new File(this.baseDirectory); - baseDir.mkdirs(); + if (!baseDir.mkdirs() && this.logger.isWarnEnabled()) { + this.logger.warn("Failed to create directories for " + baseDir); + } this.file = new File(baseDir, this.fileName); try { - if (!this.file.exists()) { - this.file.createNewFile(); + if (!this.file.exists() && !this.file.createNewFile() && this.logger.isWarnEnabled()) { + this.logger.warn("Failed to create file " + this.file); } } catch (Exception e) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/locks/PassThruLockRegistry.java b/spring-integration-core/src/main/java/org/springframework/integration/support/locks/PassThruLockRegistry.java index 390577d732..8ea96aef93 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/locks/PassThruLockRegistry.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/locks/PassThruLockRegistry.java @@ -21,44 +21,59 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; /** - * The {@link LockRegistry} implementation which has no effect. Mainly used in cases where locking itself must be conditional - * but an extra IF statement would clutter the code. - * For example. In the FILE module FileWritingMessageHandler is initialized with this instance of LockRegistry by default - * since real locking is only required if its 'append' flag is set to true. + * The {@link LockRegistry} implementation which has no effect. Mainly used in cases where + * locking itself must be conditional but an extra IF statement would clutter the code. + * For example. In the FILE module FileWritingMessageHandler is initialized with this + * instance of LockRegistry by default since real locking is only required if its 'append' + * flag is set to true. * * @author Oleg Zhurakousky + * @author Gary Russell * @since 2.2 * */ public final class PassThruLockRegistry implements LockRegistry { + @Override public Lock obtain(Object lockKey) { - return new Lock() { - - public void unlock() { - // noop - } - - public boolean tryLock(long time, TimeUnit unit) - throws InterruptedException { - return true; - } - - public boolean tryLock() { - return true; - } - - public Condition newCondition() { - throw new UnsupportedOperationException("This method is not supported for this implementation of Lock"); - } - - public void lockInterruptibly() throws InterruptedException { - // noop - } - - public void lock() { - // noop - } - }; + return new PassThruLock(); } + + private static final class PassThruLock implements Lock { + + PassThruLock() { + super(); + } + + @Override + public void unlock() { + // noop + } + + @Override + public boolean tryLock(long time, TimeUnit unit) { + return true; + } + + @Override + public boolean tryLock() { + return true; + } + + @Override + public Condition newCondition() { + throw new UnsupportedOperationException("This method is not supported for this implementation of Lock"); + } + + @Override + public void lockInterruptibly() { + // noop + } + + @Override + public void lock() { + // noop + } + } + } 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 9465bd2f3c..c9024ff767 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 @@ -685,10 +685,10 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply * nothing. * @param remoteFileOperations the remote file template. * @param path the path. - * @param chmod the chmod to set. + * @param chmodToSet the chmod to set. * @since 4.3 */ - protected void doChmod(RemoteFileOperations remoteFileOperations, String path, int chmod) { + protected void doChmod(RemoteFileOperations remoteFileOperations, String path, int chmodToSet) { // no-op } @@ -921,7 +921,9 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply outputStream = new BufferedOutputStream(new FileOutputStream(tempFile)); } if (replacing) { - localFile.delete(); + if (!localFile.delete() && this.logger.isWarnEnabled()) { + this.logger.warn("Failed to delete " + localFile); + } } try { session.read(remoteFilePath, outputStream); @@ -944,7 +946,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply try { outputStream.close(); } - catch (Exception ignored2) { + catch (@SuppressWarnings("unused") Exception ignored2) { //Ignore it } } @@ -953,7 +955,9 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply } if (this.options.contains(Option.PRESERVE_TIMESTAMP) || FileExistsMode.REPLACE_IF_MODIFIED.equals(existsMode)) { - localFile.setLastModified(getModified(fileInfo)); + if (!localFile.setLastModified(getModified(fileInfo)) && this.logger.isWarnEnabled()) { + logger.warn("Failed to set lastModified on " + localFile); + } } if (this.options.contains(Option.DELETE)) { boolean result = session.remove(remoteFilePath); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java index 1787b40f5e..ce0b40f758 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java @@ -181,7 +181,9 @@ public abstract class AbstractInboundFileSynchronizingMessageSource if (logger.isDebugEnabled()) { logger.debug("The '" + this.localDirectory + "' directory doesn't exist; Will create."); } - this.localDirectory.mkdirs(); + if (!this.localDirectory.mkdirs() && this.logger.isWarnEnabled()) { + this.logger.warn("Failed to create directories for " + this.localDirectory); + } } else { throw new FileNotFoundException(this.localDirectory.getName()); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactory.java index cb7d98cc7b..71fa96e10d 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactory.java @@ -58,30 +58,30 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact // override single-use to true so the target creates multiple connections target.setSingleUse(true); this.targetConnectionFactory = target; - this.pool = new SimplePool(poolSize, - new SimplePool.PoolItemCallback() { + class Callback implements SimplePool.PoolItemCallback { - @Override - public TcpConnectionSupport createForPool() { - try { - return CachingClientConnectionFactory.this.targetConnectionFactory.getConnection(); - } - catch (Exception e) { - throw new MessagingException("Failed to obtain connection", e); - } - } + @Override + public TcpConnectionSupport createForPool() { + try { + return CachingClientConnectionFactory.this.targetConnectionFactory.getConnection(); + } + catch (Exception e) { + throw new MessagingException("Failed to obtain connection", e); + } + } - @Override - public boolean isStale(TcpConnectionSupport connection) { - return !connection.isOpen(); - } + @Override + public boolean isStale(TcpConnectionSupport connection) { + return !connection.isOpen(); + } - @Override - public void removedFromPool(TcpConnectionSupport connection) { - connection.close(); - } + @Override + public void removedFromPool(TcpConnectionSupport connection) { + connection.close(); + } - }); + } + this.pool = new SimplePool(poolSize, new Callback()); } /** diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelPriorityMessageStore.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelPriorityMessageStore.java index 21b1b3fdcc..965bdfd826 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelPriorityMessageStore.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelPriorityMessageStore.java @@ -141,8 +141,8 @@ public class RedisChannelPriorityMessageStore extends RedisChannelMessageStore for (Object key : keys) { Assert.isInstanceOf(String.class, key); String keyString = (String) key; - int lastIndexOfColon = keyString.lastIndexOf(":"); - if (keyString.indexOf(":") != lastIndexOfColon) { + int lastIndexOfColon = keyString.lastIndexOf(':'); + if (keyString.indexOf(':') != lastIndexOfColon) { narrowedKeys.add(keyString.substring(0, lastIndexOfColon)); } else { diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGateway.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGateway.java index cc5737ff63..f31cff994c 100644 --- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGateway.java +++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGateway.java @@ -185,12 +185,6 @@ public class RSocketOutboundGateway extends AbstractReplyProducingMessageHandler } } - @Override - public void destroy() { - super.destroy(); - - } - @Override protected Object handleRequestMessage(Message requestMessage) { RSocketRequester rsocketRequester = requestMessage.getHeaders() diff --git a/spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelSecurityInterceptor.java b/spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelSecurityInterceptor.java index bb0c959018..329d8636f3 100644 --- a/spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelSecurityInterceptor.java +++ b/spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelSecurityInterceptor.java @@ -53,7 +53,8 @@ public final class ChannelSecurityInterceptor extends AbstractSecurityIntercepto } - public Object invoke(MethodInvocation invocation) throws Throwable { + @Override + public Object invoke(MethodInvocation invocation) throws Throwable { // NOSONAR Method method = invocation.getMethod(); if (method.getName().equals("send") || method.getName().equals("receive")) { return this.invokeWithAuthorizationCheck(invocation); @@ -61,7 +62,7 @@ public final class ChannelSecurityInterceptor extends AbstractSecurityIntercepto return invocation.proceed(); } - private Object invokeWithAuthorizationCheck(MethodInvocation methodInvocation) throws Throwable { + private Object invokeWithAuthorizationCheck(MethodInvocation methodInvocation) throws Throwable { // NOSONAR Object returnValue = null; InterceptorStatusToken token = super.beforeInvocation(new ChannelInvocation(methodInvocation)); try { diff --git a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapter.java b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapter.java index 305040589b..b40ed4fb7e 100644 --- a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapter.java +++ b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapter.java @@ -208,37 +208,38 @@ public class StompInboundChannelAdapter extends MessageProducerSupport implement private void subscribeDestination(final String destination) { if (this.stompSession != null) { + class FrameHandler implements StompFrameHandler { + + @Override + public Type getPayloadType(StompHeaders headers) { + return StompInboundChannelAdapter.this.payloadType; + } + + @Override + public void handleFrame(StompHeaders headers, @Nullable Object body) { + Message message; + + if (body == null) { + logger.info("No body in STOMP frame: nothing to produce."); + return; + } + else if (body instanceof Message) { + message = (Message) body; + } + else { + message = + getMessageBuilderFactory() + .withPayload(body) + .copyHeaders( + StompInboundChannelAdapter.this.headerMapper.toHeaders(headers)) + .build(); + } + sendMessage(message); + } + + } final StompSession.Subscription subscription = - this.stompSession.subscribe(destination, new StompFrameHandler() { - - @Override - public Type getPayloadType(StompHeaders headers) { - return StompInboundChannelAdapter.this.payloadType; - } - - @Override - public void handleFrame(StompHeaders headers, @Nullable Object body) { - Message message; - - if (body == null) { - logger.info("No body in STOMP frame: nothing to produce."); - return; - } - else if (body instanceof Message) { - message = (Message) body; - } - else { - message = - getMessageBuilderFactory() - .withPayload(body) - .copyHeaders( - StompInboundChannelAdapter.this.headerMapper.toHeaders(headers)) - .build(); - } - sendMessage(message); - } - - }); + this.stompSession.subscribe(destination, new FrameHandler()); if (this.stompSessionManager.isAutoReceiptEnabled()) { final ApplicationEventPublisher eventPublisher = this.applicationEventPublisher; diff --git a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/support/StompHeaderMapper.java b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/support/StompHeaderMapper.java index 9813ccbf7c..b19a749890 100644 --- a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/support/StompHeaderMapper.java +++ b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/support/StompHeaderMapper.java @@ -80,21 +80,23 @@ public class StompHeaderMapper implements HeaderMapper { private String[] outboundHeaderNames = STOMP_OUTBOUND_HEADER_NAMES; - public void setInboundHeaderNames(String[] inboundHeaderNames) { //NOSONAR - false positive + public void setInboundHeaderNames(String[] inboundHeaderNames) { Assert.notNull(inboundHeaderNames, "'inboundHeaderNames' must not be null."); Assert.noNullElements(inboundHeaderNames, "'inboundHeaderNames' must not contains null elements."); - Arrays.sort(inboundHeaderNames); + String[] copy = Arrays.copyOf(inboundHeaderNames, inboundHeaderNames.length); + Arrays.sort(copy); if (!Arrays.equals(STOMP_INBOUND_HEADER_NAMES, inboundHeaderNames)) { - this.inboundHeaderNames = inboundHeaderNames; + this.inboundHeaderNames = copy; } } - public void setOutboundHeaderNames(String[] outboundHeaderNames) { //NOSONAR - false positive + public void setOutboundHeaderNames(String[] outboundHeaderNames) { Assert.notNull(outboundHeaderNames, "'outboundHeaderNames' must not be null."); Assert.noNullElements(outboundHeaderNames, "'outboundHeaderNames' must not contains null elements."); - Arrays.sort(outboundHeaderNames); + String[] copy = Arrays.copyOf(outboundHeaderNames, outboundHeaderNames.length); + Arrays.sort(copy); if (!Arrays.equals(STOMP_OUTBOUND_HEADER_NAMES, outboundHeaderNames)) { - this.outboundHeaderNames = outboundHeaderNames; + this.outboundHeaderNames = copy; } } diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java index 1e05508cf4..bb09db171d 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java @@ -32,6 +32,9 @@ import java.util.concurrent.Executors; import javax.net.ServerSocketFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.util.Base64Utils; /** @@ -145,7 +148,7 @@ public final class TestMailServer { messages.add(sb.toString()); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error(IO_EXCEPTION, e); } } @@ -205,7 +208,7 @@ public final class TestMailServer { } } catch (IOException e) { - e.printStackTrace(); + LOGGER.error(IO_EXCEPTION, e); } } @@ -256,7 +259,7 @@ public final class TestMailServer { if (line == null) { break; } - String tag = line.substring(0, line.indexOf(" ") + 1); + String tag = line.substring(0, line.indexOf(' ') + 1); if (line.endsWith("CAPABILITY")) { write("* CAPABILITY IDLE IMAP4rev1"); write(tag + "OK CAPABILITY completed"); @@ -357,7 +360,7 @@ public final class TestMailServer { write("* 2 EXISTS"); seen = false; } - catch (InterruptedException e) { + catch (@SuppressWarnings("unused") InterruptedException e) { Thread.currentThread().interrupt(); } } @@ -373,7 +376,7 @@ public final class TestMailServer { } } catch (IOException e) { - e.printStackTrace(); + LOGGER.error(IO_EXCEPTION, e); } } @@ -393,6 +396,10 @@ public final class TestMailServer { public abstract static class MailServer implements Runnable { + protected final Log LOGGER = LogFactory.getLog(getClass()); // NOSONAR + + protected static final String IO_EXCEPTION = "IOException"; // NOSONAR + private final ServerSocket serverSocket; private final ExecutorService exec = Executors.newCachedThreadPool(); @@ -437,7 +444,7 @@ public final class TestMailServer { exec.execute(mailHandler(socket)); } } - catch (IOException e) { + catch (@SuppressWarnings("unused") IOException e) { this.listening = false; } } @@ -449,7 +456,7 @@ public final class TestMailServer { this.serverSocket.close(); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error(IO_EXCEPTION, e); } this.exec.shutdownNow(); } @@ -485,7 +492,7 @@ public final class TestMailServer { this.writer = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream())); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error(IO_EXCEPTION, e); } doRun(); } diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java index 991648cf9d..92a9614570 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java @@ -77,7 +77,7 @@ public final class Log4j2LevelAdjuster implements MethodRule { @Override public Statement apply(final Statement base, final FrameworkMethod method, Object target) { - return new Statement() { + class AdjustingStatement extends Statement { @Override public void evaluate() throws Throwable { @@ -152,19 +152,19 @@ public final class Log4j2LevelAdjuster implements MethodRule { ctx.updateLoggers(); } } - - }; + } + return new AdjustingStatement(); } /** * Specify the classes for logging level adjusting configured before. * A new copy Log4j2LevelAdjuster instance is produced by this method. * The provided classes parameter overrides existing value in the {@link #classes}. - * @param classes the classes to use for logging level adjusting + * @param clazzes the classes to use for logging level adjusting * @return a Log4j2LevelAdjuster copy with the provided classes */ - public Log4j2LevelAdjuster classes(Class... classes) { - return classes(false, classes); + public Log4j2LevelAdjuster classes(Class... clazzes) { + return classes(false, clazzes); } /** @@ -172,13 +172,13 @@ public final class Log4j2LevelAdjuster implements MethodRule { * A new copy Log4j2LevelAdjuster instance is produced by this method. * The provided classes parameter can be merged with existing value in the {@link #classes}. * @param merge to merge or not with previously configured {@link #classes} - * @param classes the classes to use for logging level adjusting + * @param classesToAdjust the classes to use for logging level adjusting * @return a Log4j2LevelAdjuster copy with the provided classes * @since 5.0.2 */ - public Log4j2LevelAdjuster classes(boolean merge, Class... classes) { + public Log4j2LevelAdjuster classes(boolean merge, Class... classesToAdjust) { return new Log4j2LevelAdjuster(this.level, - merge ? Stream.of(this.classes, classes).flatMap(Stream::of).toArray(Class[]::new) : classes, + merge ? Stream.of(this.classes, classesToAdjust).flatMap(Stream::of).toArray(Class[]::new) : classesToAdjust, this.categories); } @@ -186,11 +186,11 @@ public final class Log4j2LevelAdjuster implements MethodRule { * Specify the categories for logging level adjusting configured before. * A new copy Log4j2LevelAdjuster instance is produced by this method. * The provided categories parameter overrides existing value in the {@link #categories}. - * @param categories the categories to use for logging level adjusting + * @param categoriesToAdjust the categories to use for logging level adjusting * @return a Log4j2LevelAdjuster copy with the provided categories */ - public Log4j2LevelAdjuster categories(String... categories) { - return categories(false, categories); + public Log4j2LevelAdjuster categories(String... categoriesToAdjust) { + return categories(false, categoriesToAdjust); } /**