Skip to content

Commit 2766707

Browse files
garyrussellartembilan
authored andcommitted
Sonar fixes
- remaining hidden fields * Fix copyright
1 parent e30741f commit 2766707

File tree

28 files changed

+280
-272
lines changed

28 files changed

+280
-272
lines changed

spring-integration-core/src/main/java/org/springframework/integration/router/RecipientListRouter.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -84,10 +84,9 @@ public class RecipientListRouter extends AbstractMessageRouter
8484
*/
8585
public void setChannels(List<MessageChannel> channels) {
8686
Assert.notEmpty(channels, "'channels' must not be empty");
87-
List<Recipient> recipients = channels.stream()
87+
setRecipients(channels.stream()
8888
.map(Recipient::new)
89-
.collect(Collectors.toList());
90-
setRecipients(recipients);
89+
.collect(Collectors.toList()));
9190
}
9291

9392
/**
@@ -300,11 +299,13 @@ private MessageSelector getSelector() {
300299
}
301300

302301
public MessageChannel getChannel() {
303-
String channelName = this.channelName;
304-
if (channelName != null) {
305-
if (this.channelResolver != null) {
306-
this.channel = this.channelResolver.resolveDestination(channelName);
307-
this.channelName = null;
302+
if (this.channel == null) {
303+
String channelNameForInitialization = this.channelName;
304+
if (channelNameForInitialization != null) {
305+
if (this.channelResolver != null) {
306+
this.channel = this.channelResolver.resolveDestination(channelNameForInitialization);
307+
this.channelName = null;
308+
}
308309
}
309310
}
310311
return this.channel;

spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupQueue.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -165,17 +165,17 @@ public int size() {
165165
@Override
166166
public Message<?> peek() {
167167
Message<?> message = null;
168-
final Lock storeLock = this.storeLock;
168+
final Lock lock = this.storeLock;
169169
try {
170-
storeLock.lockInterruptibly();
170+
lock.lockInterruptibly();
171171
try {
172172
Collection<Message<?>> messages = getMessages();
173173
if (!messages.isEmpty()) {
174174
message = messages.iterator().next();
175175
}
176176
}
177177
finally {
178-
storeLock.unlock();
178+
lock.unlock();
179179
}
180180
}
181181
catch (InterruptedException e) {
@@ -188,8 +188,8 @@ public Message<?> peek() {
188188
public Message<?> poll(long timeout, TimeUnit unit) throws InterruptedException {
189189
Message<?> message = null;
190190
long timeoutInNanos = unit.toNanos(timeout);
191-
final Lock storeLock = this.storeLock;
192-
storeLock.lockInterruptibly();
191+
final Lock lock = this.storeLock;
192+
lock.lockInterruptibly();
193193

194194
try {
195195
message = doPoll();
@@ -199,22 +199,22 @@ public Message<?> poll(long timeout, TimeUnit unit) throws InterruptedException
199199
}
200200
}
201201
finally {
202-
storeLock.unlock();
202+
lock.unlock();
203203
}
204204
return message;
205205
}
206206

207207
@Override
208208
public Message<?> poll() {
209209
Message<?> message = null;
210-
final Lock storeLock = this.storeLock;
210+
final Lock lock = this.storeLock;
211211
try {
212-
storeLock.lockInterruptibly();
212+
lock.lockInterruptibly();
213213
try {
214214
message = this.doPoll();
215215
}
216216
finally {
217-
storeLock.unlock();
217+
lock.unlock();
218218
}
219219
}
220220
catch (InterruptedException e) {
@@ -233,9 +233,9 @@ public int drainTo(Collection<? super Message<?>> collection, int maxElements) {
233233
Assert.notNull(collection, "'collection' must not be null");
234234
int originalSize = collection.size();
235235
ArrayList<Message<?>> list = new ArrayList<>();
236-
final Lock storeLock = this.storeLock;
236+
final Lock lock = this.storeLock;
237237
try {
238-
storeLock.lockInterruptibly();
238+
lock.lockInterruptibly();
239239
try {
240240
Message<?> message = this.messageGroupStore.pollMessageFromGroup(this.groupId);
241241
for (int i = 0; i < maxElements && message != null; i++) {
@@ -245,7 +245,7 @@ public int drainTo(Collection<? super Message<?>> collection, int maxElements) {
245245
this.messageStoreNotFull.signal();
246246
}
247247
finally {
248-
storeLock.unlock();
248+
lock.unlock();
249249
}
250250
}
251251
catch (InterruptedException e) {
@@ -259,14 +259,14 @@ public int drainTo(Collection<? super Message<?>> collection, int maxElements) {
259259
@Override
260260
public boolean offer(Message<?> message) {
261261
boolean offered = true;
262-
final Lock storeLock = this.storeLock;
262+
final Lock lock = this.storeLock;
263263
try {
264-
storeLock.lockInterruptibly();
264+
lock.lockInterruptibly();
265265
try {
266266
offered = this.doOffer(message);
267267
}
268268
finally {
269-
storeLock.unlock();
269+
lock.unlock();
270270
}
271271
}
272272
catch (InterruptedException e) {
@@ -280,8 +280,8 @@ public boolean offer(Message<?> message, long timeout, TimeUnit unit) throws Int
280280
long timeoutInNanos = unit.toNanos(timeout);
281281
boolean offered = false;
282282

283-
final Lock storeLock = this.storeLock;
284-
storeLock.lockInterruptibly();
283+
final Lock lock = this.storeLock;
284+
lock.lockInterruptibly();
285285
try {
286286
if (this.capacity != Integer.MAX_VALUE) {
287287
while (this.size() == this.capacity && timeoutInNanos > 0) {
@@ -293,15 +293,15 @@ public boolean offer(Message<?> message, long timeout, TimeUnit unit) throws Int
293293
}
294294
}
295295
finally {
296-
storeLock.unlock();
296+
lock.unlock();
297297
}
298298
return offered;
299299
}
300300

301301
@Override
302302
public void put(Message<?> message) throws InterruptedException {
303-
final Lock storeLock = this.storeLock;
304-
storeLock.lockInterruptibly();
303+
final Lock lock = this.storeLock;
304+
lock.lockInterruptibly();
305305
try {
306306
if (this.capacity != Integer.MAX_VALUE) {
307307
while (this.size() == this.capacity) {
@@ -311,7 +311,7 @@ public void put(Message<?> message) throws InterruptedException {
311311
this.doOffer(message);
312312
}
313313
finally {
314-
storeLock.unlock();
314+
lock.unlock();
315315
}
316316
}
317317

@@ -326,8 +326,8 @@ public int remainingCapacity() {
326326
@Override
327327
public Message<?> take() throws InterruptedException {
328328
Message<?> message = null;
329-
final Lock storeLock = this.storeLock;
330-
storeLock.lockInterruptibly();
329+
final Lock lock = this.storeLock;
330+
lock.lockInterruptibly();
331331

332332
try {
333333
while (this.size() == 0) {
@@ -337,7 +337,7 @@ public Message<?> take() throws InterruptedException {
337337

338338
}
339339
finally {
340-
storeLock.unlock();
340+
lock.unlock();
341341
}
342342
return message;
343343
}

spring-integration-core/src/main/java/org/springframework/integration/support/IdGenerators.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2015 the original author or authors.
2+
* Copyright 2013-2019 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.
@@ -26,6 +26,7 @@
2626
* Alternative {@link IdGenerator} implementations.
2727
*
2828
* @author Andy Wilkinson
29+
* @author Gary Russell
2930
* @since 4.0
3031
*
3132
*/
@@ -67,12 +68,12 @@ public static class SimpleIncrementingIdGenerator implements IdGenerator {
6768

6869
@Override
6970
public UUID generateId() {
70-
long bottomBits = this.bottomBits.incrementAndGet();
71-
if (bottomBits == 0) {
72-
return new UUID(this.topBits.incrementAndGet(), bottomBits);
71+
long lowerBits = this.bottomBits.incrementAndGet();
72+
if (lowerBits == 0) {
73+
return new UUID(this.topBits.incrementAndGet(), lowerBits);
7374
}
7475
else {
75-
return new UUID(this.topBits.get(), bottomBits);
76+
return new UUID(this.topBits.get(), lowerBits);
7677
}
7778
}
7879

spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 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.
@@ -102,12 +102,12 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
102102
* @param lifecycle the {@link SmartLifecycle}.
103103
*/
104104
public final void addLifecycleToRole(String role, SmartLifecycle lifecycle) {
105-
List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
106-
if (CollectionUtils.isEmpty(lifecycles)) {
105+
List<SmartLifecycle> componentsInRole = this.lifecycles.get(role);
106+
if (CollectionUtils.isEmpty(componentsInRole)) {
107107
this.lifecycles.add(role, lifecycle);
108108
}
109109
else {
110-
lifecycles
110+
componentsInRole
111111
.stream()
112112
.filter(e ->
113113
e == lifecycle ||
@@ -125,7 +125,7 @@ public final void addLifecycleToRole(String role, SmartLifecycle lifecycle) {
125125
+ "' is already present.");
126126
});
127127

128-
lifecycles.add(lifecycle);
128+
componentsInRole.add(lifecycle);
129129
}
130130
}
131131

@@ -157,15 +157,15 @@ public void startLifecyclesInRole(String role) {
157157
if (this.lazyLifecycles.size() > 0) {
158158
addLazyLifecycles();
159159
}
160-
List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
161-
if (lifecycles != null) {
162-
lifecycles = new ArrayList<>(lifecycles);
163-
lifecycles.sort(Comparator.comparingInt(Phased::getPhase));
160+
List<SmartLifecycle> componentsInRole = this.lifecycles.get(role);
161+
if (componentsInRole != null) {
162+
componentsInRole = new ArrayList<>(componentsInRole);
163+
componentsInRole.sort(Comparator.comparingInt(Phased::getPhase));
164164
if (logger.isDebugEnabled()) {
165-
logger.debug("Starting " + lifecycles + " in role " + role);
165+
logger.debug("Starting " + componentsInRole + " in role " + role);
166166
}
167167

168-
lifecycles.forEach(lifecycle -> {
168+
componentsInRole.forEach(lifecycle -> {
169169
try {
170170
lifecycle.start();
171171
}
@@ -189,15 +189,15 @@ public void stopLifecyclesInRole(String role) {
189189
if (this.lazyLifecycles.size() > 0) {
190190
addLazyLifecycles();
191191
}
192-
List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
193-
if (lifecycles != null) {
194-
lifecycles = new ArrayList<>(lifecycles);
195-
lifecycles.sort((o1, o2) -> Integer.compare(o2.getPhase(), o1.getPhase()));
192+
List<SmartLifecycle> componentsInRole = this.lifecycles.get(role);
193+
if (componentsInRole != null) {
194+
componentsInRole = new ArrayList<>(componentsInRole);
195+
componentsInRole.sort((o1, o2) -> Integer.compare(o2.getPhase(), o1.getPhase()));
196196
if (logger.isDebugEnabled()) {
197-
logger.debug("Stopping " + lifecycles + " in role " + role);
197+
logger.debug("Stopping " + componentsInRole + " in role " + role);
198198
}
199199

200-
lifecycles.forEach(lifecycle -> {
200+
componentsInRole.forEach(lifecycle -> {
201201
try {
202202
lifecycle.stop();
203203
}
@@ -312,10 +312,10 @@ else if (event instanceof OnRevokedEvent) {
312312
public boolean removeLifecycle(SmartLifecycle lifecycle) {
313313
boolean removed = false;
314314

315-
for (List<SmartLifecycle> lifecycles : this.lifecycles.values()) {
316-
boolean actualRemoved = lifecycles.removeIf(Predicate.isEqual(lifecycle));
317-
if (!removed) {
318-
removed = actualRemoved;
315+
for (List<SmartLifecycle> componentsInRole : this.lifecycles.values()) {
316+
removed = componentsInRole.removeIf(Predicate.isEqual(lifecycle));
317+
if (removed) {
318+
break;
319319
}
320320
}
321321

spring-integration-core/src/main/java/org/springframework/integration/support/converter/DefaultDatatypeChannelMessageConverter.java

Lines changed: 6 additions & 7 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-2019 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.
@@ -72,13 +72,12 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
7272
*/
7373
@Override
7474
public Object fromMessage(Message<?> message, Class<?> targetClass) {
75-
ConversionService conversionService = this.conversionService;
76-
if (conversionService != null) {
77-
if (conversionService.canConvert(message.getPayload().getClass(), targetClass)) {
78-
return conversionService.convert(message.getPayload(), targetClass);
79-
}
75+
if (this.conversionService.canConvert(message.getPayload().getClass(), targetClass)) {
76+
return this.conversionService.convert(message.getPayload(), targetClass);
77+
}
78+
else {
79+
return null;
8080
}
81-
return null;
8281
}
8382

8483
@Override

0 commit comments

Comments
 (0)