From 869c5c7088910e097d4425496f38991adc35e811 Mon Sep 17 00:00:00 2001 From: abilan Date: Sat, 15 Apr 2023 20:00:38 -0400 Subject: [PATCH] Fix new Sonar smells --- .../dsl/BaseIntegrationFlowDefinition.java | 10 ++--- .../integration/dsl/EndpointSpec.java | 6 ++- .../integration/dsl/HeaderEnricherSpec.java | 38 ++++++++-------- .../dsl/RecipientListRouterSpec.java | 45 +++++++++++-------- .../dsl/StandardIntegrationFlow.java | 18 +++----- .../dsl/KotlinRecipientListRouterSpec.kt | 18 +++----- .../GroovyIntegrationFlowDefinition.groovy | 4 +- 7 files changed, 69 insertions(+), 70 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java index 21be9fac73..f623d4c423 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java @@ -450,7 +450,7 @@ public abstract class BaseIntegrationFlowDefinition wireTapConfigurer) { + public B wireTap(String wireTapChannel, @Nullable Consumer wireTapConfigurer) { DirectChannel internalWireTapChannel = new DirectChannel(); addComponent(IntegrationFlow.from(internalWireTapChannel).channel(wireTapChannel).get()); return wireTap(internalWireTapChannel, wireTapConfigurer); @@ -639,7 +639,7 @@ public abstract class BaseIntegrationFlowDefinition messageProcessorSpec, - Consumer> endpointConfigurer) { + @Nullable Consumer> endpointConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.getObject(); @@ -1087,7 +1087,7 @@ public abstract class BaseIntegrationFlowDefinition messageProcessorSpec, - Consumer> endpointConfigurer) { + @Nullable Consumer> endpointConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.getObject(); @@ -2362,7 +2362,7 @@ public abstract class BaseIntegrationFlowDefinition B log(LoggingHandler.Level level, String category, Function, Object> function) { + public

B log(LoggingHandler.Level level, @Nullable String category, Function, Object> function) { Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL); return log(level, category, new FunctionExpression<>(function)); } @@ -2650,7 +2650,7 @@ public abstract class BaseIntegrationFlowDefinition IntegrationFlow logAndReply(LoggingHandler.Level level, String category, + public

IntegrationFlow logAndReply(LoggingHandler.Level level, @Nullable String category, Function, Object> function) { Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java index 742c78a5f9..ab52cc100b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java @@ -61,8 +61,10 @@ public abstract class EndpointSpec, F extends Be } @Override - public S id(String id) { - this.endpointFactoryBean.setBeanName(id); + public S id(@Nullable String id) { + if (id != null) { + this.endpointFactoryBean.setBeanName(id); + } return super.id(id); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java index 240286afc8..55a7846546 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java @@ -216,7 +216,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec headers, Boolean overwrite) { + public HeaderEnricherSpec headerExpressions(MapBuilder headers, @Nullable Boolean overwrite) { Assert.notNull(headers, HEADERS_MUST_NOT_BE_NULL); return headerExpressions(headers.get(), overwrite); } @@ -285,7 +285,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec headers, Boolean overwrite) { + public HeaderEnricherSpec headerExpressions(Map headers, @Nullable Boolean overwrite) { Assert.notNull(headers, HEADERS_MUST_NOT_BE_NULL); for (Entry entry : headers.entrySet()) { AbstractHeaderValueMessageProcessor processor = @@ -314,7 +314,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec HeaderEnricherSpec correlationIdFunction(Function, ?> correlationIdFunction, - Boolean overwrite) { + @Nullable Boolean overwrite) { return headerFunction(IntegrationMessageHeaderAccessor.CORRELATION_ID, correlationIdFunction, overwrite); } @@ -394,7 +394,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec HeaderEnricherSpec replyChannelFunction(Function, ?> replyChannelFunction, - Boolean overwrite) { + @Nullable Boolean overwrite) { return headerFunction(MessageHeaders.REPLY_CHANNEL, replyChannelFunction, overwrite); } @@ -472,7 +472,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec HeaderEnricherSpec errorChannelFunction(Function, ?> errorChannelFunction, - Boolean overwrite) { + @Nullable Boolean overwrite) { return headerFunction(MessageHeaders.ERROR_CHANNEL, errorChannelFunction, overwrite); } @@ -550,7 +550,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec HeaderEnricherSpec priorityFunction(Function, ?> priorityFunction, Boolean overwrite) { + public

HeaderEnricherSpec priorityFunction(Function, ?> priorityFunction, + @Nullable Boolean overwrite) { + return headerFunction(IntegrationMessageHeaderAccessor.PRIORITY, priorityFunction, overwrite); } @@ -626,7 +628,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec HeaderEnricherSpec expirationDateFunction(Function, ?> expirationDateFunction, - Boolean overwrite) { + @Nullable Boolean overwrite) { return headerFunction(IntegrationMessageHeaderAccessor.EXPIRATION_DATE, expirationDateFunction, overwrite); } @@ -726,7 +728,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec RecipientListRouterSpec recipient(MessageChannel channel, GenericSelector

selector) { MessageSelector messageSelector = wrapToMessageSelectorIfNecessary(selector); this.handler.addRecipient(channel, messageSelector); - return _this(); + return this; } /** @@ -212,7 +213,13 @@ public class RecipientListRouterSpec extends AbstractRouterSpec iterator = components.listIterator(this.integrationComponents.size()); while (iterator.hasPrevious()) { Object component = iterator.previous(); - if (component instanceof SmartLifecycle) { - ((SmartLifecycle) component).start(); + if (component instanceof SmartLifecycle lifecycle) { + lifecycle.start(); } } this.running = true; @@ -148,11 +148,9 @@ public class StandardIntegrationFlow public void stop(Runnable callback) { AggregatingCallback aggregatingCallback = new AggregatingCallback(this.integrationComponents.size(), callback); for (Object component : this.integrationComponents.keySet()) { - if (component instanceof SmartLifecycle lifecycle) { - if (lifecycle.isRunning()) { - lifecycle.stop(aggregatingCallback); - continue; - } + if (component instanceof SmartLifecycle lifecycle && lifecycle.isRunning()) { + lifecycle.stop(aggregatingCallback); + continue; } aggregatingCallback.run(); } @@ -162,10 +160,8 @@ public class StandardIntegrationFlow @Override public void stop() { for (Object component : this.integrationComponents.keySet()) { - if (component instanceof SmartLifecycle lifecycle) { - if (lifecycle.isRunning()) { - lifecycle.stop(); - } + if (component instanceof SmartLifecycle lifecycle && lifecycle.isRunning()) { + lifecycle.stop(); } } this.running = false; diff --git a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRecipientListRouterSpec.kt b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRecipientListRouterSpec.kt index c9312c817f..308a0c0cf8 100644 --- a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRecipientListRouterSpec.kt +++ b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRecipientListRouterSpec.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-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. @@ -35,11 +35,7 @@ import org.springframework.messaging.MessageChannel class KotlinRecipientListRouterSpec(override val delegate: RecipientListRouterSpec) : AbstractKotlinRouterSpec(delegate) { - fun recipient(channelName: String) { - this.delegate.recipient(channelName) - } - - fun recipient(channelName: String, expression: String) { + fun recipient(channelName: String, expression: String? = null) { this.delegate.recipient(channelName, expression) } @@ -54,11 +50,7 @@ class KotlinRecipientListRouterSpec(override val delegate: RecipientListRouterSp this.delegate.recipient

(channelName) { selector(it) } } - fun recipient(channel: MessageChannel) { - this.delegate.recipient(channel) - } - - fun recipient(channel: MessageChannel, expression: String) { + fun recipient(channel: MessageChannel, expression: String? = null) { this.delegate.recipient(channel, expression) } @@ -68,9 +60,9 @@ class KotlinRecipientListRouterSpec(override val delegate: RecipientListRouterSp inline fun recipient(channel: MessageChannel, crossinline selector: (P) -> Boolean) { if (Message::class.java.isAssignableFrom(P::class.java)) - this.delegate.recipientMessageSelector(channel, MessageSelector { selector(it as P) }) + this.delegate.recipientMessageSelector(channel) { selector(it as P) } else - this.delegate.recipient

(channel, GenericSelector { selector(it) }) + this.delegate.recipient

(channel) { selector(it) } } inline fun recipientFlow(crossinline selector: (P) -> Boolean, diff --git a/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy b/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy index 262d466d07..b8187380a2 100644 --- a/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy +++ b/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-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. @@ -126,7 +126,7 @@ class GroovyIntegrationFlowDefinition { * at the current {@link IntegrationFlow} chain position using the {@link MessageChannelSpec} * fluent API. * @param messageChannelSpec the {@link MessageChannelSpec} to use. - * @see MessageChannels + * @see org.springframework.integration.dsl.MessageChannels */ GroovyIntegrationFlowDefinition channel(MessageChannelSpec messageChannelSpec) { this.delegate.channel messageChannelSpec