Sonar fixes

- remaining hidden fields

* Fix copyright
This commit is contained in:
Gary Russell
2019-01-09 13:30:08 -05:00
committed by Artem Bilan
parent e30741f7eb
commit 2766707547
28 changed files with 280 additions and 272 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,10 +84,9 @@ public class RecipientListRouter extends AbstractMessageRouter
*/
public void setChannels(List<MessageChannel> channels) {
Assert.notEmpty(channels, "'channels' must not be empty");
List<Recipient> recipients = channels.stream()
setRecipients(channels.stream()
.map(Recipient::new)
.collect(Collectors.toList());
setRecipients(recipients);
.collect(Collectors.toList()));
}
/**
@@ -300,11 +299,13 @@ public class RecipientListRouter extends AbstractMessageRouter
}
public MessageChannel getChannel() {
String channelName = this.channelName;
if (channelName != null) {
if (this.channelResolver != null) {
this.channel = this.channelResolver.resolveDestination(channelName);
this.channelName = null;
if (this.channel == null) {
String channelNameForInitialization = this.channelName;
if (channelNameForInitialization != null) {
if (this.channelResolver != null) {
this.channel = this.channelResolver.resolveDestination(channelNameForInitialization);
this.channelName = null;
}
}
}
return this.channel;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -165,9 +165,9 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
@Override
public Message<?> peek() {
Message<?> message = null;
final Lock storeLock = this.storeLock;
final Lock lock = this.storeLock;
try {
storeLock.lockInterruptibly();
lock.lockInterruptibly();
try {
Collection<Message<?>> messages = getMessages();
if (!messages.isEmpty()) {
@@ -175,7 +175,7 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
}
}
finally {
storeLock.unlock();
lock.unlock();
}
}
catch (InterruptedException e) {
@@ -188,8 +188,8 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
public Message<?> poll(long timeout, TimeUnit unit) throws InterruptedException {
Message<?> message = null;
long timeoutInNanos = unit.toNanos(timeout);
final Lock storeLock = this.storeLock;
storeLock.lockInterruptibly();
final Lock lock = this.storeLock;
lock.lockInterruptibly();
try {
message = doPoll();
@@ -199,7 +199,7 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
}
}
finally {
storeLock.unlock();
lock.unlock();
}
return message;
}
@@ -207,14 +207,14 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
@Override
public Message<?> poll() {
Message<?> message = null;
final Lock storeLock = this.storeLock;
final Lock lock = this.storeLock;
try {
storeLock.lockInterruptibly();
lock.lockInterruptibly();
try {
message = this.doPoll();
}
finally {
storeLock.unlock();
lock.unlock();
}
}
catch (InterruptedException e) {
@@ -233,9 +233,9 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
Assert.notNull(collection, "'collection' must not be null");
int originalSize = collection.size();
ArrayList<Message<?>> list = new ArrayList<>();
final Lock storeLock = this.storeLock;
final Lock lock = this.storeLock;
try {
storeLock.lockInterruptibly();
lock.lockInterruptibly();
try {
Message<?> message = this.messageGroupStore.pollMessageFromGroup(this.groupId);
for (int i = 0; i < maxElements && message != null; i++) {
@@ -245,7 +245,7 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
this.messageStoreNotFull.signal();
}
finally {
storeLock.unlock();
lock.unlock();
}
}
catch (InterruptedException e) {
@@ -259,14 +259,14 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
@Override
public boolean offer(Message<?> message) {
boolean offered = true;
final Lock storeLock = this.storeLock;
final Lock lock = this.storeLock;
try {
storeLock.lockInterruptibly();
lock.lockInterruptibly();
try {
offered = this.doOffer(message);
}
finally {
storeLock.unlock();
lock.unlock();
}
}
catch (InterruptedException e) {
@@ -280,8 +280,8 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
long timeoutInNanos = unit.toNanos(timeout);
boolean offered = false;
final Lock storeLock = this.storeLock;
storeLock.lockInterruptibly();
final Lock lock = this.storeLock;
lock.lockInterruptibly();
try {
if (this.capacity != Integer.MAX_VALUE) {
while (this.size() == this.capacity && timeoutInNanos > 0) {
@@ -293,15 +293,15 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
}
}
finally {
storeLock.unlock();
lock.unlock();
}
return offered;
}
@Override
public void put(Message<?> message) throws InterruptedException {
final Lock storeLock = this.storeLock;
storeLock.lockInterruptibly();
final Lock lock = this.storeLock;
lock.lockInterruptibly();
try {
if (this.capacity != Integer.MAX_VALUE) {
while (this.size() == this.capacity) {
@@ -311,7 +311,7 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
this.doOffer(message);
}
finally {
storeLock.unlock();
lock.unlock();
}
}
@@ -326,8 +326,8 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
@Override
public Message<?> take() throws InterruptedException {
Message<?> message = null;
final Lock storeLock = this.storeLock;
storeLock.lockInterruptibly();
final Lock lock = this.storeLock;
lock.lockInterruptibly();
try {
while (this.size() == 0) {
@@ -337,7 +337,7 @@ public class MessageGroupQueue extends AbstractQueue<Message<?>> implements Bloc
}
finally {
storeLock.unlock();
lock.unlock();
}
return message;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import org.springframework.util.IdGenerator;
* Alternative {@link IdGenerator} implementations.
*
* @author Andy Wilkinson
* @author Gary Russell
* @since 4.0
*
*/
@@ -67,12 +68,12 @@ public class IdGenerators {
@Override
public UUID generateId() {
long bottomBits = this.bottomBits.incrementAndGet();
if (bottomBits == 0) {
return new UUID(this.topBits.incrementAndGet(), bottomBits);
long lowerBits = this.bottomBits.incrementAndGet();
if (lowerBits == 0) {
return new UUID(this.topBits.incrementAndGet(), lowerBits);
}
else {
return new UUID(this.topBits.get(), bottomBits);
return new UUID(this.topBits.get(), lowerBits);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -102,12 +102,12 @@ public class SmartLifecycleRoleController implements ApplicationListener<Abstrac
* @param lifecycle the {@link SmartLifecycle}.
*/
public final void addLifecycleToRole(String role, SmartLifecycle lifecycle) {
List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
if (CollectionUtils.isEmpty(lifecycles)) {
List<SmartLifecycle> componentsInRole = this.lifecycles.get(role);
if (CollectionUtils.isEmpty(componentsInRole)) {
this.lifecycles.add(role, lifecycle);
}
else {
lifecycles
componentsInRole
.stream()
.filter(e ->
e == lifecycle ||
@@ -125,7 +125,7 @@ public class SmartLifecycleRoleController implements ApplicationListener<Abstrac
+ "' is already present.");
});
lifecycles.add(lifecycle);
componentsInRole.add(lifecycle);
}
}
@@ -157,15 +157,15 @@ public class SmartLifecycleRoleController implements ApplicationListener<Abstrac
if (this.lazyLifecycles.size() > 0) {
addLazyLifecycles();
}
List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
if (lifecycles != null) {
lifecycles = new ArrayList<>(lifecycles);
lifecycles.sort(Comparator.comparingInt(Phased::getPhase));
List<SmartLifecycle> componentsInRole = this.lifecycles.get(role);
if (componentsInRole != null) {
componentsInRole = new ArrayList<>(componentsInRole);
componentsInRole.sort(Comparator.comparingInt(Phased::getPhase));
if (logger.isDebugEnabled()) {
logger.debug("Starting " + lifecycles + " in role " + role);
logger.debug("Starting " + componentsInRole + " in role " + role);
}
lifecycles.forEach(lifecycle -> {
componentsInRole.forEach(lifecycle -> {
try {
lifecycle.start();
}
@@ -189,15 +189,15 @@ public class SmartLifecycleRoleController implements ApplicationListener<Abstrac
if (this.lazyLifecycles.size() > 0) {
addLazyLifecycles();
}
List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
if (lifecycles != null) {
lifecycles = new ArrayList<>(lifecycles);
lifecycles.sort((o1, o2) -> Integer.compare(o2.getPhase(), o1.getPhase()));
List<SmartLifecycle> componentsInRole = this.lifecycles.get(role);
if (componentsInRole != null) {
componentsInRole = new ArrayList<>(componentsInRole);
componentsInRole.sort((o1, o2) -> Integer.compare(o2.getPhase(), o1.getPhase()));
if (logger.isDebugEnabled()) {
logger.debug("Stopping " + lifecycles + " in role " + role);
logger.debug("Stopping " + componentsInRole + " in role " + role);
}
lifecycles.forEach(lifecycle -> {
componentsInRole.forEach(lifecycle -> {
try {
lifecycle.stop();
}
@@ -312,10 +312,10 @@ public class SmartLifecycleRoleController implements ApplicationListener<Abstrac
public boolean removeLifecycle(SmartLifecycle lifecycle) {
boolean removed = false;
for (List<SmartLifecycle> lifecycles : this.lifecycles.values()) {
boolean actualRemoved = lifecycles.removeIf(Predicate.isEqual(lifecycle));
if (!removed) {
removed = actualRemoved;
for (List<SmartLifecycle> componentsInRole : this.lifecycles.values()) {
removed = componentsInRole.removeIf(Predicate.isEqual(lifecycle));
if (removed) {
break;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,13 +72,12 @@ public class DefaultDatatypeChannelMessageConverter implements MessageConverter,
*/
@Override
public Object fromMessage(Message<?> message, Class<?> targetClass) {
ConversionService conversionService = this.conversionService;
if (conversionService != null) {
if (conversionService.canConvert(message.getPayload().getClass(), targetClass)) {
return conversionService.convert(message.getPayload(), targetClass);
}
if (this.conversionService.canConvert(message.getPayload().getClass(), targetClass)) {
return this.conversionService.convert(message.getPayload(), targetClass);
}
else {
return null;
}
return null;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,41 +98,41 @@ public class ExponentialMovingAverage {
private Statistics calc() {
List<Double> copy;
long count;
long currentCount;
synchronized (this) {
copy = new ArrayList<Double>(this.samples);
count = this.count;
currentCount = this.count;
}
double sum = 0;
double decay = 1 - 1. / this.window;
double sumSquares = 0;
double weight = 0;
double min = this.min;
double max = this.max;
double currentMin = this.min;
double currentMax = this.max;
for (Double value : copy) {
value /= this.factor;
if (value > max) {
max = value;
if (value > currentMax) {
currentMax = value;
}
if (value < min) {
min = value;
if (value < currentMin) {
currentMin = value;
}
sum = decay * sum + value;
sumSquares = decay * sumSquares + value * value;
weight = decay * weight + 1;
}
synchronized (this) {
if (max > this.max) {
this.max = max;
if (currentMax > this.max) {
this.max = currentMax;
}
if (min < this.min) {
this.min = min;
if (currentMin < this.min) {
this.min = currentMin;
}
}
double mean = weight > 0 ? sum / weight : 0.;
double var = weight > 0 ? sumSquares / weight - mean * mean : 0.;
double standardDeviation = var > 0 ? Math.sqrt(var) : 0;
return new Statistics(count, min == Double.MAX_VALUE ? 0 : min, max, mean, standardDeviation); //NOSONAR
return new Statistics(currentCount, currentMin == Double.MAX_VALUE ? 0 : currentMin, currentMax, mean, standardDeviation); //NOSONAR
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,50 +120,50 @@ public class ExponentialMovingAverageRate {
private Statistics calcStatic() {
List<Long> copy;
long count;
long currentCount;
synchronized (this) {
copy = new ArrayList<Long>(this.times);
count = this.count;
currentCount = this.count;
}
ExponentialMovingAverage rates = new ExponentialMovingAverage(this.window);
double t0 = 0;
double currentT0 = 0;
double sum = 0;
double weight = 0;
double min = this.min;
double max = this.max;
double currentMin = this.min;
double currentMax = this.max;
int size = copy.size();
for (Long time : copy) {
double t = time / this.factor;
if (size == 1) {
t0 = this.t0;
currentT0 = this.t0;
}
else if (t0 == 0) {
t0 = t;
else if (currentT0 == 0) {
currentT0 = t;
continue;
}
double delta = t - t0;
double delta = t - currentT0;
double value = delta > 0 ? delta / this.period : 0;
if (value > max) {
max = value;
if (value > currentMax) {
currentMax = value;
}
if (value < min) {
min = value;
if (value < currentMin) {
currentMin = value;
}
double alpha = Math.exp(-delta * this.lapse);
t0 = t;
currentT0 = t;
sum = alpha * sum + value;
weight = alpha * weight + 1;
rates.append(sum > 0 ? weight / sum : 0);
}
synchronized (this) {
if (max > this.max) {
this.max = max;
if (currentMax > this.max) {
this.max = currentMax;
}
if (min < this.min) {
this.min = min;
if (currentMin < this.min) {
this.min = currentMin;
}
}
return new Statistics(count, min < Double.MAX_VALUE ? min : 0, max, rates.getMean(),
return new Statistics(currentCount, currentMin < Double.MAX_VALUE ? currentMin : 0, currentMax, rates.getMean(),
rates.getStandardDeviation());
}
@@ -189,8 +189,8 @@ public class ExponentialMovingAverageRate {
if (this.count == 0) {
return 0;
}
double t0 = lastTime();
return (System.nanoTime() / this.factor - t0);
double currentT0 = lastTime();
return (System.nanoTime() / this.factor - currentT0);
}
/**
@@ -206,15 +206,15 @@ public class ExponentialMovingAverageRate {
* @return the new mean.
*/
private double recalcMean(Statistics staticStats) {
long count = this.count;
count = count > this.retention ? this.retention : count;
if (count == 0) {
long currentCount = this.count;
currentCount = currentCount > this.retention ? this.retention : currentCount;
if (currentCount == 0) {
return 0;
}
double t0 = lastTime();
double currentT0 = lastTime();
double t = System.nanoTime() / this.factor;
double value = t > t0 ? (t - t0) / this.period : 0;
return count / (count / staticStats.getMean() + value);
double value = t > currentT0 ? (t - currentT0) / this.period : 0;
return currentCount / (currentCount / staticStats.getMean() + value);
}
private synchronized double lastTime() {
@@ -237,16 +237,16 @@ public class ExponentialMovingAverageRate {
* @return the maximum value recorded (not weighted)
*/
public double getMax() {
double min = calcStatic().getMin();
return min > 0 ? 1 / min : 0;
double currentMin = calcStatic().getMin();
return currentMin > 0 ? 1 / currentMin : 0;
}
/**
* @return the minimum value recorded (not weighted)
*/
public double getMin() {
double max = calcStatic().getMax();
return max > 0 ? 1 / max : 0;
double currentMax = calcStatic().getMax();
return currentMax > 0 ? 1 / currentMax : 0;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -140,52 +140,52 @@ public class ExponentialMovingAverageRatio {
private Statistics calcStatic() {
List<Long> copyTimes;
List<Integer> copyValues;
long count;
long currentCount;
synchronized (this) {
copyTimes = new ArrayList<Long>(this.times);
copyValues = new ArrayList<Integer>(this.values);
count = this.count;
currentCount = this.count;
}
ExponentialMovingAverage cumulative = new ExponentialMovingAverage(this.window);
double t0 = 0;
double currentT0 = 0;
double sum = 0;
double weight = 0;
double min = this.min;
double max = this.max;
double currentMin = this.min;
double currentMax = this.max;
int size = copyTimes.size();
Iterator<Integer> values = copyValues.iterator();
Iterator<Integer> valuesIterator = copyValues.iterator();
for (Long time : copyTimes) {
double t = time / this.factor;
if (size == 1) {
t0 = this.t0;
currentT0 = this.t0;
}
else if (t0 == 0) {
t0 = t;
values.next();
else if (currentT0 == 0) {
currentT0 = t;
valuesIterator.next();
continue;
}
double alpha = Math.exp((t0 - t) * this.lapse);
t0 = t;
sum = alpha * sum + values.next();
double alpha = Math.exp((currentT0 - t) * this.lapse);
currentT0 = t;
sum = alpha * sum + valuesIterator.next();
weight = alpha * weight + 1;
double value = sum / weight;
if (value > max) {
max = value;
if (value > currentMax) {
currentMax = value;
}
if (value < min) {
min = value;
if (value < currentMin) {
currentMin = value;
}
cumulative.append(value);
}
synchronized (this) {
if (max > this.max) {
this.max = max;
if (currentMax > this.max) {
this.max = currentMax;
}
if (min < this.min) {
this.min = min;
if (currentMin < this.min) {
this.min = currentMin;
}
}
return new Statistics(count, min < Double.MAX_VALUE ? min : 0, max, cumulative.getMean(),
return new Statistics(currentCount, currentMin < Double.MAX_VALUE ? currentMin : 0, currentMax, cumulative.getMean(),
cumulative.getStandardDeviation());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -201,15 +201,15 @@ public class ExpressionEvaluatingTransactionSynchronizationProcessor extends Int
*/
private EvaluationContext prepareEvaluationContextToUse(Object resource) {
if (resource != null) {
EvaluationContext evaluationContext = createEvaluationContext();
EvaluationContext evaluationContextWithVariables = createEvaluationContext();
if (resource instanceof IntegrationResourceHolder) {
IntegrationResourceHolder holder = (IntegrationResourceHolder) resource;
for (Entry<String, Object> entry : holder.getAttributes().entrySet()) {
String key = entry.getKey();
evaluationContext.setVariable(key, entry.getValue());
evaluationContextWithVariables.setVariable(key, entry.getValue());
}
}
return evaluationContext;
return evaluationContextWithVariables;
}
else {
return this.evaluationContext;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,14 +77,14 @@ public class RoutingSlipHeaderValueMessageProcessor
@Override
public Map<List<Object>, Integer> processMessage(Message<?> message) {
// use a local variable to avoid the second access to volatile field on the happy path
Map<List<Object>, Integer> routingSlip = this.routingSlip;
if (routingSlip == null) {
Map<List<Object>, Integer> slip = this.routingSlip;
if (slip == null) {
synchronized (this) {
routingSlip = this.routingSlip;
if (routingSlip == null) {
List<Object> routingSlipPath = this.routingSlipPath;
List<Object> routingSlipValues = new ArrayList<Object>(routingSlipPath.size());
for (Object path : routingSlipPath) {
slip = this.routingSlip;
if (slip == null) {
List<Object> slipPath = this.routingSlipPath;
List<Object> routingSlipValues = new ArrayList<Object>(slipPath.size());
for (Object path : slipPath) {
if (path instanceof String) {
String entry = (String) path;
if (this.beanFactory.containsBean(entry)) {
@@ -114,12 +114,12 @@ public class RoutingSlipHeaderValueMessageProcessor
}
}
routingSlip = Collections.singletonMap(Collections.unmodifiableList(routingSlipValues), 0);
this.routingSlip = routingSlip;
slip = Collections.singletonMap(Collections.unmodifiableList(routingSlipValues), 0);
this.routingSlip = slip;
}
}
}
return routingSlip;
return slip;
}
}