More Sonar resolutions

This commit is contained in:
Gary Russell
2018-11-20 13:42:30 -05:00
committed by Artem Bilan
parent aa8068a71b
commit c3f8c4af27
11 changed files with 44 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,12 @@ import org.springframework.messaging.Message;
* <ul>
* <li>The sequence is complete (if there is one).</li>
* <li>There are more messages than a threshold set by the user.</li>
* <li>The time elapsed since the earliest message, according to their timestamps, exceeds a timeout set by the user.</li>
* <li>The time elapsed since the earliest message, according to their timestamps, if
* present, exceeds a timeout set by the user.</li>
* </ul>
*
* @author Dave Syer
* @author Gary Russell
*
* @since 2.0
*/
@@ -61,6 +63,7 @@ public class TimeoutCountSequenceSizeReleaseStrategy implements ReleaseStrategy
this.timeout = timeout;
}
@Override
public boolean canRelease(MessageGroup messages) {
long elapsedTime = System.currentTimeMillis() - findEarliestTimestamp(messages);
return messages.isComplete() || messages.getMessages().size() >= this.threshold || elapsedTime > this.timeout;
@@ -73,10 +76,13 @@ public class TimeoutCountSequenceSizeReleaseStrategy implements ReleaseStrategy
private long findEarliestTimestamp(MessageGroup messages) {
long result = Long.MAX_VALUE;
for (Message<?> message : messages.getMessages()) {
long timestamp = message.getHeaders().getTimestamp();
if (timestamp < result) {
Long timestamp = message.getHeaders().getTimestamp();
if (timestamp != null && timestamp < result) {
result = timestamp;
}
else {
return Long.MAX_VALUE; // can't release based on time if there is no timestamp
}
}
return result;
}

View File

@@ -253,6 +253,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
}
@Override
@Nullable
public ChannelInterceptor removeInterceptor(int index) {
return this.interceptors.remove(index);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.integration.channel;
import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.messaging.support.ChannelInterceptor;
/**
@@ -28,6 +29,7 @@ import org.springframework.messaging.support.ChannelInterceptor;
* is an AOP Proxy.
* *
* @author Artem Bilan
* @author Gary Russell
* @since 4.0
*/
public interface ChannelInterceptorAware {
@@ -69,6 +71,7 @@ public interface ChannelInterceptorAware {
* @param index the index for the {@link org.springframework.messaging.support.ChannelInterceptor} to remove.
* @return the {@code boolean} if the {@link ChannelInterceptor} has been removed.
*/
@Nullable
ChannelInterceptor removeInterceptor(int index);
}

View File

@@ -20,6 +20,7 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.core.ErrorMessagePublisher;
import org.springframework.integration.support.ErrorMessageStrategy;
import org.springframework.integration.support.MessagingExceptionWrapper;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessagingException;
@@ -71,6 +72,7 @@ public class MessagePublishingErrorHandler extends ErrorMessagePublisher impleme
* @return the error channel.
* @since 4.3
*/
@Nullable
public MessageChannel getDefaultErrorChannel() {
return getChannel();
}
@@ -115,6 +117,7 @@ public class MessagePublishingErrorHandler extends ErrorMessagePublisher impleme
}
}
@Nullable
private MessageChannel resolveErrorChannel(Throwable t) {
Throwable actualThrowable = t;
if (t instanceof MessagingExceptionWrapper) {
@@ -137,7 +140,12 @@ public class MessagePublishingErrorHandler extends ErrorMessagePublisher impleme
Assert.isInstanceOf(String.class, errorChannelHeader,
"Unsupported error channel header type. Expected MessageChannel or String, but actual type is [" +
errorChannelHeader.getClass() + "]");
return getChannelResolver().resolveDestination((String) errorChannelHeader);
if (getChannelResolver() != null) {
return getChannelResolver().resolveDestination((String) errorChannelHeader);
}
else {
return null;
}
}
}

View File

@@ -275,10 +275,8 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean<H extends MessageH
return object;
}
Advised advised = (Advised) object;
if (advised.getTargetSource() == null) {
return null;
}
try {
// TargetSource is never null
return extractTarget(advised.getTargetSource().getTarget());
}
catch (Exception e) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,10 @@ class IdempotentReceiverAutoProxyCreator extends AbstractAutoProxyCreator {
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
pointcut.setMappedName("handleMessage");
idempotentReceiverInterceptor.setPointcut(pointcut);
idempotentReceiverInterceptor.setBeanFactory(getBeanFactory());
BeanFactory beanFactory = getBeanFactory();
if (beanFactory != null) {
idempotentReceiverInterceptor.setBeanFactory(beanFactory);
}
interceptors.add(idempotentReceiverInterceptor);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -107,7 +107,7 @@ public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRe
}
};
if ((boolean) componentScan.get("useDefaultFilters")) {
if ((boolean) componentScan.get("useDefaultFilters")) { // NOSONAR - never null
for (TypeFilter typeFilter : this.componentRegistrars.keySet()) {
scanner.addIncludeFilter(typeFilter);
}
@@ -147,7 +147,7 @@ public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRe
Set<String> basePackages = new HashSet<>();
for (String pkg : (String[]) componentScan.get("value")) {
for (String pkg : (String[]) componentScan.get("value")) { // NOSONAR - never null
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
@@ -210,7 +210,9 @@ public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRe
if (parserStrategyBean instanceof BeanClassLoaderAware) {
ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
if (classLoader != null) {
((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
}
}
if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ import org.springframework.integration.support.utils.IntegrationUtils;
/**
* @author Artem Bilan
* @author Gary Russell
* @since 4.0
*/
public class IntegrationConverterInitializer implements IntegrationConfigurationInitializer {
@@ -89,6 +90,6 @@ public class IntegrationConverterInitializer implements IntegrationConfiguration
.getValue();
}
converters.add(converterBeanDefinition);
converters.add(converterBeanDefinition); // NOSONAR never null
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import org.springframework.integration.history.MessageHistoryConfigurer;
* or from {@code MessageHistoryParser}.
*
* @author Artem Bilan
* @author Gary Russell
* @since 4.0
*/
public class MessageHistoryRegistrar implements ImportBeanDefinitionRegistrar {
@@ -44,7 +45,7 @@ public class MessageHistoryRegistrar implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableMessageHistory.class.getName());
Object componentNamePatterns = annotationAttributes.get("value");
Object componentNamePatterns = annotationAttributes.get("value"); // NOSONAR never null
if (componentNamePatterns instanceof String[]) {
StringBuilder componentNamePatternsString = new StringBuilder();

View File

@@ -66,7 +66,7 @@ public class MessagingGatewayRegistrar implements ImportBeanDefinitionRegistrar
List<MultiValueMap<String, Object>> valuesHierarchy = captureMetaAnnotationValues(importingClassMetadata);
Map<String, Object> annotationAttributes =
importingClassMetadata.getAnnotationAttributes(MessagingGateway.class.getName());
replaceEmptyOverrides(valuesHierarchy, annotationAttributes);
replaceEmptyOverrides(valuesHierarchy, annotationAttributes); // NOSONAR never null
annotationAttributes.put("serviceInterface", importingClassMetadata.getClassName());
BeanDefinitionReaderUtils.registerBeanDefinition(this.parse(annotationAttributes), registry);

View File

@@ -105,6 +105,7 @@ public class ErrorMessagePublisher implements BeanFactoryAware {
return this.messagingTemplate;
}
@Nullable
protected DestinationResolver<MessageChannel> getChannelResolver() {
return this.channelResolver;
}