Skip to content

Commit 3d24527

Browse files
committed
Fix new Sonar smells
1 parent 4cd1085 commit 3d24527

File tree

7 files changed

+49
-29
lines changed

7 files changed

+49
-29
lines changed

spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected <T> Map<String, T> getBeansOfType(Class<T> type) {
161161
}
162162

163163
private <T extends IntegrationNode> T enhance(T node) {
164-
if (this.micrometerEnhancer != null) {
164+
if (this.micrometerEnhancer != null) { // NOSONAR - synchronized inconsistency
165165
return this.micrometerEnhancer.enhance(node);
166166
}
167167
else {

spring-integration-core/src/main/java/org/springframework/integration/graph/MicrometerNodeEnhancer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private <T extends IntegrationNode> Timer observationTimer(T node, String type,
148148
}
149149

150150
private Search buildTimerSearch(ObservationConvention<?> observationConvention, KeyName tagKey, String tagValue) {
151-
return this.registry.find(observationConvention.getName()).tag(tagKey.asString(), tagValue); // NO SONAR
151+
return this.registry.find(observationConvention.getName()).tag(tagKey.asString(), tagValue); // NOSONAR
152152
}
153153

154154
private <T extends IntegrationNode> void enhanceWithCounts(T node, String type) {

spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/AbstractFtpSessionFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ private void updateClientMode(FTPClient client) {
222222
switch (this.clientMode) {
223223
case FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE -> client.enterLocalActiveMode();
224224
case FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE -> client.enterLocalPassiveMode();
225+
default -> {
226+
throw new IllegalArgumentException("Only 'FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE' " +
227+
"and 'FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE' are supported for 'clientMode'");
228+
}
225229
}
226230
}
227231

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioSSLConnection.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException {
154154
HandshakeStatus handshakeStatus = this.sslEngine.getHandshakeStatus();
155155
SSLEngineResult result = new SSLEngineResult(Status.OK, handshakeStatus, 0, 0);
156156
switch (handshakeStatus) {
157-
case NEED_TASK -> runTasks();
158-
case NEED_UNWRAP, FINISHED, NOT_HANDSHAKING -> result = checkBytesProduced(networkBuffer);
159-
case NEED_WRAP -> result = needWrap(networkBuffer, result);
157+
case NEED_TASK:
158+
runTasks();
159+
break;
160+
case NEED_WRAP:
161+
result = needWrap(networkBuffer, result);
162+
break;
163+
default:
164+
result = checkBytesProduced(networkBuffer);
160165
}
161166

162167
switch (result.getHandshakeStatus()) {
@@ -165,8 +170,8 @@ private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException {
165170
// switch fall-through intended
166171
case NOT_HANDSHAKING:
167172
case NEED_UNWRAP:
168-
this.needMoreNetworkData = result.getStatus() == Status.BUFFER_UNDERFLOW || networkBuffer
169-
.remaining() == 0;
173+
this.needMoreNetworkData =
174+
result.getStatus() == Status.BUFFER_UNDERFLOW || networkBuffer.remaining() == 0;
170175
break;
171176
default:
172177
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,22 @@ protected int readHeader(InputStream inputStream) throws IOException {
244244
if (status < 0) {
245245
throw new SoftEndOfStreamException("Stream closed between payloads");
246246
}
247-
int messageLength;
248247
switch (this.headerSize) {
249-
case HEADER_SIZE_INT -> {
250-
messageLength = ByteBuffer.wrap(lengthPart).getInt();
248+
case HEADER_SIZE_INT:
249+
int messageLength = ByteBuffer.wrap(lengthPart).getInt();
251250
if (messageLength < 0) {
252251
throw new IllegalArgumentException("Length header: "
253252
+ messageLength
254253
+ " is negative");
255254
}
256-
}
257-
case HEADER_SIZE_UNSIGNED_BYTE -> messageLength = ByteBuffer.wrap(lengthPart).get() & MAX_UNSIGNED_BYTE;
258-
case HEADER_SIZE_UNSIGNED_SHORT ->
259-
messageLength = ByteBuffer.wrap(lengthPart).getShort() & MAX_UNSIGNED_SHORT;
260-
default -> throw new IllegalArgumentException("Bad header size: " + this.headerSize);
255+
return messageLength;
256+
case HEADER_SIZE_UNSIGNED_BYTE:
257+
return ByteBuffer.wrap(lengthPart).get() & MAX_UNSIGNED_BYTE;
258+
case HEADER_SIZE_UNSIGNED_SHORT:
259+
return ByteBuffer.wrap(lengthPart).getShort() & MAX_UNSIGNED_SHORT;
260+
default:
261+
throw new IllegalArgumentException("Bad header size: " + this.headerSize);
261262
}
262-
return messageLength;
263263
}
264264
catch (SoftEndOfStreamException e) { // NOSONAR catch and throw
265265
throw e; // it's an IO exception and we don't want an event for this

spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class MockIntegrationContext implements BeanPostProcessor, SmartInitializ
6868

6969
private static final String HANDLER = "handler";
7070

71+
private static final String REACTIVE_MESSAGE_HANDLER = "reactiveMessageHandler";
72+
7173
/**
7274
* The bean name for the mock integration context.
7375
*/
@@ -153,14 +155,13 @@ private void resetBean(Object endpoint, Object handler) {
153155
directFieldAccessor.setPropertyValue("source", handler);
154156
}
155157
else if (endpoint instanceof ReactiveStreamsConsumer) {
156-
if (handler instanceof Tuple2<?, ?>) {
157-
Tuple2<?, ?> value = (Tuple2<?, ?>) handler;
158+
if (handler instanceof Tuple2<?, ?> value) {
158159
directFieldAccessor.setPropertyValue(HANDLER, value.getT1());
159-
directFieldAccessor.setPropertyValue("reactiveMessageHandler", value.getT2());
160+
directFieldAccessor.setPropertyValue(REACTIVE_MESSAGE_HANDLER, value.getT2());
160161
}
161162
else {
162163
directFieldAccessor.setPropertyValue(HANDLER, handler);
163-
directFieldAccessor.setPropertyValue("reactiveMessageHandler", null);
164+
directFieldAccessor.setPropertyValue(REACTIVE_MESSAGE_HANDLER, null);
164165
}
165166
}
166167
else if (endpoint instanceof IntegrationConsumer) {
@@ -214,7 +215,7 @@ public void substituteMessageHandlerFor(String consumerEndpointId, // NOSONAR -
214215
Object targetMessageHandler = directFieldAccessor.getPropertyValue(HANDLER);
215216
Assert.notNull(targetMessageHandler, () -> "'handler' must not be null in the: " + endpoint);
216217
if (endpoint instanceof ReactiveStreamsConsumer) {
217-
Object targetReactiveMessageHandler = directFieldAccessor.getPropertyValue("reactiveMessageHandler");
218+
Object targetReactiveMessageHandler = directFieldAccessor.getPropertyValue(REACTIVE_MESSAGE_HANDLER);
218219
if (targetReactiveMessageHandler != null) {
219220
this.beans.put(consumerEndpointId, Tuples.of(targetMessageHandler, targetReactiveMessageHandler));
220221
}
@@ -250,7 +251,7 @@ public void substituteMessageHandlerFor(String consumerEndpointId, // NOSONAR -
250251
if (endpoint instanceof ReactiveStreamsConsumer) {
251252
ReactiveMessageHandler reactiveMessageHandler =
252253
(message) -> Mono.fromRunnable(() -> mockMessageHandler.handleMessage(message));
253-
directFieldAccessor.setPropertyValue("reactiveMessageHandler", reactiveMessageHandler);
254+
directFieldAccessor.setPropertyValue(REACTIVE_MESSAGE_HANDLER, reactiveMessageHandler);
254255
}
255256

256257
if (autoStartup && endpoint instanceof Lifecycle) {

spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/leader/LeaderInitiator.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2023 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.
@@ -301,17 +301,27 @@ public String getRole() {
301301
* @return the leader.
302302
* @since 6.0.3
303303
*/
304-
public Participant getLeader() throws Exception {
305-
return LeaderInitiator.this.leaderSelector.getLeader();
304+
public Participant getLeader() {
305+
try {
306+
return LeaderInitiator.this.leaderSelector.getLeader();
307+
}
308+
catch (Exception ex) {
309+
throw new IllegalStateException(ex);
310+
}
306311
}
307312

308313
/**
309314
* Get the list of participants
310315
* @return list of participants.
311316
* @since 6.0.3
312317
*/
313-
public Collection<Participant> getParticipants() throws Exception {
314-
return LeaderInitiator.this.leaderSelector.getParticipants();
318+
public Collection<Participant> getParticipants() {
319+
try {
320+
return LeaderInitiator.this.leaderSelector.getParticipants();
321+
}
322+
catch (Exception ex) {
323+
throw new IllegalStateException(ex);
324+
}
315325
}
316326

317327
@Override
@@ -336,12 +346,12 @@ public String getRole() {
336346
}
337347

338348
@Override
339-
public Participant getLeader() throws Exception {
349+
public Participant getLeader() {
340350
return null;
341351
}
342352

343353
@Override
344-
public Collection<Participant> getParticipants() throws Exception {
354+
public Collection<Participant> getParticipants() {
345355
return List.of();
346356
}
347357

0 commit comments

Comments
 (0)