Skip to content

Commit 62fc7df

Browse files
garyrussellartembilan
authored andcommitted
Sonar Fixes
Critical smells, packages `o.s.i.a*` to `f*`. Plus new smells caused by these changes.
1 parent 4ade0ce commit 62fc7df

File tree

45 files changed

+188
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+188
-140
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ subprojects { subproject ->
131131
romeToolsVersion = '1.9.0'
132132
servletApiVersion = '4.0.0'
133133
smackVersion = '4.3.1'
134-
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.1.2.RELEASE'
134+
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.1.3.BUILD-SNAPSHOT'
135135
springDataJpaVersion = '2.1.3.RELEASE'
136136
springDataMongoVersion = '2.1.3.RELEASE'
137137
springDataRedisVersion = '2.1.3.RELEASE'

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,9 @@ public void onMessage(org.springframework.amqp.core.Message message) {
288288
Message<?> messageToSend = null;
289289
try {
290290
Object converted = this.converter.fromMessage(message);
291-
if (converted != null) {
292-
messageToSend = (converted instanceof Message<?>) ? (Message<?>) converted
293-
: buildMessage(message, converted);
294-
this.dispatcher.dispatch(messageToSend);
295-
}
296-
else if (this.logger.isWarnEnabled()) {
297-
this.logger.warn("MessageConverter returned null, no Message to dispatch");
298-
}
291+
messageToSend = (converted instanceof Message<?>) ? (Message<?>) converted
292+
: buildMessage(message, converted);
293+
this.dispatcher.dispatch(messageToSend);
299294
}
300295
catch (MessageDispatchingException e) {
301296
String exceptionMessage = e.getMessage() + " for amqp-channel '"

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.springframework.integration.amqp.channel.PublishSubscribeAmqpChannel;
4747
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
4848
import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper;
49+
import org.springframework.lang.Nullable;
4950
import org.springframework.messaging.support.ChannelInterceptor;
5051
import org.springframework.transaction.PlatformTransactionManager;
5152
import org.springframework.transaction.interceptor.TransactionAttribute;
@@ -152,7 +153,7 @@ public AmqpChannelFactoryBean(boolean messageDriven) {
152153

153154

154155
@Override
155-
public void setBeanName(String name) {
156+
public void setBeanName(@Nullable String name) {
156157
this.beanName = name;
157158
}
158159

@@ -399,8 +400,8 @@ protected AbstractAmqpChannel createInstance() throws Exception {
399400
this.channel.setInterceptors(this.interceptors);
400401
}
401402
this.channel.setBeanName(this.beanName);
402-
if (this.getBeanFactory() != null) {
403-
this.channel.setBeanFactory(this.getBeanFactory());
403+
if (getBeanFactory() != null) {
404+
this.channel.setBeanFactory(getBeanFactory()); // NOSONAR never null
404405
}
405406
if (this.defaultDeliveryMode != null) {
406407
this.channel.setDefaultDeliveryMode(this.defaultDeliveryMode);

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

+5-5
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.
@@ -126,7 +126,7 @@ private MessageChannel resolveErrorChannel(Throwable t) {
126126
Message<?> failedMessage = (actualThrowable instanceof MessagingException) ?
127127
((MessagingException) actualThrowable).getFailedMessage() : null;
128128
if (getDefaultErrorChannel() == null && getChannelResolver() != null) {
129-
setChannel(getChannelResolver().resolveDestination(
129+
setChannel(getChannelResolver().resolveDestination(// NOSONAR not null
130130
IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME));
131131
}
132132

@@ -137,11 +137,11 @@ private MessageChannel resolveErrorChannel(Throwable t) {
137137
if (errorChannelHeader instanceof MessageChannel) {
138138
return (MessageChannel) errorChannelHeader;
139139
}
140-
Assert.isInstanceOf(String.class, errorChannelHeader,
140+
Assert.isInstanceOf(String.class, errorChannelHeader, () ->
141141
"Unsupported error channel header type. Expected MessageChannel or String, but actual type is [" +
142-
errorChannelHeader.getClass() + "]");
142+
errorChannelHeader.getClass() + "]"); // NOSONAR never null here
143143
if (getChannelResolver() != null) {
144-
return getChannelResolver().resolveDestination((String) errorChannelHeader);
144+
return getChannelResolver().resolveDestination((String) errorChannelHeader); // NOSONAR not null
145145
}
146146
else {
147147
return null;

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

+20-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.springframework.integration.core.MessageSelector;
2828
import org.springframework.integration.support.management.QueueChannelManagement;
29+
import org.springframework.lang.Nullable;
2930
import org.springframework.messaging.Message;
3031
import org.springframework.util.Assert;
3132

@@ -116,19 +117,7 @@ protected Message<?> doReceive(long timeout) {
116117
return ((BlockingQueue<Message<?>>) this.queue).poll(timeout, TimeUnit.MILLISECONDS);
117118
}
118119
else {
119-
Message<?> message = this.queue.poll();
120-
if (message == null) {
121-
long nanos = TimeUnit.MILLISECONDS.toNanos(timeout);
122-
long deadline = System.nanoTime() + nanos;
123-
while (message == null && nanos > 0) {
124-
this.queueSemaphore.tryAcquire(nanos, TimeUnit.NANOSECONDS); // NOSONAR ok to ignore result
125-
message = this.queue.poll();
126-
if (message == null) {
127-
nanos = deadline - System.nanoTime();
128-
}
129-
}
130-
}
131-
return message;
120+
return pollNonBlockingQueue(timeout);
132121
}
133122
}
134123
if (timeout == 0) {
@@ -141,7 +130,7 @@ protected Message<?> doReceive(long timeout) {
141130
else {
142131
Message<?> message = this.queue.poll();
143132
while (message == null) {
144-
this.queueSemaphore.tryAcquire(50, TimeUnit.MILLISECONDS);
133+
this.queueSemaphore.tryAcquire(50, TimeUnit.MILLISECONDS); // NOSONAR ok to ignore result
145134
message = this.queue.poll();
146135
}
147136
return message;
@@ -153,6 +142,23 @@ protected Message<?> doReceive(long timeout) {
153142
}
154143
}
155144

145+
@Nullable
146+
private Message<?> pollNonBlockingQueue(long timeout) throws InterruptedException {
147+
Message<?> message = this.queue.poll();
148+
if (message == null) {
149+
long nanos = TimeUnit.MILLISECONDS.toNanos(timeout);
150+
long deadline = System.nanoTime() + nanos;
151+
while (message == null && nanos > 0) {
152+
this.queueSemaphore.tryAcquire(nanos, TimeUnit.NANOSECONDS); // NOSONAR ok to ignore result
153+
message = this.queue.poll();
154+
if (message == null) {
155+
nanos = deadline - System.nanoTime();
156+
}
157+
}
158+
}
159+
return message;
160+
}
161+
156162
@Override
157163
public List<Message<?>> clear() {
158164
List<Message<?>> clearedMessages = new ArrayList<>();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private void registerNullChannel() {
160160
else {
161161
nullChannelDefinition =
162162
((BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory())
163-
.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
163+
.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); // NOSONAR not null
164164
}
165165
if (!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
166166
throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME

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

+10-5
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.
@@ -38,6 +38,7 @@
3838
* {@link org.springframework.context.annotation.Bean} methods are also processed.
3939
*
4040
* @author Artem Bilan
41+
* @author Gary Russell
4142
* @since 4.0
4243
*/
4344
public class GlobalChannelInterceptorInitializer implements IntegrationConfigurationInitializer {
@@ -50,14 +51,18 @@ public void initialize(ConfigurableListableBeanFactory beanFactory) throws Beans
5051
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
5152
if (beanDefinition instanceof AnnotatedBeanDefinition) {
5253
AnnotationMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata();
53-
Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(GlobalChannelInterceptor.class.getName());
54-
if (CollectionUtils.isEmpty(annotationAttributes) && beanDefinition.getSource() instanceof MethodMetadata) {
54+
Map<String, Object> annotationAttributes = metadata
55+
.getAnnotationAttributes(GlobalChannelInterceptor.class.getName());
56+
if (CollectionUtils.isEmpty(annotationAttributes)
57+
&& beanDefinition.getSource() instanceof MethodMetadata) {
5558
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
56-
annotationAttributes = beanMethod.getAnnotationAttributes(GlobalChannelInterceptor.class.getName());
59+
annotationAttributes =
60+
beanMethod.getAnnotationAttributes(GlobalChannelInterceptor.class.getName()); // NOSONAR not null
5761
}
5862

5963
if (!CollectionUtils.isEmpty(annotationAttributes)) {
60-
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorWrapper.class)
64+
BeanDefinitionBuilder builder = BeanDefinitionBuilder
65+
.genericBeanDefinition(GlobalChannelInterceptorWrapper.class)
6166
.addConstructorArgReference(beanName)
6267
.addPropertyValue("patterns", annotationAttributes.get("patterns"))
6368
.addPropertyValue("order", annotationAttributes.get("order"));

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -48,6 +48,7 @@ public final class IdGeneratorConfigurer implements ApplicationListener<Applicat
4848

4949
private final Log logger = LogFactory.getLog(getClass());
5050

51+
@Override
5152
public synchronized void onApplicationEvent(ApplicationContextEvent event) {
5253
ApplicationContext context = event.getApplicationContext();
5354
if (event instanceof ContextRefreshedEvent) {
@@ -75,7 +76,7 @@ private boolean setIdGenerator(ApplicationContext context) {
7576
this.logger.debug("using custom MessageHeaders.IdGenerator [" + idGeneratorBean.getClass() + "]");
7677
}
7778
Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator");
78-
ReflectionUtils.makeAccessible(idGeneratorField);
79+
ReflectionUtils.makeAccessible(idGeneratorField); // NOSONAR never null
7980
IdGenerator currentIdGenerator = (IdGenerator) ReflectionUtils.getField(idGeneratorField, null);
8081
if (currentIdGenerator != null) {
8182
if (currentIdGenerator.equals(idGeneratorBean)) {
@@ -128,7 +129,7 @@ else if (this.logger.isDebugEnabled()) {
128129
private void unsetIdGenerator() {
129130
try {
130131
Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator");
131-
ReflectionUtils.makeAccessible(idGeneratorField);
132+
ReflectionUtils.makeAccessible(idGeneratorField); // NOSONAR never null
132133
idGeneratorField.set(null, null);
133134
IdGeneratorConfigurer.theIdGenerator = null;
134135
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ else if (beanDefinition instanceof AnnotatedBeanDefinition) {
7979
if (beanDefinition.getSource() instanceof MethodMetadata) {
8080
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
8181
String annotationType = IdempotentReceiver.class.getName();
82-
if (beanMethod.isAnnotated(annotationType)) {
83-
Object value = beanMethod.getAnnotationAttributes(annotationType).get("value");
82+
if (beanMethod.isAnnotated(annotationType)) { // NOSONAR never null
83+
Object value = beanMethod.getAnnotationAttributes(annotationType).get("value"); // NOSONAR
8484
if (value != null) {
8585

8686
Class<?> returnType;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void initialize(ConfigurableListableBeanFactory beanFactory) throws Beans
5454

5555
if (!hasIntegrationConverter && beanDefinition.getSource() instanceof MethodMetadata) {
5656
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
57-
hasIntegrationConverter = beanMethod.isAnnotated(IntegrationConverter.class.getName());
57+
hasIntegrationConverter = beanMethod.isAnnotated(IntegrationConverter.class.getName()); // NOSONAR never null
5858
}
5959

6060
if (hasIntegrationConverter) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
7373
if (propertyValue != null) {
7474
@SuppressWarnings("unchecked")
7575
Set<Object> currentComponentNamePatternsSet = (Set<Object>) propertyValue.getValue();
76-
currentComponentNamePatternsSet.add(componentNamePatterns);
76+
currentComponentNamePatternsSet.add(componentNamePatterns); // NOSONAR never null
7777
}
7878
else {
7979
Set<Object> componentNamePatternsSet = new ManagedSet<Object>();

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.springframework.integration.scheduling.PollerMetadata;
6767
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
6868
import org.springframework.integration.util.MessagingAnnotationUtils;
69+
import org.springframework.lang.Nullable;
6970
import org.springframework.messaging.MessageChannel;
7071
import org.springframework.messaging.MessageHandler;
7172
import org.springframework.messaging.PollableChannel;
@@ -195,7 +196,7 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
195196

196197
if (AnnotatedElementUtils.isAnnotated(method, IdempotentReceiver.class.getName())
197198
&& !AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
198-
String[] interceptors = AnnotationUtils.getAnnotation(method, IdempotentReceiver.class).value();
199+
String[] interceptors = AnnotationUtils.getAnnotation(method, IdempotentReceiver.class).value(); // NOSONAR never null
199200
for (String interceptor : interceptors) {
200201
DefaultBeanFactoryPointcutAdvisor advisor = new DefaultBeanFactoryPointcutAdvisor();
201202
advisor.setAdviceBeanName(interceptor);
@@ -469,15 +470,15 @@ protected Object resolveTargetBeanFromMethodWithBeanAnnotation(Method method) {
469470

470471
protected String resolveTargetBeanName(Method method) {
471472
String id = method.getName();
472-
String[] names = AnnotationUtils.getAnnotation(method, Bean.class).name();
473+
String[] names = AnnotationUtils.getAnnotation(method, Bean.class).name(); // NOSONAR never null
473474
if (!ObjectUtils.isEmpty(names)) {
474475
id = names[0];
475476
}
476477
return id;
477478
}
478479

479480
@SuppressWarnings("unchecked")
480-
protected <H> H extractTypeIfPossible(Object targetObject, Class<H> expectedType) {
481+
protected <H> H extractTypeIfPossible(@Nullable Object targetObject, Class<H> expectedType) {
481482
if (targetObject == null) {
482483
return null;
483484
}
@@ -486,9 +487,6 @@ protected <H> H extractTypeIfPossible(Object targetObject, Class<H> expectedType
486487
}
487488
if (targetObject instanceof Advised) {
488489
TargetSource targetSource = ((Advised) targetObject).getTargetSource();
489-
if (targetSource == null) {
490-
return null;
491-
}
492490
try {
493491
return extractTypeIfPossible(targetSource.getTarget(), expectedType);
494492
}

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

+3-3
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.
@@ -156,8 +156,8 @@ protected final AbstractBeanDefinition parseInternal(Element element, ParserCont
156156

157157
@SuppressWarnings("unchecked")
158158
Collection<String> channelCandidateNames =
159-
(Collection<String>) caValues.getArgumentValue(0, Collection.class).getValue();
160-
channelCandidateNames.add(inputChannelName);
159+
(Collection<String>) caValues.getArgumentValue(0, Collection.class).getValue(); // NOSONAR see comment above
160+
channelCandidateNames.add(inputChannelName); // NOSONAR
161161
}
162162
else {
163163
parserContext.getReaderContext().error("Failed to locate '" +

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -49,6 +49,7 @@
4949
* @author Oleg Zhurakousky
5050
* @author Artem Bilan
5151
* @author Gunnar Hillert
52+
* @author Gary Russell
5253
*/
5354
public class ChainParser extends AbstractConsumerEndpointParser {
5455

@@ -147,7 +148,7 @@ private BeanMetadataElement parseChild(String chainHandlerId, Element element, i
147148
}
148149
}
149150

150-
holder.getBeanDefinition().getPropertyValues().add("componentName", handlerComponentName);
151+
holder.getBeanDefinition().getPropertyValues().add("componentName", handlerComponentName); // NOSONAR never null
151152

152153
if (hasId) {
153154
BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 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.
@@ -36,6 +36,7 @@
3636
*
3737
* @author Mark Fisher
3838
* @author Oleg Zhurakousky
39+
* @author Gary Russell
3940
*/
4041
public class ChannelInterceptorParser {
4142

@@ -60,7 +61,7 @@ public ManagedList parseInterceptors(Element element, ParserContext parserContex
6061
if ("bean".equals(localName)) {
6162
BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
6263
BeanDefinitionHolder holder = delegate.parseBeanDefinitionElement(childElement);
63-
holder = delegate.decorateBeanDefinitionIfRequired(childElement, holder);
64+
holder = delegate.decorateBeanDefinitionIfRequired(childElement, holder); // NOSONAR never null
6465
parserContext.registerBeanComponent(new BeanComponentDefinition(holder));
6566
interceptors.add(new RuntimeBeanReference(holder.getBeanName()));
6667
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -97,7 +97,8 @@ else if (delegate.nodeNameEquals(child, BeanDefinitionParserDelegate.REF_ELEMENT
9797
}
9898
else {
9999
BeanDefinition beanDef = delegate.parseCustomElement(child);
100-
beanName = BeanDefinitionReaderUtils.generateBeanName(beanDef, parserContext.getRegistry());
100+
beanName = BeanDefinitionReaderUtils.generateBeanName(beanDef, // NOSONAR never null
101+
parserContext.getRegistry());
101102
}
102103
}
103104
}

0 commit comments

Comments
 (0)