Skip to content

Commit c3f8c4a

Browse files
garyrussellartembilan
authored andcommitted
More Sonar resolutions
1 parent aa8068a commit c3f8c4a

11 files changed

+44
-20
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/TimeoutCountSequenceSizeReleaseStrategy.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,10 +25,12 @@
2525
* <ul>
2626
* <li>The sequence is complete (if there is one).</li>
2727
* <li>There are more messages than a threshold set by the user.</li>
28-
* <li>The time elapsed since the earliest message, according to their timestamps, exceeds a timeout set by the user.</li>
28+
* <li>The time elapsed since the earliest message, according to their timestamps, if
29+
* present, exceeds a timeout set by the user.</li>
2930
* </ul>
3031
*
3132
* @author Dave Syer
33+
* @author Gary Russell
3234
*
3335
* @since 2.0
3436
*/
@@ -61,6 +63,7 @@ public TimeoutCountSequenceSizeReleaseStrategy(int threshold, long timeout) {
6163
this.timeout = timeout;
6264
}
6365

66+
@Override
6467
public boolean canRelease(MessageGroup messages) {
6568
long elapsedTime = System.currentTimeMillis() - findEarliestTimestamp(messages);
6669
return messages.isComplete() || messages.getMessages().size() >= this.threshold || elapsedTime > this.timeout;
@@ -73,10 +76,13 @@ public boolean canRelease(MessageGroup messages) {
7376
private long findEarliestTimestamp(MessageGroup messages) {
7477
long result = Long.MAX_VALUE;
7578
for (Message<?> message : messages.getMessages()) {
76-
long timestamp = message.getHeaders().getTimestamp();
77-
if (timestamp < result) {
79+
Long timestamp = message.getHeaders().getTimestamp();
80+
if (timestamp != null && timestamp < result) {
7881
result = timestamp;
7982
}
83+
else {
84+
return Long.MAX_VALUE; // can't release based on time if there is no timestamp
85+
}
8086
}
8187
return result;
8288
}

spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public boolean removeInterceptor(ChannelInterceptor interceptor) {
253253
}
254254

255255
@Override
256+
@Nullable
256257
public ChannelInterceptor removeInterceptor(int index) {
257258
return this.interceptors.remove(index);
258259
}

spring-integration-core/src/main/java/org/springframework/integration/channel/ChannelInterceptorAware.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.List;
2020

21+
import org.springframework.lang.Nullable;
2122
import org.springframework.messaging.support.ChannelInterceptor;
2223

2324
/**
@@ -28,6 +29,7 @@
2829
* is an AOP Proxy.
2930
* *
3031
* @author Artem Bilan
32+
* @author Gary Russell
3133
* @since 4.0
3234
*/
3335
public interface ChannelInterceptorAware {
@@ -69,6 +71,7 @@ public interface ChannelInterceptorAware {
6971
* @param index the index for the {@link org.springframework.messaging.support.ChannelInterceptor} to remove.
7072
* @return the {@code boolean} if the {@link ChannelInterceptor} has been removed.
7173
*/
74+
@Nullable
7275
ChannelInterceptor removeInterceptor(int index);
7376

7477
}

spring-integration-core/src/main/java/org/springframework/integration/channel/MessagePublishingErrorHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.springframework.integration.core.ErrorMessagePublisher;
2121
import org.springframework.integration.support.ErrorMessageStrategy;
2222
import org.springframework.integration.support.MessagingExceptionWrapper;
23+
import org.springframework.lang.Nullable;
2324
import org.springframework.messaging.Message;
2425
import org.springframework.messaging.MessageChannel;
2526
import org.springframework.messaging.MessagingException;
@@ -71,6 +72,7 @@ public void setDefaultErrorChannel(MessageChannel defaultErrorChannel) {
7172
* @return the error channel.
7273
* @since 4.3
7374
*/
75+
@Nullable
7476
public MessageChannel getDefaultErrorChannel() {
7577
return getChannel();
7678
}
@@ -115,6 +117,7 @@ public final void handleError(Throwable t) {
115117
}
116118
}
117119

120+
@Nullable
118121
private MessageChannel resolveErrorChannel(Throwable t) {
119122
Throwable actualThrowable = t;
120123
if (t instanceof MessagingExceptionWrapper) {
@@ -137,7 +140,12 @@ private MessageChannel resolveErrorChannel(Throwable t) {
137140
Assert.isInstanceOf(String.class, errorChannelHeader,
138141
"Unsupported error channel header type. Expected MessageChannel or String, but actual type is [" +
139142
errorChannelHeader.getClass() + "]");
140-
return getChannelResolver().resolveDestination((String) errorChannelHeader);
143+
if (getChannelResolver() != null) {
144+
return getChannelResolver().resolveDestination((String) errorChannelHeader);
145+
}
146+
else {
147+
return null;
148+
}
141149
}
142150

143151
}

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,8 @@ private Object extractTarget(Object object) {
275275
return object;
276276
}
277277
Advised advised = (Advised) object;
278-
if (advised.getTargetSource() == null) {
279-
return null;
280-
}
281278
try {
279+
// TargetSource is never null
282280
return extractTarget(advised.getTargetSource().getTarget());
283281
}
284282
catch (Exception e) {

spring-integration-core/src/main/java/org/springframework/integration/config/IdempotentReceiverAutoProxyCreator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,7 +69,10 @@ protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanN
6969
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
7070
pointcut.setMappedName("handleMessage");
7171
idempotentReceiverInterceptor.setPointcut(pointcut);
72-
idempotentReceiverInterceptor.setBeanFactory(getBeanFactory());
72+
BeanFactory beanFactory = getBeanFactory();
73+
if (beanFactory != null) {
74+
idempotentReceiverInterceptor.setBeanFactory(beanFactory);
75+
}
7376
interceptors.add(idempotentReceiverInterceptor);
7477
}
7578
}

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,7 +107,7 @@ protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
107107
}
108108
};
109109

110-
if ((boolean) componentScan.get("useDefaultFilters")) {
110+
if ((boolean) componentScan.get("useDefaultFilters")) { // NOSONAR - never null
111111
for (TypeFilter typeFilter : this.componentRegistrars.keySet()) {
112112
scanner.addIncludeFilter(typeFilter);
113113
}
@@ -147,7 +147,7 @@ protected Collection<String> getBasePackages(AnnotationMetadata importingClassMe
147147

148148
Set<String> basePackages = new HashSet<>();
149149

150-
for (String pkg : (String[]) componentScan.get("value")) {
150+
for (String pkg : (String[]) componentScan.get("value")) { // NOSONAR - never null
151151
if (StringUtils.hasText(pkg)) {
152152
basePackages.add(pkg);
153153
}
@@ -210,7 +210,9 @@ private static void invokeAwareMethods(Object parserStrategyBean, Environment en
210210
if (parserStrategyBean instanceof BeanClassLoaderAware) {
211211
ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
212212
((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
213-
((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
213+
if (classLoader != null) {
214+
((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
215+
}
214216
}
215217
if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
216218
((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConverterInitializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535

3636
/**
3737
* @author Artem Bilan
38+
* @author Gary Russell
3839
* @since 4.0
3940
*/
4041
public class IntegrationConverterInitializer implements IntegrationConfigurationInitializer {
@@ -89,6 +90,6 @@ public void registerConverter(BeanDefinitionRegistry registry, BeanMetadataEleme
8990
.getValue();
9091
}
9192

92-
converters.add(converterBeanDefinition);
93+
converters.add(converterBeanDefinition); // NOSONAR never null
9394
}
9495
}

spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryRegistrar.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,14 +37,15 @@
3737
* or from {@code MessageHistoryParser}.
3838
*
3939
* @author Artem Bilan
40+
* @author Gary Russell
4041
* @since 4.0
4142
*/
4243
public class MessageHistoryRegistrar implements ImportBeanDefinitionRegistrar {
4344

4445
@Override
4546
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
4647
Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableMessageHistory.class.getName());
47-
Object componentNamePatterns = annotationAttributes.get("value");
48+
Object componentNamePatterns = annotationAttributes.get("value"); // NOSONAR never null
4849

4950
if (componentNamePatterns instanceof String[]) {
5051
StringBuilder componentNamePatternsString = new StringBuilder();

spring-integration-core/src/main/java/org/springframework/integration/config/MessagingGatewayRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
6666
List<MultiValueMap<String, Object>> valuesHierarchy = captureMetaAnnotationValues(importingClassMetadata);
6767
Map<String, Object> annotationAttributes =
6868
importingClassMetadata.getAnnotationAttributes(MessagingGateway.class.getName());
69-
replaceEmptyOverrides(valuesHierarchy, annotationAttributes);
69+
replaceEmptyOverrides(valuesHierarchy, annotationAttributes); // NOSONAR never null
7070
annotationAttributes.put("serviceInterface", importingClassMetadata.getClassName());
7171

7272
BeanDefinitionReaderUtils.registerBeanDefinition(this.parse(annotationAttributes), registry);

0 commit comments

Comments
 (0)