From 1e507073709275ae15953d26b2eddf6c5a77fd3a Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 17 Oct 2019 10:09:55 -0400 Subject: [PATCH] Fix new Sonar smells --- .../handler/support/MessagingMethodInvokerHelper.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java index 86a0f84276..b378e9fc5d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java @@ -1276,12 +1276,12 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im private String determineHeaderExpression(Annotation headerAnnotation, MethodParameter methodParameter) { methodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER); - String headerName = null; String relativeExpression = ""; AnnotationAttributes annotationAttributes = (AnnotationAttributes) AnnotationUtils.getAnnotationAttributes(headerAnnotation); String valueAttribute = annotationAttributes.getString(AnnotationUtils.VALUE); - int len = valueAttribute == null ? 0 : valueAttribute.length(); + int len = valueAttribute.length(); + String headerName = valueAttribute; if (!StringUtils.hasText(valueAttribute)) { headerName = methodParameter.getParameterName(); } @@ -1296,9 +1296,7 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im this.spelOnly = true; } } - else { - headerName = valueAttribute; - } + Assert.notNull(headerName, "Cannot determine header name. Possible reasons: -debug is " + "disabled or header name is not explicitly provided via @Header annotation."); String headerRetrievalExpression = "headers['" + headerName + "']";