diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java index 2ae968f7ad..1cd1ecd56e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java @@ -161,7 +161,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat } private T enhance(T node) { - if (this.micrometerEnhancer != null) { + if (this.micrometerEnhancer != null) { // NOSONAR - synchronized inconsistency return this.micrometerEnhancer.enhance(node); } else { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/MicrometerNodeEnhancer.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/MicrometerNodeEnhancer.java index 4e0a0765b4..acf1c7f2a0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/MicrometerNodeEnhancer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/MicrometerNodeEnhancer.java @@ -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 void enhanceWithCounts(T node, String type) { diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/AbstractFtpSessionFactory.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/AbstractFtpSessionFactory.java index 60b17a72c1..c608b969f7 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/AbstractFtpSessionFactory.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/AbstractFtpSessionFactory.java @@ -222,6 +222,10 @@ public abstract class AbstractFtpSessionFactory 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'"); + } } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioSSLConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioSSLConnection.java index 5c1c61338e..48c36881d9 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioSSLConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioSSLConnection.java @@ -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: } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java index 941f14e4de..7c3f20fb47 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java @@ -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 diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java b/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java index 3723274de1..6273340426 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java @@ -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) { diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/leader/LeaderInitiator.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/leader/LeaderInitiator.java index 9db5c2abc2..8203d525b2 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/leader/LeaderInitiator.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/leader/LeaderInitiator.java @@ -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 getParticipants() throws Exception { - return LeaderInitiator.this.leaderSelector.getParticipants(); + public Collection 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 getParticipants() throws Exception { + public Collection getParticipants() { return List.of(); }