Skip to content

Commit 4760c54

Browse files
garyrussellartembilan
authored andcommitted
Sonar Fixes
Critical smells `o.s.i.h*`.
1 parent 536b6b1 commit 4760c54

14 files changed

+85
-41
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -25,13 +25,15 @@
2525
import org.springframework.context.Lifecycle;
2626
import org.springframework.integration.handler.support.MessagingMethodInvokerHelper;
2727
import org.springframework.integration.util.AbstractExpressionEvaluator;
28+
import org.springframework.lang.NonNull;
2829
import org.springframework.messaging.Message;
2930

3031
/**
3132
* A MessageListProcessor implementation that invokes a method on a target POJO.
3233
*
3334
* @author Dave Syer
3435
* @author Artem Bilan
36+
* @author Gary Russell
3537
* @since 2.0
3638
*/
3739
public class MethodInvokingMessageListProcessor<T> extends AbstractExpressionEvaluator
@@ -61,7 +63,7 @@ public MethodInvokingMessageListProcessor(Object targetObject, Class<? extends A
6163
}
6264

6365
@Override
64-
public void setBeanFactory(BeanFactory beanFactory) {
66+
public void setBeanFactory(@NonNull BeanFactory beanFactory) {
6567
super.setBeanFactory(beanFactory);
6668
this.delegate.setBeanFactory(beanFactory);
6769
}
@@ -77,6 +79,7 @@ public void setUseSpelInvoker(boolean useSpelInvoker) {
7779
this.delegate.setUseSpelInvoker(useSpelInvoker);
7880
}
7981

82+
@Override
8083
public String toString() {
8184
return this.delegate.toString();
8285
}

spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -23,6 +23,7 @@
2323
import org.springframework.context.Lifecycle;
2424
import org.springframework.core.convert.ConversionService;
2525
import org.springframework.integration.handler.support.MessagingMethodInvokerHelper;
26+
import org.springframework.lang.NonNull;
2627
import org.springframework.messaging.Message;
2728
import org.springframework.messaging.MessageHandlingException;
2829

@@ -37,6 +38,7 @@
3738
*
3839
* @author Dave Syer
3940
* @author Artem Bilan
41+
* @author Gary Russell
4042
*
4143
* @since 2.0
4244
*/
@@ -67,7 +69,7 @@ public void setConversionService(ConversionService conversionService) {
6769
}
6870

6971
@Override
70-
public void setBeanFactory(BeanFactory beanFactory) {
72+
public void setBeanFactory(@NonNull BeanFactory beanFactory) {
7173
super.setBeanFactory(beanFactory);
7274
this.delegate.setBeanFactory(beanFactory);
7375
}

spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ErrorMessageSendingRecoverer.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,25 @@ public Object recover(RetryContext context) throws Exception {
8686

8787
@Override
8888
protected Throwable payloadWhenNull(AttributeAccessor context) {
89-
return new RetryExceptionNotAvailableException(
90-
(Message<?>) context.getAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY),
91-
"No retry exception available; " +
92-
"this can occur, for example, if the RetryPolicy allowed zero attempts " +
93-
"to execute the handler; " +
94-
"RetryContext: " + context.toString());
89+
Message<?> message = (Message<?>) context.getAttribute(ErrorMessageUtils.FAILED_MESSAGE_CONTEXT_KEY);
90+
String description = "No retry exception available; " +
91+
"this can occur, for example, if the RetryPolicy allowed zero attempts " +
92+
"to execute the handler; " +
93+
"RetryContext: " + context.toString();
94+
return message == null
95+
? new RetryExceptionNotAvailableException(description)
96+
: new RetryExceptionNotAvailableException(message, description);
9597
}
9698

9799
public static class RetryExceptionNotAvailableException extends MessagingException {
98100

99101
private static final long serialVersionUID = 1L;
100102

103+
104+
RetryExceptionNotAvailableException(String description) {
105+
super(description);
106+
}
107+
101108
public RetryExceptionNotAvailableException(Message<?> message, String description) {
102109
super(message, description);
103110
}

spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java

-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ protected Object doInvoke(MethodInvocation invocation, Message<?> message) throw
171171
private MessageChannel obtainDiscardChannel() {
172172
if (this.discardChannel == null) {
173173
if (this.discardChannelName != null) {
174-
if (getChannelResolver() == null) {
175-
throw new IllegalStateException("No channel resolver available to resolve the discard channel '"
176-
+ this.discardChannelName + "'");
177-
}
178174
this.discardChannel = getChannelResolver()
179175
.resolveDestination(this.discardChannelName);
180176
}

spring-integration-core/src/main/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGenerator.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public SpelExpressionRetryStateGenerator(String keyExpression, String forceRefre
6161
}
6262
}
6363

64+
@Override
6465
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
6566
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(beanFactory);
6667
}
@@ -69,11 +70,13 @@ public void setClassifier(Classifier<? super Throwable, Boolean> classifier) {
6970
this.classifier = classifier;
7071
}
7172

73+
@Override
7274
public RetryState determineRetryState(Message<?> message) {
75+
Boolean forceRefresh = this.forceRefreshExpression == null
76+
? Boolean.FALSE
77+
: this.forceRefreshExpression.getValue(this.evaluationContext, message, Boolean.class);
7378
return new DefaultRetryState(this.keyExpression.getValue(this.evaluationContext, message),
74-
this.forceRefreshExpression == null
75-
? false
76-
: this.forceRefreshExpression.getValue(this.evaluationContext, message, Boolean.class),
79+
forceRefresh == null ? false : forceRefresh,
7780
this.classifier);
7881
}
7982

spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import org.springframework.integration.util.FixedMethodFilter;
8585
import org.springframework.integration.util.MessagingAnnotationUtils;
8686
import org.springframework.integration.util.UniqueMethodFilter;
87+
import org.springframework.lang.NonNull;
8788
import org.springframework.messaging.Message;
8889
import org.springframework.messaging.MessageHandlingException;
8990
import org.springframework.messaging.MessageHeaders;
@@ -155,7 +156,8 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
155156
private static final Collection<Message<?>> dummyMessages = Collections.emptyList();
156157

157158
private static final TypeDescriptor messageListTypeDescriptor =
158-
new TypeDescriptor(ReflectionUtils.findField(MessagingMethodInvokerHelper.class, "dummyMessages"));
159+
new TypeDescriptor(ReflectionUtils.findField(MessagingMethodInvokerHelper.class, // NOSONAR never null
160+
"dummyMessages"));
159161

160162
private static final TypeDescriptor messageArrayTypeDescriptor = TypeDescriptor.valueOf(Message[].class);
161163

@@ -291,7 +293,7 @@ public void setUseSpelInvoker(boolean useSpelInvoker) {
291293
}
292294

293295
@Override
294-
public void setBeanFactory(BeanFactory beanFactory) {
296+
public void setBeanFactory(@NonNull BeanFactory beanFactory) {
295297
super.setBeanFactory(beanFactory);
296298
this.messageHandlerMethodFactory.setBeanFactory(beanFactory);
297299
if (beanFactory instanceof ConfigurableListableBeanFactory) {

spring-integration-core/src/main/java/org/springframework/integration/handler/support/PayloadExpressionArgumentResolver.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2018 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.
@@ -32,6 +32,7 @@
3232
* as a SpEL expression against {@code message} and converting result to expected parameter type.
3333
*
3434
* @author Artem Bilan
35+
* @author Gary Russell
3536
*
3637
* @since 5.0
3738
*
@@ -53,7 +54,7 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
5354
Expression expression = this.expressionCache.get(parameter);
5455
if (expression == null) {
5556
Payload ann = parameter.getParameterAnnotation(Payload.class);
56-
expression = EXPRESSION_PARSER.parseExpression(ann.expression());
57+
expression = EXPRESSION_PARSER.parseExpression(ann.expression()); // NOSONAR never null - supportsParameter()
5758
this.expressionCache.put(parameter, expression);
5859
}
5960
return evaluateExpression(expression, message.getPayload(), parameter.getParameterType());

spring-integration-core/src/main/java/org/springframework/integration/handler/support/PayloadsArgumentResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2018 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.
@@ -62,7 +62,7 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
6262
Collection<Message<?>> messages = (Collection<Message<?>>) payload;
6363

6464
if (!this.expressionCache.containsKey(parameter)) {
65-
Payloads payloads = parameter.getParameterAnnotation(Payloads.class);
65+
Payloads payloads = parameter.getParameterAnnotation(Payloads.class); // NOSONAR never null - supportsParameter()
6666
String expression = payloads.value();
6767
if (StringUtils.hasText(expression)) {
6868
this.expressionCache.put(parameter, EXPRESSION_PARSER.parseExpression("![payload." + expression + "]"));

spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrar.java

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.http.config;
1818

19+
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.Map;
2122

@@ -55,6 +56,9 @@ class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistr
5556
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
5657
Map<String, Object> annotationAttributes =
5758
importingClassMetadata.getAnnotationAttributes(EnableIntegrationGraphController.class.getName());
59+
if (annotationAttributes == null) {
60+
annotationAttributes = Collections.emptyMap(); // To satisfy sonar for subsequent references
61+
}
5862

5963
if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_GRAPH_SERVER_BEAN_NAME)) {
6064
registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_GRAPH_SERVER_BEAN_NAME,

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/BaseHttpInboundEndpoint.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@
5252
*/
5353
public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements OrderlyShutdownCapable {
5454

55-
protected static final boolean jaxb2Present = ClassUtils.isPresent("javax.xml.bind.Binder",
56-
BaseHttpInboundEndpoint.class.getClassLoader());
55+
protected static final boolean jaxb2Present = // NOSONAR lower case static
56+
ClassUtils.isPresent("javax.xml.bind.Binder",
57+
BaseHttpInboundEndpoint.class.getClassLoader());
5758

58-
protected static final boolean romeToolsPresent = ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed",
59-
BaseHttpInboundEndpoint.class.getClassLoader());
59+
protected static final boolean romeToolsPresent = // NOSONAR lower case static
60+
ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed",
61+
BaseHttpInboundEndpoint.class.getClassLoader());
6062

61-
protected static final List<HttpMethod> nonReadableBodyHttpMethods =
63+
protected static final List<HttpMethod> nonReadableBodyHttpMethods = // NOSONAR lower case static
6264
Arrays.asList(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS);
6365

6466
protected final boolean expectReply;
@@ -327,6 +329,8 @@ public String getComponentType() {
327329
* @return true or false if HTTP request can contain the body
328330
*/
329331
protected boolean isReadable(HttpRequest request) {
330-
return !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, request.getMethod()));
332+
HttpMethod method = request.getMethod();
333+
return method == null ? false : !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, method));
331334
}
335+
332336
}

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -34,6 +34,7 @@
3434
import org.springframework.expression.Expression;
3535
import org.springframework.expression.spel.support.StandardEvaluationContext;
3636
import org.springframework.http.HttpEntity;
37+
import org.springframework.http.HttpMethod;
3738
import org.springframework.http.HttpStatus;
3839
import org.springframework.http.MediaType;
3940
import org.springframework.http.RequestEntity;
@@ -339,14 +340,19 @@ private Message<?> actualDoHandleRequest(HttpServletRequest servletRequest, Requ
339340
.copyHeadersIfAbsent(headers);
340341
}
341342
else {
343+
Assert.state(payload != null, "payload cannot be null");
342344
messageBuilder = this.getMessageBuilderFactory().withPayload(payload).copyHeaders(headers);
343345
}
344346

347+
HttpMethod method = httpEntity.getMethod();
348+
if (method != null) {
349+
messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
350+
method.toString());
351+
}
352+
345353
Message<?> message = messageBuilder
346354
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,
347355
httpEntity.getUrl().toString())
348-
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
349-
httpEntity.getMethod().toString())
350356
.setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,
351357
servletRequest.getUserPrincipal())
352358
.build();

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626

