Skip to content

Commit

Permalink
spring-projectsGH-3549: Fix minor SonarQube smells
Browse files Browse the repository at this point in the history
  • Loading branch information
trgpa authored Jul 23, 2021
1 parent bc8246d commit 9e51218
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public String getRole() {
/**
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class DefaultLockRegistry implements LockRegistry {
* mask 0xFF with 256 locks.
*/
public DefaultLockRegistry() {
this(0xFF);
this(0xFF); // NOSONAR magic number
}

/**
Expand All @@ -60,7 +60,7 @@ public DefaultLockRegistry() {
*/
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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -131,7 +131,7 @@ private Object extractObjectToSend(Object root) {
}

private boolean stoppedRecently() {
return this.stoppedAt > System.currentTimeMillis() - 5000;
return this.stoppedAt > System.currentTimeMillis() - 5000; // NOSONAR magic number
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageProducerSupport
implements TailerListener {

private long pollingDelay = 1000;
private long pollingDelay = 1000; // NOSONAR magic number

private boolean end = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public abstract class AbstractInternetProtocolReceivingChannelAdapter

private int soReceiveBufferSize = -1;

private int receiveBufferSize = 2048;
private int receiveBufferSize = 2048; // NOSONAR magic number

private String localAddress;

private Executor taskExecutor;

private boolean taskExecutorSet;

private int poolSize = 5;
private int poolSize = 5; // NOSONAR magic number

private volatile boolean listening;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public synchronized void send(Message<?> message) {
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'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ private HandshakeStatus runTasksIfNeeded(SSLEngineResult result) {
*/
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected byte[] doDeserialize(InputStream inputStream, byte[] buffer) throws IO
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public DatagramPacket fromMessage(Message<?> message) {
}
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);
Expand All @@ -157,7 +157,7 @@ public DatagramPacket fromMessage(Message<?> message) {
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
}
Expand All @@ -177,7 +177,7 @@ private DatagramPacket fromMessageWithAck(Message<?> message) {
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)
Expand Down Expand Up @@ -224,12 +224,12 @@ public Message<byte[]> toMessage(DatagramPacket packet, @Nullable Map<String, Ob
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void run() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public static void waitListening(AbstractServerConnectionFactory serverConnectio

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();
Expand All @@ -81,15 +81,15 @@ public static void waitListening(AbstractInternetProtocolReceivingChannelAdapter

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();
Expand All @@ -114,10 +114,10 @@ public static void waitStopListening(AbstractServerConnectionFactory serverConne

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()) {
Expand All @@ -128,7 +128,7 @@ public static void waitStopListening(AbstractServerConnectionFactory serverConne
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
if (n++ > 200) {
if (n++ > 200) { // NOSONAR magic number
throw new IllegalStateException("Server didn't stop listening.");
}
}
Expand All @@ -146,12 +146,12 @@ public static void waitUntilFactoryHasThisNumberOfConnections(AbstractConnection
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ private int tryToPutIfAbsent(String key, String value) {
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) {
Expand All @@ -188,8 +188,8 @@ public boolean replace(String key, String oldValue, String newValue) {
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;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public void put(String key, String value) {
ps -> {
ps.setString(1, value);
ps.setString(2, key);
ps.setString(3, this.region);
ps.setString(3, this.region); // NOSONAR magic number
});
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,21 @@ public void setValues(PreparedStatement preparedStatement, Message<?> requestMes

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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int getPriority() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public MessageGroup addMessageToGroup(Object groupId, Message<?> message) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public int hashCode() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SftpPersistentAcceptOnceFileListFilter(ConcurrentMetadataStore store, Str

@Override
protected long modified(LsEntry file) {
return ((long) file.getAttrs().getMTime()) * 1000;
return ((long) file.getAttrs().getMTime()) * 1000; // NOSONAR magic number
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected List<AbstractFileInfo<LsEntry>> asFileInfoList(Collection<LsEntry> fil

@Override
protected long getModified(LsEntry file) {
return ((long) file.getAttrs().getMTime()) * 1000;
return ((long) file.getAttrs().getMTime()) * 1000; // NOSONAR magic number
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected String getFilename(LsEntry file) {

@Override
protected long getModified(LsEntry file) {
return (long) file.getAttrs().getMTime() * 1000;
return (long) file.getAttrs().getMTime() * 1000; // NOSONAR magic number
}

@Override
Expand Down
Loading

0 comments on commit 9e51218

Please sign in to comment.