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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 5 additions & 5 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.
@@ -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

Lines changed: 20 additions & 14 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 5 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.
@@ -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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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) {

0 commit comments

Comments
 (0)