Fix new Sonar smells

This commit is contained in:
abilan
2023-02-14 17:02:23 -05:00
parent 4cd1085f94
commit 3d245276e4
7 changed files with 49 additions and 29 deletions

View File

@@ -161,7 +161,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat
}
private <T extends IntegrationNode> T enhance(T node) {
if (this.micrometerEnhancer != null) {
if (this.micrometerEnhancer != null) { // NOSONAR - synchronized inconsistency
return this.micrometerEnhancer.enhance(node);
}
else {

View File

@@ -148,7 +148,7 @@ public class MicrometerNodeEnhancer {
}
private Search buildTimerSearch(ObservationConvention<?> observationConvention, KeyName tagKey, String tagValue) {
return this.registry.find(observationConvention.getName()).tag(tagKey.asString(), tagValue); // NO SONAR
return this.registry.find(observationConvention.getName()).tag(tagKey.asString(), tagValue); // NOSONAR
}
private <T extends IntegrationNode> void enhanceWithCounts(T node, String type) {

View File

@@ -222,6 +222,10 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
switch (this.clientMode) {
case FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE -> client.enterLocalActiveMode();
case FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE -> client.enterLocalPassiveMode();
default -> {
throw new IllegalArgumentException("Only 'FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE' " +
"and 'FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE' are supported for 'clientMode'");
}
}
}

View File

@@ -154,9 +154,14 @@ public class TcpNioSSLConnection extends TcpNioConnection {
HandshakeStatus handshakeStatus = this.sslEngine.getHandshakeStatus();
SSLEngineResult result = new SSLEngineResult(Status.OK, handshakeStatus, 0, 0);
switch (handshakeStatus) {
case NEED_TASK -> runTasks();
case NEED_UNWRAP, FINISHED, NOT_HANDSHAKING -> result = checkBytesProduced(networkBuffer);
case NEED_WRAP -> result = needWrap(networkBuffer, result);
case NEED_TASK:
runTasks();
break;
case NEED_WRAP:
result = needWrap(networkBuffer, result);
break;
default:
result = checkBytesProduced(networkBuffer);
}
switch (result.getHandshakeStatus()) {
@@ -165,8 +170,8 @@ public class TcpNioSSLConnection extends TcpNioConnection {
// switch fall-through intended
case NOT_HANDSHAKING:
case NEED_UNWRAP:
this.needMoreNetworkData = result.getStatus() == Status.BUFFER_UNDERFLOW || networkBuffer
.remaining() == 0;
this.needMoreNetworkData =
result.getStatus() == Status.BUFFER_UNDERFLOW || networkBuffer.remaining() == 0;
break;
default:
}

View File

@@ -244,22 +244,22 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer
if (status < 0) {
throw new SoftEndOfStreamException("Stream closed between payloads");
}
int messageLength;
switch (this.headerSize) {
case HEADER_SIZE_INT -> {
messageLength = ByteBuffer.wrap(lengthPart).getInt();
case HEADER_SIZE_INT:
int messageLength = ByteBuffer.wrap(lengthPart).getInt();
if (messageLength < 0) {
throw new IllegalArgumentException("Length header: "
+ messageLength
+ " is negative");
}
}
case HEADER_SIZE_UNSIGNED_BYTE -> messageLength = ByteBuffer.wrap(lengthPart).get() & MAX_UNSIGNED_BYTE;
case HEADER_SIZE_UNSIGNED_SHORT ->
messageLength = ByteBuffer.wrap(lengthPart).getShort() & MAX_UNSIGNED_SHORT;
default -> throw new IllegalArgumentException("Bad header size: " + this.headerSize);
return messageLength;
case HEADER_SIZE_UNSIGNED_BYTE:
return ByteBuffer.wrap(lengthPart).get() & MAX_UNSIGNED_BYTE;
case HEADER_SIZE_UNSIGNED_SHORT:
return ByteBuffer.wrap(lengthPart).getShort() & MAX_UNSIGNED_SHORT;
default:
throw new IllegalArgumentException("Bad header size: " + this.headerSize);
}
return messageLength;
}
catch (SoftEndOfStreamException e) { // NOSONAR catch and throw
throw e; // it's an IO exception and we don't want an event for this

View File

@@ -68,6 +68,8 @@ public class MockIntegrationContext implements BeanPostProcessor, SmartInitializ
private static final String HANDLER = "handler";
private static final String REACTIVE_MESSAGE_HANDLER = "reactiveMessageHandler";
/**
* The bean name for the mock integration context.
*/
@@ -153,14 +155,13 @@ public class MockIntegrationContext implements BeanPostProcessor, SmartInitializ
directFieldAccessor.setPropertyValue("source", handler);
}
else if (endpoint instanceof ReactiveStreamsConsumer) {
if (handler instanceof Tuple2<?, ?>) {
Tuple2<?, ?> value = (Tuple2<?, ?>) handler;
if (handler instanceof Tuple2<?, ?> value) {
directFieldAccessor.setPropertyValue(HANDLER, value.getT1());
directFieldAccessor.setPropertyValue("reactiveMessageHandler", value.getT2());
directFieldAccessor.setPropertyValue(REACTIVE_MESSAGE_HANDLER, value.getT2());
}
else {
directFieldAccessor.setPropertyValue(HANDLER, handler);
directFieldAccessor.setPropertyValue("reactiveMessageHandler", null);
directFieldAccessor.setPropertyValue(REACTIVE_MESSAGE_HANDLER, null);
}
}
else if (endpoint instanceof IntegrationConsumer) {
@@ -214,7 +215,7 @@ public class MockIntegrationContext implements BeanPostProcessor, SmartInitializ
Object targetMessageHandler = directFieldAccessor.getPropertyValue(HANDLER);
Assert.notNull(targetMessageHandler, () -> "'handler' must not be null in the: " + endpoint);
if (endpoint instanceof ReactiveStreamsConsumer) {
Object targetReactiveMessageHandler = directFieldAccessor.getPropertyValue("reactiveMessageHandler");
Object targetReactiveMessageHandler = directFieldAccessor.getPropertyValue(REACTIVE_MESSAGE_HANDLER);
if (targetReactiveMessageHandler != null) {
this.beans.put(consumerEndpointId, Tuples.of(targetMessageHandler, targetReactiveMessageHandler));
}
@@ -250,7 +251,7 @@ public class MockIntegrationContext implements BeanPostProcessor, SmartInitializ
if (endpoint instanceof ReactiveStreamsConsumer) {
ReactiveMessageHandler reactiveMessageHandler =
(message) -> Mono.fromRunnable(() -> mockMessageHandler.handleMessage(message));
directFieldAccessor.setPropertyValue("reactiveMessageHandler", reactiveMessageHandler);
directFieldAccessor.setPropertyValue(REACTIVE_MESSAGE_HANDLER, reactiveMessageHandler);
}
if (autoStartup && endpoint instanceof Lifecycle) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2023 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.
@@ -301,8 +301,13 @@ public class LeaderInitiator implements SmartLifecycle {
* @return the leader.
* @since 6.0.3
*/
public Participant getLeader() throws Exception {
return LeaderInitiator.this.leaderSelector.getLeader();
public Participant getLeader() {
try {
return LeaderInitiator.this.leaderSelector.getLeader();
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
/**
@@ -310,8 +315,13 @@ public class LeaderInitiator implements SmartLifecycle {
* @return list of participants.
* @since 6.0.3
*/
public Collection<Participant> getParticipants() throws Exception {
return LeaderInitiator.this.leaderSelector.getParticipants();
public Collection<Participant> getParticipants() {
try {
return LeaderInitiator.this.leaderSelector.getParticipants();
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
@Override
@@ -336,12 +346,12 @@ public class LeaderInitiator implements SmartLifecycle {
}
@Override
public Participant getLeader() throws Exception {
public Participant getLeader() {
return null;
}
@Override
public Collection<Participant> getParticipants() throws Exception {
public Collection<Participant> getParticipants() {
return List.of();
}