GH-3549: Fix minor SonarQube smells

Fixes https://github.com/spring-projects/spring-integration/issues/3549
This commit is contained in:
trungPa
2021-07-23 22:07:39 +07:00
committed by GitHub
parent bc8246d267
commit 9e512186ed
33 changed files with 77 additions and 77 deletions

View File

@@ -140,7 +140,7 @@ public class LockRegistryLeaderInitiator implements SmartLifecycle, DisposableBe
/**
* @see SmartLifecycle which is an extension of org.springframework.context.Phased
*/
private int phase = Integer.MAX_VALUE - 1000;
private int phase = Integer.MAX_VALUE - 1000; // NOSONAR magic number
/**
* Time in milliseconds to wait in between attempts to acquire the lock, if it is not

View File

@@ -44,7 +44,7 @@ public final class DefaultLockRegistry implements LockRegistry {
* mask 0xFF with 256 locks.
*/
public DefaultLockRegistry() {
this(0xFF);
this(0xFF); // NOSONAR magic number
}
/**
@@ -60,7 +60,7 @@ public final class DefaultLockRegistry implements LockRegistry {
*/
public DefaultLockRegistry(int mask) {
String bits = Integer.toBinaryString(mask);
Assert.isTrue(bits.length() < 32 && (mask == 0 || bits.lastIndexOf('0') < bits.indexOf('1')), "Mask must be a power of 2 - 1");
Assert.isTrue(bits.length() < 32 && (mask == 0 || bits.lastIndexOf('0') < bits.indexOf('1')), "Mask must be a power of 2 - 1"); // NOSONAR magic number
this.mask = mask;
int arraySize = this.mask + 1;
this.lockTable = new ReentrantLock[arraySize];

View File

@@ -55,7 +55,7 @@ public class ApplicationEventListeningMessageProducer extends ExpressionMessageP
private volatile long stoppedAt;
public ApplicationEventListeningMessageProducer() {
setPhase(Integer.MAX_VALUE / 2 - 1000);
setPhase(Integer.MAX_VALUE / 2 - 1000); // NOSONAR magic number
}
/**
@@ -131,7 +131,7 @@ public class ApplicationEventListeningMessageProducer extends ExpressionMessageP
}
private boolean stoppedRecently() {
return this.stoppedAt > System.currentTimeMillis() - 5000;
return this.stoppedAt > System.currentTimeMillis() - 5000; // NOSONAR magic number
}
@Override

View File

@@ -31,7 +31,7 @@ import org.apache.commons.io.input.TailerListener;
public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageProducerSupport
implements TailerListener {
private long pollingDelay = 1000;
private long pollingDelay = 1000; // NOSONAR magic number
private boolean end = true;

View File

@@ -52,7 +52,7 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
private int port = FTP.DEFAULT_PORT;
private int bufferSize = 2048; //see https://issues.apache.org/jira/browse/NET-207
private int bufferSize = 2048; // NOSONAR magic number. See https://issues.apache.org/jira/browse/NET-207
private int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE;

View File

@@ -44,7 +44,7 @@ public class CrossOrigin {
private Boolean allowCredentials = true;
private long maxAge = 1800;
private long maxAge = 1800; // NOSONAR magic number
public void setOrigin(String... origin) {
this.origin = Arrays.copyOf(origin, origin.length);

View File

@@ -47,7 +47,7 @@ public abstract class AbstractInternetProtocolReceivingChannelAdapter
private int soReceiveBufferSize = -1;
private int receiveBufferSize = 2048;
private int receiveBufferSize = 2048; // NOSONAR magic number
private String localAddress;
@@ -55,7 +55,7 @@ public abstract class AbstractInternetProtocolReceivingChannelAdapter
private boolean taskExecutorSet;
private int poolSize = 5;
private int poolSize = 5; // NOSONAR magic number
private volatile boolean listening;

View File

@@ -96,7 +96,7 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<Abstrac
private boolean singleUse;
private int backlog = 5;
private int backlog = 5; // NOSONAR magic number
private TcpConnectionInterceptorFactoryChain interceptorFactoryChain;

View File

@@ -82,7 +82,7 @@ public class TcpOutboundGateway extends AbstractReplyProducingMessageHandler
private Expression remoteTimeoutExpression = new ValueExpression<>(DEFAULT_REMOTE_TIMEOUT);
private long requestTimeout = 10000;
private long requestTimeout = 10000; // NOSONAR magic number
private EvaluationContext evaluationContext = new StandardEvaluationContext();

View File

@@ -57,7 +57,7 @@ public class TcpReceivingChannelAdapter
private volatile boolean isClientMode;
private volatile long retryInterval = 60000;
private volatile long retryInterval = 60000; // NOSONAR magic number
private volatile ScheduledFuture<?> scheduledFuture;

View File

@@ -107,7 +107,7 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling
if (this.socketOutputStream == null) {
int writeBufferSize = this.socket.getSendBufferSize();
this.socketOutputStream = new BufferedOutputStream(this.socket.getOutputStream(),
writeBufferSize > 0 ? writeBufferSize : 8192);
writeBufferSize > 0 ? writeBufferSize : 8192); // NOSONAR magic number
}
Object object = getMapper().fromMessage(message);
Assert.state(object != null, "Mapper mapped the message to 'null'.");

View File

@@ -271,8 +271,8 @@ public class TcpNioSSLConnection extends TcpNioConnection {
*/
public void init() {
if (this.decoded == null) {
this.decoded = allocateEncryptionBuffer(2048);
this.encoded = allocateEncryptionBuffer(2048);
this.decoded = allocateEncryptionBuffer(2048); // NOSONAR magic number
this.encoded = allocateEncryptionBuffer(2048); // NOSONAR magic number
initializeEngine();
}
}

View File

@@ -63,7 +63,7 @@ public class ByteArraySingleTerminatorSerializer extends AbstractPooledBufferByt
buffer[n++] = (byte) bite;
int maxMessageSize = getMaxMessageSize();
if (n >= maxMessageSize) {
throw new IOException("Terminator '0x" + Integer.toHexString(this.terminator & 0xff)
throw new IOException("Terminator '0x" + Integer.toHexString(this.terminator & 0xff) // NOSONAR magic number
+ "' not found before max message length: "
+ maxMessageSize);
}

View File

@@ -141,7 +141,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
}
byte[] bytes = getPayloadAsBytes(message);
if (this.lengthCheck) {
ByteBuffer buffer = ByteBuffer.allocate(bytes.length + 4);
ByteBuffer buffer = ByteBuffer.allocate(bytes.length + 4); // NOSONAR magic number
// insert the length (not including the length bytes)
// default ByteOrder is ByteOrder.BIG_ENDIAN (network byte order)
buffer.putInt(bytes.length);
@@ -157,7 +157,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
private DatagramPacket fromMessageWithAck(Message<?> message) {
Assert.state(StringUtils.hasText(this.ackAddress), "'ackAddress' must not be empty");
byte[] bytes = getPayloadAsBytes(message);
ByteBuffer buffer = ByteBuffer.allocate(100 + bytes.length);
ByteBuffer buffer = ByteBuffer.allocate(100 + bytes.length); // NOSONAR magic number
if (this.lengthCheck) {
buffer.putInt(0); // placeholder for length
}
@@ -177,7 +177,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
catch (UnsupportedEncodingException e) {
throw new MessagingException(message, "Failed to get headers", e);
}
int headersLength = buffer.position() - 4;
int headersLength = buffer.position() - 4; // NOSONAR magic number
buffer.put(bytes);
if (this.lengthCheck) {
// insert the length (not including the length bytes)
@@ -224,12 +224,12 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
Message<byte[]> message = null;
if (this.lengthCheck) {
int declaredLength = buffer.getInt();
if (declaredLength != (length - 4)) {
throw new MessageMappingException("Incorrect length; expected " + (declaredLength + 4)
if (declaredLength != (length - 4)) { // NOSONAR magic number
throw new MessageMappingException("Incorrect length; expected " + (declaredLength + 4) // NOSONAR magic number
+ ", received " + length);
}
offset += 4;
length -= 4;
offset += 4; // NOSONAR magic number
length -= 4; // NOSONAR magic number
}
String hostAddress = packet.getAddress().getHostAddress();
String hostName;

View File

@@ -518,7 +518,7 @@ public class UnicastSendingMessageHandler extends
try {
this.ackThreadRunning = true;
this.ackLatch.countDown();
DatagramPacket ackPack = new DatagramPacket(new byte[100], 100);
DatagramPacket ackPack = new DatagramPacket(new byte[100], 100); // NOSONAR magic number
while (true) {
getSocket().receive(ackPack);
String id = new String(ackPack.getData(), ackPack.getOffset(), ackPack.getLength());

View File

@@ -48,15 +48,15 @@ public final class TestingUtilities {
Long delay = delayArg;
if (delay == null) {
delay = 100L;
delay = 100L; // NOSONAR magic number
}
else {
delay = delay / 100;
delay = delay / 100; // NOSONAR magic number
}
int n = 0;
while (!serverConnectionFactory.isListening()) {
try {
Thread.sleep(100);
Thread.sleep(100); // NOSONAR magic number
}
catch (InterruptedException e1) {
Thread.currentThread().interrupt();
@@ -81,15 +81,15 @@ public final class TestingUtilities {
Long delay = delayArg;
if (delay == null) {
delay = 100L;
delay = 100L; // NOSONAR magic number
}
else {
delay = delay / 100;
delay = delay / 100; // NOSONAR magic number
}
int n = 0;
while (!adapter.isListening()) {
try {
Thread.sleep(100);
Thread.sleep(100); // NOSONAR magic number
}
catch (InterruptedException e1) {
Thread.currentThread().interrupt();
@@ -114,10 +114,10 @@ public final class TestingUtilities {
Long delay = delayArg;
if (delay == null) {
delay = 100L;
delay = 100L; // NOSONAR magic number
}
else {
delay = delay / 100;
delay = delay / 100; // NOSONAR magic number
}
int n = 0;
while (serverConnectionFactory.isListening()) {
@@ -128,7 +128,7 @@ public final class TestingUtilities {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
if (n++ > 200) {
if (n++ > 200) { // NOSONAR magic number
throw new IllegalStateException("Server didn't stop listening.");
}
}
@@ -146,12 +146,12 @@ public final class TestingUtilities {
throws InterruptedException {
int timer = 0;
while (timer < 10000) {
while (timer < 10000) { // NOSONAR magic number
if (factory.getOpenConnectionIds().size() == n) {
return;
}
Thread.sleep(100);
timer += 100;
Thread.sleep(100); // NOSONAR magic number
timer += 100; // NOSONAR magic number
}
throw new IllegalStateException("Connections=" + factory.getOpenConnectionIds().size() + "wanted=" + n);
}

View File

@@ -168,9 +168,9 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB
ps -> {
ps.setString(1, key);
ps.setString(2, value);
ps.setString(3, this.region);
ps.setString(4, key);
ps.setString(5, this.region);
ps.setString(3, this.region); // NOSONAR magic number
ps.setString(4, key); // NOSONAR magic number
ps.setString(5, this.region); // NOSONAR magic number
});
}
catch (DuplicateKeyException ex) {
@@ -188,8 +188,8 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB
ps -> {
ps.setString(1, newValue);
ps.setString(2, key);
ps.setString(3, oldValue);
ps.setString(4, this.region);
ps.setString(3, oldValue); // NOSONAR magic number
ps.setString(4, this.region); // NOSONAR magic number
});
return affectedRows > 0;
}
@@ -217,7 +217,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB
ps -> {
ps.setString(1, value);
ps.setString(2, key);
ps.setString(3, this.region);
ps.setString(3, this.region); // NOSONAR magic number
});
}
return;

View File

@@ -112,21 +112,21 @@ public class ChannelMessageStorePreparedStatementSetter {
preparedStatement.setString(1, messageId);
preparedStatement.setString(2, groupKey);
preparedStatement.setString(3, region);
preparedStatement.setLong(4, createdDate);
preparedStatement.setString(3, region); // NOSONAR magic number
preparedStatement.setLong(4, createdDate); // NOSONAR magic number
Integer priority = requestMessage.getHeaders().get(IntegrationMessageHeaderAccessor.PRIORITY, Integer.class);
if (priorityEnabled && priority != null) {
preparedStatement.setInt(5, priority);
preparedStatement.setInt(5, priority); // NOSONAR magic number
}
else {
preparedStatement.setNull(5, Types.NUMERIC);
preparedStatement.setNull(5, Types.NUMERIC); // NOSONAR magic number
}
if (this.serializer != null) {
byte[] messageBytes = this.serializer.convert(requestMessage);
this.lobHandler.getLobCreator().setBlobAsBytes(preparedStatement, 6, messageBytes);
this.lobHandler.getLobCreator().setBlobAsBytes(preparedStatement, 6, messageBytes); // NOSONAR magic number
}
}

View File

@@ -61,7 +61,7 @@ public class DynamicJmsTemplate extends JmsTemplate {
if (priority == null) {
return super.getPriority();
}
Assert.isTrue(priority >= 0 && priority <= 9, "JMS priority must be in the range of 0-9");
Assert.isTrue(priority >= 0 && priority <= 9, "JMS priority must be in the range of 0-9"); // NOSONAR magic number
return priority;
}

View File

@@ -93,7 +93,7 @@ public class RedisChannelPriorityMessageStore extends RedisChannelMessageStore
Assert.isInstanceOf(String.class, groupId);
String key = (String) groupId;
Integer priority = new IntegrationMessageHeaderAccessor(message).getPriority();
if (priority != null && priority < 10 && priority >= 0) {
if (priority != null && priority < 10 && priority >= 0) { // NOSONAR magic number
key = key + ":" + priority;
}
return super.addMessageToGroup(key, message);

View File

@@ -374,7 +374,7 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + ((this.lockKey == null) ? 0 : this.lockKey.hashCode());
result = prime * result + (int) (this.lockedAt ^ (this.lockedAt >>> 32));
result = prime * result + (int) (this.lockedAt ^ (this.lockedAt >>> 32)); // NOSONAR magic number
result = prime * result + RedisLockRegistry.this.clientId.hashCode();
return result;
}

View File

@@ -39,7 +39,7 @@ public class SftpPersistentAcceptOnceFileListFilter extends AbstractPersistentAc
@Override
protected long modified(LsEntry file) {
return ((long) file.getAttrs().getMTime()) * 1000;
return ((long) file.getAttrs().getMTime()) * 1000; // NOSONAR magic number
}
@Override

View File

@@ -133,7 +133,7 @@ public class SftpOutboundGateway extends AbstractRemoteFileOutboundGateway<LsEnt
@Override
protected long getModified(LsEntry file) {
return ((long) file.getAttrs().getMTime()) * 1000;
return ((long) file.getAttrs().getMTime()) * 1000; // NOSONAR magic number
}
@Override

View File

@@ -56,7 +56,7 @@ public class SftpInboundFileSynchronizer extends AbstractInboundFileSynchronizer
@Override
protected long getModified(LsEntry file) {
return (long) file.getAttrs().getMTime() * 1000;
return (long) file.getAttrs().getMTime() * 1000; // NOSONAR magic number
}
@Override

View File

@@ -76,7 +76,7 @@ public class DefaultSftpSessionFactory implements SessionFactory<LsEntry>, Share
private String host;
private int port = 22; // the default
private int port = 22; // NOSONAR magic number. The default
private String user;
@@ -419,7 +419,7 @@ public class DefaultSftpSessionFactory implements SessionFactory<LsEntry>, Share
"either a password or a private key is required");
if (this.port <= 0) {
this.port = 22;
this.port = 22; // NOSONAR magic number
}
if (this.knownHosts != null) {
this.jsch.setKnownHosts(this.knownHosts.getInputStream());

View File

@@ -70,7 +70,7 @@ public class SftpFileInfo extends AbstractFileInfo<LsEntry> {
*/
@Override
public long getModified() {
return ((long) this.attrs.getMTime()) * 1000;
return ((long) this.attrs.getMTime()) * 1000; // NOSONAR magic number
}
/**

View File

@@ -33,7 +33,7 @@ public class ByteStreamReadingMessageSource extends AbstractMessageSource<byte[]
private final BufferedInputStream stream;
private int bytesPerMessage = 1024;
private int bytesPerMessage = 1024; // NOSONAR magic number
private boolean shouldTruncate = true;

View File

@@ -99,8 +99,8 @@ public class RFC5424SyslogParser {
message = "";
}
int severity = pri & 0x7;
int facility = pri >> 3;
int severity = pri & 0x7; // NOSONAR magic number
int facility = pri >> 3; // NOSONAR magic number
map.put(SyslogHeaders.FACILITY, facility);
map.put(SyslogHeaders.SEVERITY, severity);
map.put(SyslogHeaders.SEVERITY_TEXT, Severity.parseInt(severity).label());
@@ -239,7 +239,7 @@ public class RFC5424SyslogParser {
public int readInt() {
int val = 0;
while (isDigit()) {
val = (val * 10) + getInt();
val = (val * 10) + getInt(); // NOSONAR magic number
}
return val;
}
@@ -248,8 +248,8 @@ public class RFC5424SyslogParser {
int val = 0;
int order = 0;
while (isDigit()) {
val = (val * 10) + getInt();
order *= 10;
val = (val * 10) + getInt(); // NOSONAR magic number
order *= 10; // NOSONAR magic number
}
return (double) val / order;
@@ -289,7 +289,7 @@ public class RFC5424SyslogParser {
int c;
while (true) {
c = getc();
if (c >= 33 && c <= 127) {
if (c >= 33 && c <= 127) { // NOSONAR magic number
sb.append((char) c);
}
else {
@@ -339,19 +339,19 @@ public class RFC5424SyslogParser {
}
public static Severity parseInt(int syslogSeverity) {
if (syslogSeverity == 7) {
if (syslogSeverity == 7) { // NOSONAR magic number
return DEBUG;
}
if (syslogSeverity == 6) {
if (syslogSeverity == 6) { // NOSONAR magic number
return INFO;
}
if (syslogSeverity == 5) {
if (syslogSeverity == 5) { // NOSONAR magic number
return NOTICE;
}
if (syslogSeverity == 4) {
if (syslogSeverity == 4) { // NOSONAR magic number
return WARN;
}
if (syslogSeverity == 3) {
if (syslogSeverity == 3) { // NOSONAR magic number
return ERROR;
}
if (syslogSeverity == 2) {

View File

@@ -101,14 +101,14 @@ public class RFC6587SyslogDeserializer implements Deserializer<Map<String, ?>> {
}
private boolean isDigit(int peek) {
return peek >= 0x30 && peek <= 0x39;
return peek >= 0x30 && peek <= 0x39; // NOSONAR magic number
}
private int calculateLength(DataInputStream stream, int peek) throws IOException {
int length = peek & 0xf;
int length = peek & 0xf; // NOSONAR magic number
int c = stream.read();
while (isDigit(c)) {
length = length * 10 + (c & 0xf);
length = length * 10 + (c & 0xf); // NOSONAR magic number
c = stream.read();
}
return length;

View File

@@ -83,7 +83,7 @@ public abstract class AbstractRequestResponseScenarioTests {
.as(name + ": message not sent on " + scenario.getInputChannelName()).isTrue();
if (outputChannel instanceof PollableChannel) {
Message<?> response = ((PollableChannel) outputChannel).receive(10000);
Message<?> response = ((PollableChannel) outputChannel).receive(10000); // NOSONAR magic number
assertThat(response).as(name + ": receive timeout on " + scenario.getOutputChannelName()).isNotNull();
scenario.getResponseValidator().handleMessage(response);
}

View File

@@ -61,7 +61,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
private String host;
private int port = 5222;
private int port = 5222; // NOSONAR magic number
private Roster.SubscriptionMode subscriptionMode = Roster.getDefaultSubscriptionMode();

View File

@@ -48,7 +48,7 @@ public class CuratorFrameworkFactoryBean implements FactoryBean<CuratorFramework
/**
* @see SmartLifecycle
*/
private int phase = Integer.MIN_VALUE + 1000;
private int phase = Integer.MIN_VALUE + 1000; // NOSONAR magic number
/**
* @see SmartLifecycle
@@ -62,7 +62,7 @@ public class CuratorFrameworkFactoryBean implements FactoryBean<CuratorFramework
* @param connectionString list of servers to connect to
*/
public CuratorFrameworkFactoryBean(String connectionString) {
this(connectionString, new ExponentialBackoffRetry(1000, 3));
this(connectionString, new ExponentialBackoffRetry(1000, 3)); // NOSONAR magic number
}
/**

View File

@@ -53,7 +53,7 @@ public class LeaderInitiatorFactoryBean
private boolean autoStartup = true;
private int phase = Integer.MAX_VALUE - 1000;
private int phase = Integer.MAX_VALUE - 1000; // NOSONAR magic number
private ApplicationEventPublisher applicationEventPublisher;