Fix new Sonar smells

This commit is contained in:
Artem Bilan
2021-11-10 14:55:48 -05:00
parent e51513230a
commit 0aac4c0a86
6 changed files with 17 additions and 27 deletions

View File

@@ -20,6 +20,7 @@ import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -51,7 +52,7 @@ public final class JavaUtils {
* @param <T> the value type.
* @return this.
*/
public <T> JavaUtils acceptIfCondition(boolean condition, T value, Consumer<T> consumer) {
public <T> JavaUtils acceptIfCondition(boolean condition, @Nullable T value, Consumer<T> consumer) {
if (condition) {
consumer.accept(value);
}
@@ -65,7 +66,7 @@ public final class JavaUtils {
* @param <T> the value type.
* @return this.
*/
public <T> JavaUtils acceptIfNotNull(T value, Consumer<T> consumer) {
public <T> JavaUtils acceptIfNotNull(@Nullable T value, Consumer<T> consumer) {
if (value != null) {
consumer.accept(value);
}

View File

@@ -201,17 +201,16 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean<H extends MessageH
JavaUtils.INSTANCE
.acceptIfCondition(this.handler instanceof ApplicationContextAware && this.applicationContext != null,
this.applicationContext,
context -> ((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext))
((ApplicationContextAware) this.handler)::setApplicationContext)
.acceptIfCondition(this.handler instanceof BeanFactoryAware && getBeanFactory() != null,
getBeanFactory(),
factory -> ((BeanFactoryAware) this.handler).setBeanFactory(factory))
((BeanFactoryAware) this.handler)::setBeanFactory)
.acceptIfCondition(this.handler instanceof BeanNameAware && this.beanName != null, this.beanName,
name -> ((BeanNameAware) this.handler).setBeanName(this.beanName))
((BeanNameAware) this.handler)::setBeanName)
.acceptIfCondition(this.handler instanceof ApplicationEventPublisherAware
&& this.applicationEventPublisher != null,
this.applicationEventPublisher,
publisher -> ((ApplicationEventPublisherAware) this.handler)
.setApplicationEventPublisher(publisher));
((ApplicationEventPublisherAware) this.handler)::setApplicationEventPublisher);
configureOutputChannelIfAny();
Object actualHandler = extractTarget(this.handler);
if (actualHandler == null) {
@@ -223,9 +222,9 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean<H extends MessageH
JavaUtils.INSTANCE
.acceptIfCondition(this.async != null && actualHandler instanceof AbstractMessageProducingHandler,
this.async,
asyncValue -> ((AbstractMessageProducingHandler) handlerToConfigure).setAsync(asyncValue))
((AbstractMessageProducingHandler) handlerToConfigure)::setAsync)
.acceptIfCondition(this.handler instanceof Orderable && this.order != null,
this.order, theOrder -> ((Orderable) this.handler).setOrder(theOrder));
this.order, ((Orderable) this.handler)::setOrder);
this.initialized = true;
}
initializingBean();
@@ -236,9 +235,9 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean<H extends MessageH
if (actualHandler instanceof IntegrationObjectSupport) {
JavaUtils.INSTANCE
.acceptIfNotNull(this.componentName,
name -> ((IntegrationObjectSupport) handlerToConfigure).setComponentName(name))
((IntegrationObjectSupport) handlerToConfigure)::setComponentName)
.acceptIfNotNull(this.channelResolver,
resolver -> ((IntegrationObjectSupport) handlerToConfigure).setChannelResolver(resolver));
((IntegrationObjectSupport) handlerToConfigure)::setChannelResolver);
}
}

View File

@@ -28,7 +28,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
@@ -38,8 +37,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.log.LogAccessor;
import org.springframework.integration.channel.ChannelUtils;
import org.springframework.integration.channel.DefaultHeaderChannelRegistry;
@@ -69,7 +66,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.ClassUtils;
/**
* A {@link BeanFactoryPostProcessor} implementation that registers bean definitions
* A {@link BeanDefinitionRegistryPostProcessor} implementation that registers bean definitions
* for many infrastructure components with their default configurations.
* All of them can be overridden using particular bean names.
*
@@ -330,7 +327,6 @@ public class DefaultConfiguringBeanFactoryPostProcessor
*/
private void registerIntegrationProperties() {
if (!this.beanFactory.containsBean(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME)) {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(this.classLoader);
// TODO Revise in favor of 'IntegrationProperties' instance in the next 6.0 version
BeanDefinitionBuilder integrationPropertiesBuilder =
BeanDefinitionBuilder.genericBeanDefinition(PropertiesFactoryBean.class,

View File

@@ -95,10 +95,7 @@ public class AnnotationGatewayProxyFactoryBean extends GatewayProxyFactoryBean {
populateAsyncExecutorIfAny();
boolean proxyDefaultMethods = this.gatewayAttributes.getBoolean("proxyDefaultMethods");
if (proxyDefaultMethods) {
setProxyDefaultMethods(proxyDefaultMethods);
}
setProxyDefaultMethods(this.gatewayAttributes.getBoolean("proxyDefaultMethods"));
super.onInit();
}

View File

@@ -113,7 +113,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
private final Class<?> serviceInterface;
private final Set<Method> hasPayloadExpression = new HashSet<>();
private final Set<Method> havePayloadExpressions = new HashSet<>();
private MessageChannel defaultRequestChannel;
@@ -601,7 +601,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
}
private boolean findPayloadExpression(Method method) {
return method.isAnnotationPresent(Payload.class) || this.hasPayloadExpression.contains(method);
return method.isAnnotationPresent(Payload.class) || this.havePayloadExpressions.contains(method);
}
@Nullable
@@ -688,7 +688,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
Expression payloadExpression =
extractPayloadExpressionFromAnnotationOrMetadata(gatewayAnnotation, methodMetadata);
if (payloadExpression != null) {
this.hasPayloadExpression.add(method);
this.havePayloadExpressions.add(method);
}
String requestChannelName = extractRequestChannelFromAnnotationOrMetadata(gatewayAnnotation, methodMetadata);
String replyChannelName = extractReplyChannelFromAnnotationOrMetadata(gatewayAnnotation, methodMetadata);

View File

@@ -20,16 +20,13 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.context.annotation.Role;
import org.springframework.util.ClassUtils;
import io.micrometer.core.instrument.MeterRegistry;
/**
* An {@link ImportBeanDefinitionRegistrar} to conditionally add a {@link MicrometerMetricsCaptor}
* bean when {@code io.micrometer.core.instrument.MeterRegistry} is present in classpath and
* no {@link MicrometerMetricsCaptor#MICROMETER_CAPTOR_NAME} bean present yet.
* A {@link Configuration} to add a {@link MicrometerMetricsCaptor}.
*
* @author Artem Bilan
*