Skip to content

Commit 2b1976c

Browse files
garyrussellartembilan
authored andcommitted
Core Sonar fixes
* Polishing according PR comments
1 parent fc18476 commit 2b1976c

25 files changed

+88
-44
lines changed

spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class IntegrationMessageHeaderAccessor extends MessageHeaderAccessor {
6969

7070
private Set<String> readOnlyHeaders = new HashSet<>();
7171

72-
public IntegrationMessageHeaderAccessor(Message<?> message) {
72+
public IntegrationMessageHeaderAccessor(@Nullable Message<?> message) {
7373
super(message);
7474
}
7575

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2017 the original author or authors.
2+
* Copyright 2015-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.
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.integration.dispatcher.AbstractDispatcher;
2626
import org.springframework.integration.support.MessagingExceptionWrapper;
27+
import org.springframework.lang.Nullable;
2728
import org.springframework.messaging.Message;
2829
import org.springframework.messaging.MessageDeliveryException;
2930
import org.springframework.messaging.MessageHandler;
@@ -60,7 +61,7 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne
6061

6162
protected volatile int executorInterceptorsSize;
6263

63-
public AbstractExecutorChannel(Executor executor) {
64+
public AbstractExecutorChannel(@Nullable Executor executor) {
6465
this.executor = executor;
6566
}
6667

@@ -171,6 +172,7 @@ public void run() {
171172
}
172173
}
173174

175+
@Nullable
174176
private Message<?> applyBeforeHandle(Message<?> message, Deque<ExecutorChannelInterceptor> interceptorStack) {
175177
Message<?> theMessage = message;
176178
for (ChannelInterceptor interceptor : AbstractExecutorChannel.this.interceptors.interceptors) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ private Message<?> convertPayloadIfNecessary(Message<?> message) {
554554

555555
@Override
556556
public void destroy() throws Exception {
557-
this.meters.forEach(t -> t.remove());
557+
this.meters.forEach(MeterFacade::remove);
558558
}
559559

560560
/**
@@ -566,7 +566,7 @@ protected static class ChannelInterceptorList {
566566

567567
protected final List<ChannelInterceptor> interceptors = new CopyOnWriteArrayList<ChannelInterceptor>();
568568

569-
private volatile int size;
569+
private int size;
570570

571571
public ChannelInterceptorList(Log logger) {
572572
this.logger = logger;
@@ -594,17 +594,19 @@ public void add(int index, ChannelInterceptor interceptor) {
594594
this.interceptors.add(index, interceptor);
595595
}
596596

597+
@Nullable
597598
public Message<?> preSend(Message<?> message, MessageChannel channel,
598599
Deque<ChannelInterceptor> interceptorStack) {
599600
if (this.size > 0) {
600601
for (ChannelInterceptor interceptor : this.interceptors) {
602+
Message<?> previous = message;
601603
message = interceptor.preSend(message, channel);
602604
if (message == null) {
603605
if (this.logger.isDebugEnabled()) {
604606
this.logger.debug(interceptor.getClass().getSimpleName()
605607
+ " returned null from preSend, i.e. precluding the send.");
606608
}
607-
afterSendCompletion(null, channel, false, null, interceptorStack);
609+
afterSendCompletion(previous, channel, false, null, interceptorStack);
608610
return null;
609611
}
610612
interceptorStack.add(interceptor);
@@ -648,6 +650,7 @@ public boolean preReceive(MessageChannel channel, Deque<ChannelInterceptor> inte
648650
return true;
649651
}
650652

653+
@Nullable
651654
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
652655
if (this.size > 0) {
653656
for (ChannelInterceptor interceptor : this.interceptors) {
@@ -688,6 +691,7 @@ public boolean remove(ChannelInterceptor interceptor) {
688691
}
689692
}
690693

694+
@Nullable
691695
public ChannelInterceptor remove(int index) {
692696
ChannelInterceptor removed = this.interceptors.remove(index);
693697
if (removed != null) {

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

Lines changed: 4 additions & 2 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.
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121

2222
import org.springframework.integration.core.MessageSelector;
23+
import org.springframework.lang.Nullable;
2324
import org.springframework.messaging.Message;
2425
import org.springframework.util.Assert;
2526

@@ -38,6 +39,7 @@
3839
* place. Such messages will not be included in the returned list.
3940
*
4041
* @author Mark Fisher
42+
* @author Gary Russell
4143
*/
4244
public class ChannelPurger {
4345

@@ -50,7 +52,7 @@ public ChannelPurger(QueueChannel... channels) {
5052
this(null, channels);
5153
}
5254

53-
public ChannelPurger(MessageSelector selector, QueueChannel... channels) {
55+
public ChannelPurger(@Nullable MessageSelector selector, QueueChannel... channels) {
5456
Assert.notEmpty(channels, "at least one channel is required");
5557
if (channels.length == 1) {
5658
Assert.notNull(channels[0], "channel must not be null");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.integration.store.MessageGroupQueue;
2525
import org.springframework.integration.store.PriorityCapableChannelMessageStore;
2626
import org.springframework.integration.util.UpperBound;
27+
import org.springframework.lang.Nullable;
2728
import org.springframework.messaging.Message;
2829
import org.springframework.messaging.MessageHeaders;
2930

@@ -84,7 +85,7 @@ public PriorityChannel(Comparator<Message<?>> comparator) {
8485
* @param capacity The capacity.
8586
* @param comparator The comparator.
8687
*/
87-
public PriorityChannel(int capacity, Comparator<Message<?>> comparator) {
88+
public PriorityChannel(int capacity, @Nullable Comparator<Message<?>> comparator) {
8889
super(new PriorityBlockingQueue<>(11, new SequenceFallbackComparator(comparator)));
8990
this.upperBound = new UpperBound(capacity);
9091
this.useMessageStore = false;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
2323
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
2424
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
25+
import org.springframework.lang.Nullable;
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.ErrorHandler;
2728

@@ -49,7 +50,7 @@ public class PublishSubscribeChannel extends AbstractExecutorChannel {
4950
* the message sender's thread.
5051
* @param executor The executor.
5152
*/
52-
public PublishSubscribeChannel(Executor executor) {
53+
public PublishSubscribeChannel(@Nullable Executor executor) {
5354
super(executor);
5455
this.dispatcher = new BroadcastingDispatcher(executor);
5556
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ protected BeanDefinitionBuilder parseHandler(Element element, ParserContext pars
9898
}
9999
catch (ParserConfigurationException e) {
100100
parserContext.getReaderContext().error(e.getMessage(), element);
101+
// NOSONAR below to prevent a false positive in SONAR for a null gatherer
101102
}
102103
}
103-
gathererDefinition = GATHERER_PARSER.parse(gatherer, new ParserContext(parserContext.getReaderContext(),
104+
gathererDefinition = GATHERER_PARSER.parse(gatherer, // NOSONAR
105+
new ParserContext(parserContext.getReaderContext(),
104106
parserContext.getDelegate(), scatterGatherDefinition));
105107
String gathererId = id + ".gatherer";
106108
if (gatherer != null && gatherer.hasAttribute(ID_ATTRIBUTE)) {

spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ protected void setTaskScheduler(TaskScheduler taskScheduler) {
227227

228228
public ConversionService getConversionService() {
229229
if (this.conversionService == null && this.beanFactory != null) {
230-
synchronized (this) {
231-
if (this.conversionService == null) {
232-
this.conversionService = IntegrationUtils.getConversionService(this.beanFactory);
233-
}
234-
}
230+
this.conversionService = IntegrationUtils.getConversionService(this.beanFactory);
235231
if (this.conversionService == null && this.logger.isDebugEnabled()) {
236232
this.logger.debug("Unable to attempt conversion of Message payload types. Component '" +
237233
this.getComponentName() + "' has no explicit ConversionService reference, " +

spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-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.
@@ -27,6 +27,7 @@
2727
import org.springframework.integration.support.ErrorMessageStrategy;
2828
import org.springframework.integration.support.ErrorMessageUtils;
2929
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
30+
import org.springframework.lang.Nullable;
3031
import org.springframework.messaging.Message;
3132
import org.springframework.messaging.MessageChannel;
3233
import org.springframework.messaging.MessagingException;
@@ -144,7 +145,7 @@ public void publish(Message<?> inputMessage, MessagingException exception) {
144145
* @param failedMessage the message.
145146
* @param throwable the throwable.
146147
*/
147-
public void publish(Message<?> inputMessage, Message<?> failedMessage, Throwable throwable) {
148+
public void publish(@Nullable Message<?> inputMessage, Message<?> failedMessage, Throwable throwable) {
148149
publish(throwable, ErrorMessageUtils.getAttributeAccessor(inputMessage, failedMessage));
149150
}
150151

spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlows.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
3333
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
3434
import org.springframework.integration.gateway.MessagingGatewaySupport;
35+
import org.springframework.lang.Nullable;
3536
import org.springframework.messaging.Message;
3637
import org.springframework.messaging.MessageChannel;
3738
import org.springframework.util.Assert;
@@ -326,7 +327,7 @@ public static IntegrationFlowBuilder from(Class<?> serviceInterface) {
326327
* @param beanName the bean name to be used for registering bean for the gateway proxy
327328
* @return new {@link IntegrationFlowBuilder}.
328329
*/
329-
public static IntegrationFlowBuilder from(Class<?> serviceInterface, String beanName) {
330+
public static IntegrationFlowBuilder from(Class<?> serviceInterface, @Nullable String beanName) {
330331
final DirectChannel gatewayRequestChannel = new DirectChannel();
331332

332333
GatewayProxyFactoryBean gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean(serviceInterface);

0 commit comments

Comments
 (0)