From ece0216bfe9be10c81bb65fc57e8a957638c14a5 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 29 Jan 2021 18:11:17 -0500 Subject: [PATCH] Fix new Sonar smells --- .../channel/AbstractExecutorChannel.java | 12 ++++++------ .../gateway/GatewayProxyFactoryBean.java | 13 ++++++++----- .../integration/jpa/core/JpaExecutor.java | 9 +++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java index a3e4f4e806..e79542f4e6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2015-2021 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. @@ -190,8 +190,8 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne theMessage = executorInterceptor.beforeHandle(theMessage, AbstractExecutorChannel.this, this.delegate.getMessageHandler()); if (theMessage == null) { - if (isLoggingEnabled() && logger.isDebugEnabled()) { - logger.debug(executorInterceptor.getClass().getSimpleName() + if (isLoggingEnabled()) { + logger.debug(() -> executorInterceptor.getClass().getSimpleName() + " returned null from beforeHandle, i.e. precluding the send."); } triggerAfterMessageHandled(null, null, interceptorStack); @@ -203,13 +203,13 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne return theMessage; } - private void triggerAfterMessageHandled(Message message, Exception ex, - Deque interceptorStack) { + private void triggerAfterMessageHandled(@Nullable Message message, @Nullable Exception ex, + Deque interceptorStack) { Iterator iterator = interceptorStack.descendingIterator(); while (iterator.hasNext()) { ExecutorChannelInterceptor interceptor = iterator.next(); try { - interceptor.afterMessageHandled(message, AbstractExecutorChannel.this, + interceptor.afterMessageHandled(message, AbstractExecutorChannel.this, //NOSONAR this.delegate.getMessageHandler(), ex); } catch (Throwable ex2) { //NOSONAR diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index d0b346d7a8..2a3fea2c73 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -510,11 +510,14 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint @Override @Nullable public Object invoke(final MethodInvocation invocation) throws Throwable { // NOSONAR - Class returnType = invocation.getMethod().getReturnType(); + final Class returnType; MethodInvocationGateway gateway = this.gatewayMap.get(invocation.getMethod()); if (gateway != null) { returnType = gateway.returnType; } + else { + returnType = invocation.getMethod().getReturnType(); + } if (this.asyncExecutor != null && !Object.class.equals(returnType)) { Invoker invoker = new Invoker(invocation); if (returnType.isAssignableFrom(this.asyncSubmitType)) { @@ -526,8 +529,8 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint else if (CompletableFuture.class.equals(returnType)) { // exact return CompletableFuture.supplyAsync(invoker, this.asyncExecutor); } - else if (Future.class.isAssignableFrom(returnType) && logger.isDebugEnabled()) { - logger.debug("AsyncTaskExecutor submit*() return types are incompatible with the method return " + + else if (Future.class.isAssignableFrom(returnType)) { + logger.debug(() -> "AsyncTaskExecutor submit*() return types are incompatible with the method return " + "type; running on calling thread; the downstream flow must return the required Future: " + returnType.getSimpleName()); } @@ -997,7 +1000,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint } } - private void setChannel(String channelName1, String channelName2, Consumer channelNameMethod, + private void setChannel(@Nullable String channelName1, String channelName2, Consumer channelNameMethod, MessageChannel channel, Consumer channelMethod) { if (StringUtils.hasText(channelName1)) { diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java index e123bf2d39..0030543cb8 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -29,6 +29,7 @@ import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; import org.springframework.integration.expression.ExpressionUtils; +import org.springframework.integration.expression.ValueExpression; import org.springframework.integration.jpa.support.JpaParameter; import org.springframework.integration.jpa.support.PersistMode; import org.springframework.integration.jpa.support.parametersource.BeanPropertyParameterSourceFactory; @@ -163,7 +164,7 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { } /** - * Sets the class type which is being used for retrieving entities from the + * Set the class type which is being used for retrieving entities from the * database. * @param entityClass Must not be null. */ @@ -359,7 +360,7 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { * @see javax.persistence.Query#setMaxResults(int) */ public void setMaxNumberOfResults(int maxNumberOfResults) { - this.setMaxResultsExpression(new LiteralExpression("" + maxNumberOfResults)); + this.setMaxResultsExpression(new ValueExpression<>(maxNumberOfResults)); } @Override @@ -537,7 +538,7 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { return payload; } - private void checkDelete(final Object payload) { + private void checkDelete(@Nullable Object payload) { if (payload != null && this.deleteAfterPoll) { if (payload instanceof Iterable) { if (this.deleteInBatch) {