2727
import org.springframework.beans.BeansException;
2828
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
29+
import org.springframework.context.ApplicationContext;
2930
import org.springframework.context.ApplicationListener;
3031
import org.springframework.context.event.ContextRefreshedEvent;
3132
import org.springframework.core.annotation.AnnotationUtils;
33+
import org.springframework.lang.Nullable;
3234
import org.springframework.util.CollectionUtils;
3335
import org.springframework.util.ObjectUtils;
3436
import org.springframework.util.ReflectionUtils;
@@ -76,6 +78,7 @@
7678
* them during the {@link BaseHttpInboundEndpoint} destruction.
7779
*
7880
* @author Artem Bilan
81+
* @author Gary Russell
7982
*
8083
* @since 3.0
8184
*
@@ -100,10 +103,12 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
100103
}
101104

102105
@Override
103-
@SuppressWarnings("unchecked")
104106
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
105107
if (isHandler(bean.getClass())) {
106-
unregisterMapping(getMappingForEndpoint((BaseHttpInboundEndpoint) bean));
108+
RequestMappingInfo mapping = getMappingForEndpoint((BaseHttpInboundEndpoint) bean);
109+
if (mapping != null) {
110+
unregisterMapping(mapping);
111+
}
107112
}
108113
}
109114

@@ -141,11 +146,19 @@ protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequ
141146
}
142147

