From 5be0ed17eb594b26dbd474b426e106b0980afe5c Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 21 Jul 2020 10:45:45 -0400 Subject: [PATCH] Fix some Sonar smells --- .../AbstractCorrelatingMessageHandler.java | 1 - .../dispatcher/AbstractDispatcher.java | 10 +++--- .../dispatcher/BroadcastingDispatcher.java | 24 ++++++-------- ...vyIntegrationConfigurationInitializer.java | 6 ++-- ...raphControllerRegistrarImportSelector.java | 6 ++-- .../FileCopyingMultipartFileReader.java | 19 ++++++----- .../UdpOutboundChannelAdapterParser.java | 32 ++++++++++--------- 7 files changed, 47 insertions(+), 51 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java index eea9ceaf76..8217b1f721 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java @@ -141,7 +141,6 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP private long expireTimeout; - @Nullable private Duration expireDuration; private MessageGroupProcessor forceReleaseProcessor = new ForceReleaseMessageGroupProcessor(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java index e656d6088b..a44984d88c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.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. @@ -40,15 +40,15 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Gary Russell * @author Diego Belfer + * @author Artem Bilan */ public abstract class AbstractDispatcher implements MessageDispatcher { protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR final - private volatile int maxSubscribers = Integer.MAX_VALUE; + private final OrderedAwareCopyOnWriteArraySet handlers = new OrderedAwareCopyOnWriteArraySet<>(); - private final OrderedAwareCopyOnWriteArraySet handlers = - new OrderedAwareCopyOnWriteArraySet(); + private volatile int maxSubscribers = Integer.MAX_VALUE; private volatile MessageHandler theOneHandler; @@ -125,7 +125,7 @@ public abstract class AbstractDispatcher implements MessageDispatcher { @Override public String toString() { - return this.getClass().getSimpleName() + " with handlers: " + this.handlers.toString(); + return getClass().getSimpleName() + " with handlers: " + this.handlers.toString(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java index 95b3439f8e..ec843b2444 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java @@ -35,16 +35,16 @@ import org.springframework.messaging.support.MessageHandlingRunnable; import org.springframework.util.Assert; /** - * A broadcasting dispatcher implementation. If the 'ignoreFailures' property is set to false (the + * A broadcasting dispatcher implementation. If the 'ignoreFailures' property is set to false (the * default), it will fail fast such that any Exception thrown by a MessageHandler may prevent subsequent handlers from * receiving the Message. However, when an Executor is provided, the Messages may be dispatched in separate Threads so - * that other handlers are invoked even when the 'ignoreFailures' flag is false. + * that other handlers are invoked even when the 'ignoreFailures' flag is false. *

- * If the 'ignoreFailures' flag is set to true on the other hand, it will make a best effort to send the - * message to each of its handlers. In other words, when 'ignoreFailures' is true, if it fails to send to + * If the 'ignoreFailures' flag is set to true on the other hand, it will make a best effort to send the + * message to each of its handlers. In other words, when 'ignoreFailures' is true, if it fails to send to * any one handler, it will simply log a warn-level message but continue to send the Message to any other handlers. *

- * If the 'requireSubscribers' flag is set to true, the sent message is considered as non-dispatched + * If the 'requireSubscribers' flag is set to true, the sent message is considered as non-dispatched * and rejected to the caller with the {@code "Dispatcher has no subscribers"} {@link MessageDispatchingException}. * * @author Mark Fisher @@ -92,15 +92,14 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa } /** - * Specify whether failures for one or more of the handlers should be ignored. By default this is false + * Specify whether failures for one or more of the handlers should be ignored. By default this is false * meaning that an Exception will be thrown when a handler fails. To override this and suppress Exceptions, set the - * value to true. + * value to true. *

* Keep in mind that when using an Executor, even without ignoring the failures, other handlers may be invoked after * one throws an Exception. Since the Executor is most likely using a different thread, this flag would only affect * whether an error Message is sent to the error channel or not in the case that such an Executor has been * configured. - * * @param ignoreFailures true when failures are to be ignored. */ public void setIgnoreFailures(boolean ignoreFailures) { @@ -108,9 +107,8 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa } /** - * Specify whether to apply sequence numbers to the messages prior to sending to the handlers. By default, sequence - * numbers will not be applied. - * + * Specify whether to apply sequence numbers to the messages prior to sending to the handlers. + * By default, sequence numbers will not be applied. * @param applySequence true when sequence information should be applied. */ public void setApplySequence(boolean applySequence) { @@ -226,9 +224,7 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa } catch (RuntimeException e) { if (!this.ignoreFailures) { - if (e instanceof MessagingException - && ((MessagingException) e).getFailedMessage() == null) { // NOSONAR - + if (e instanceof MessagingException && ((MessagingException) e).getFailedMessage() == null) { // NOSONAR throw new MessagingException(message, "Failed to handle Message", e); } throw e; diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyIntegrationConfigurationInitializer.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyIntegrationConfigurationInitializer.java index 6fc968da38..7d4df94c6b 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyIntegrationConfigurationInitializer.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyIntegrationConfigurationInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-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. @@ -35,7 +35,7 @@ import org.springframework.integration.scripting.config.ScriptExecutingProcessor */ public class GroovyIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer { - private static final Log logger = LogFactory.getLog(GroovyIntegrationConfigurationInitializer.class); + private static final Log LOGGER = LogFactory.getLog(GroovyIntegrationConfigurationInitializer.class); @Override public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { @@ -43,7 +43,7 @@ public class GroovyIntegrationConfigurationInitializer implements IntegrationCon registerScriptExecutorProviderIfNecessary((BeanDefinitionRegistry) beanFactory); } else { - logger.warn("The 'ScriptExecutingProcessorFactory' isn't registered because 'beanFactory'" + + LOGGER.warn("The 'ScriptExecutingProcessorFactory' isn't registered because 'beanFactory'" + " isn't an instance of `BeanDefinitionRegistry`."); } } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrarImportSelector.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrarImportSelector.java index 89b20fbcc9..2d7267256c 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrarImportSelector.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrarImportSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-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. @@ -29,7 +29,7 @@ import org.springframework.core.type.AnnotationMetadata; */ class IntegrationGraphControllerRegistrarImportSelector implements ImportSelector { - private static final Log logger = LogFactory.getLog(IntegrationGraphControllerRegistrarImportSelector.class); + private static final Log LOGGER = LogFactory.getLog(IntegrationGraphControllerRegistrarImportSelector.class); @Override public String[] selectImports(AnnotationMetadata importingClassMetadata) { @@ -37,7 +37,7 @@ class IntegrationGraphControllerRegistrarImportSelector implements ImportSelecto return new String[] { IntegrationGraphControllerRegistrar.class.getName() }; } else { - logger.warn("The 'IntegrationGraphController' isn't registered with the application context because" + + LOGGER.warn("The 'IntegrationGraphController' isn't registered with the application context because" + " there is no 'org.springframework.web.servlet.DispatcherServlet' or" + " 'org.springframework.web.reactive.DispatcherHandler' in the classpath."); return new String[0]; diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/FileCopyingMultipartFileReader.java b/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/FileCopyingMultipartFileReader.java index df5ee06468..67a0bafbd6 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/FileCopyingMultipartFileReader.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/FileCopyingMultipartFileReader.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. @@ -25,23 +25,25 @@ import org.apache.commons.logging.LogFactory; import org.springframework.web.multipart.MultipartFile; /** - * {@link MultipartFileReader} implementation that copies the MulitpartFile's + * {@link MultipartFileReader} implementation that copies the MultipartFile's * content to a new temporary File in the specified directory. If no directory * is provided, the Files will be created in the default temporary directory. * * @author Mark Fisher + * @author Artyem Bilan + * * @since 2.0 */ public class FileCopyingMultipartFileReader implements MultipartFileReader { - private static final Log logger = LogFactory.getLog(FileCopyingMultipartFileReader.class); + private static final Log LOGGER = LogFactory.getLog(FileCopyingMultipartFileReader.class); private final File directory; - private volatile String prefix = "si_"; + private String prefix = "si_"; - private volatile String suffix = ".tmp"; + private String suffix = ".tmp"; /** @@ -55,7 +57,6 @@ public class FileCopyingMultipartFileReader implements MultipartFileReader