143148
@Override
144-
protected void detectHandlerMethods(Object handler) {
149+
protected void detectHandlerMethods(Object handlerArg) {
150+
Object handler = handlerArg;
145151
if (handler instanceof String) {
146-
handler = this.getApplicationContext().getBean((String) handler);
152+
ApplicationContext applicationContext = getApplicationContext();
153+
if (applicationContext != null) {
154+
handler = applicationContext.getBean((String) handler);
155+
}
156+
else {
157+
throw new IllegalStateException("No application context available to lookup bean '"
158+
+ handler + "'");
159+
}
147160
}
148-
RequestMappingInfo mapping = this.getMappingForEndpoint((BaseHttpInboundEndpoint) handler);
161+
RequestMappingInfo mapping = getMappingForEndpoint((BaseHttpInboundEndpoint) handler);
149162
if (mapping != null) {
150163
registerMapping(mapping, handler, HANDLE_REQUEST_METHOD);
151164
}
@@ -196,6 +209,7 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
196209
* 'Spring Integration HTTP Inbound Endpoint' {@link RequestMapping}.
197210
* @see RequestMappingHandlerMapping#getMappingForMethod
198211
*/
212+
@Nullable
199213
private RequestMappingInfo getMappingForEndpoint(BaseHttpInboundEndpoint endpoint) {
200214
final RequestMapping requestMapping = endpoint.getRequestMapping();
201215

spring-integration-http/src/main/java/org/springframework/integration/http/multipart/SimpleMultipartFileReader.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -29,6 +29,7 @@
2929
* content directly as either a String or byte array depending on the Content-Type.
3030
*
3131
* @author Mark Fisher
32+
* @author Gary Russell
3233
* @since 2.0
3334
*/
3435
public class SimpleMultipartFileReader implements MultipartFileReader<Object> {
@@ -49,8 +50,9 @@ public void setDefaultMultipartCharset(String defaultCharset) {
4950

5051
@Override
5152
public Object readMultipartFile(MultipartFile multipartFile) throws IOException {
52-
if (multipartFile.getContentType() != null && multipartFile.getContentType().startsWith("text")) {
53-
MediaType contentType = MediaType.parseMediaType(multipartFile.getContentType());
53+
String mpContentType = multipartFile.getContentType();
54+
if (mpContentType != null && mpContentType.startsWith("text")) {
55+
MediaType contentType = MediaType.parseMediaType(mpContentType);
5456
Charset charset = contentType.getCharset();
5557
if (charset == null) {
5658
charset = this.defaultCharset;

spring-integration-http/src/main/java/org/springframework/integration/http/outbound/AbstractHttpRequestExecutingMessageHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ protected Object getReply(ResponseEntity<?> httpResponse) {
325325
Object responseBody = httpResponse.getBody();
326326
replyBuilder = (responseBody instanceof Message<?>)
327327
? messageBuilderFactory.fromMessage((Message<?>) responseBody)
328-
: messageBuilderFactory.withPayload(responseBody);
328+
: messageBuilderFactory.withPayload(responseBody); // NOSONAR - hasBody()
329329

330330
}
331331
else {

0 commit comments

Comments
 (0)