Skip to content

Commit 7084e96

Browse files
committed
More Sonar fixes
1 parent 53d0448 commit 7084e96

File tree

8 files changed

+59
-49
lines changed

8 files changed

+59
-49
lines changed

spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/CamelMessageHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,19 @@ protected final void doInit() {
165165
"The 'endpointUri' option is mutually exclusive with 'route'");
166166

167167
BeanFactory beanFactory = getBeanFactory();
168-
if (this.producerTemplate == null) {
168+
if (this.producerTemplate == null) { // NOSONAR
169169
this.producerTemplate = beanFactory.getBean(CamelContext.class).createProducerTemplate();
170170
}
171171

172-
if (this.route != null) {
172+
LambdaRouteBuilder lambdaRouteBuilder = this.route;
173+
if (lambdaRouteBuilder != null) {
173174
CamelContext camelContext = this.producerTemplate.getCamelContext();
174175
RouteBuilder routeBuilder =
175176
new RouteBuilder(camelContext) {
176177

177178
@Override
178179
public void configure() throws Exception {
179-
CamelMessageHandler.this.route.accept(this);
180+
lambdaRouteBuilder.accept(this);
180181
}
181182

182183
};

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
9292
AnnotationAttributes.fromMap(
9393
importingClassMetadata.getAnnotationAttributes(IntegrationComponentScan.class.getName()));
9494

95+
Assert.notNull(componentScan, "The '@IntegrationComponentScan' must be present for using this registrar");
96+
9597
Collection<String> basePackages = getBasePackages(componentScan, registry);
9698

9799
if (basePackages.isEmpty()) {

spring-integration-core/src/main/java/org/springframework/integration/config/MessagingAnnotationPostProcessor.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
134134

135135
private void processCandidate(String beanName, AnnotatedBeanDefinition beanDefinition) {
136136
MethodMetadata methodMetadata = beanDefinition.getFactoryMethodMetadata();
137-
MergedAnnotations annotations = methodMetadata.getAnnotations();
137+
MergedAnnotations annotations = methodMetadata.getAnnotations(); // NOSONAR
138138
if (methodMetadata instanceof StandardMethodMetadata standardMethodMetadata) {
139139
annotations = MergedAnnotations.from(standardMethodMetadata.getIntrospectedMethod());
140140
}
@@ -179,7 +179,7 @@ private void processMessagingAnnotationOnBean(String beanName, AnnotatedBeanDefi
179179
if (messagingAnnotationProcessor != null) {
180180
if (messagingAnnotationProcessor.beanAnnotationAware()) {
181181
if (messagingAnnotationProcessor.shouldCreateEndpoint(
182-
beanDefinition.getFactoryMethodMetadata().getAnnotations(), annotationChain)) {
182+
beanDefinition.getFactoryMethodMetadata().getAnnotations(), annotationChain)) { // NOSONAR
183183

184184
messagingAnnotationProcessor.processBeanDefinition(beanName, beanDefinition, annotationChain);
185185
}
@@ -311,19 +311,18 @@ private void postProcessMethodAndRegisterEndpointIfAny(Object bean, String beanN
311311
MethodAnnotationPostProcessor<?> postProcessor, Method targetMethod) {
312312

313313
Object result = postProcessor.postProcess(bean, beanName, targetMethod, annotations);
314-
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
315314
if (result instanceof AbstractEndpoint endpoint) {
316315
String autoStartup = MessagingAnnotationUtils.resolveAttribute(annotations, "autoStartup", String.class);
317316
if (StringUtils.hasText(autoStartup)) {
318-
autoStartup = beanFactory.resolveEmbeddedValue(autoStartup);
317+
autoStartup = this.beanFactory.resolveEmbeddedValue(autoStartup);
319318
if (StringUtils.hasText(autoStartup)) {
320319
endpoint.setAutoStartup(Boolean.parseBoolean(autoStartup));
321320
}
322321
}
323322

324323
String phase = MessagingAnnotationUtils.resolveAttribute(annotations, "phase", String.class);
325324
if (StringUtils.hasText(phase)) {
326-
phase = beanFactory.resolveEmbeddedValue(phase);
325+
phase = this.beanFactory.resolveEmbeddedValue(phase);
327326
if (StringUtils.hasText(phase)) {
328327
endpoint.setPhase(Integer.parseInt(phase));
329328
}
@@ -339,7 +338,7 @@ private void postProcessMethodAndRegisterEndpointIfAny(Object bean, String beanN
339338
getBeanDefinitionRegistry()
340339
.registerBeanDefinition(endpointBeanName,
341340
new RootBeanDefinition((Class<AbstractEndpoint>) endpoint.getClass(), () -> endpoint));
342-
beanFactory.getBean(endpointBeanName);
341+
this.beanFactory.getBean(endpointBeanName);
343342
}
344343
}
345344

@@ -352,8 +351,7 @@ protected String generateBeanName(String originalBeanName, Method method,
352351
+ ClassUtils.getShortNameAsProperty(annotationType);
353352
name = baseName;
354353
int count = 1;
355-
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
356-
while (beanFactory.containsBean(name)) {
354+
while (this.beanFactory.containsBean(name)) {
357355
name = baseName + "#" + (++count);
358356
}
359357
}

spring-integration-core/src/main/java/org/springframework/integration/config/xml/GatewayParser.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public class GatewayParser implements BeanDefinitionParser {
6767

6868
private static final String PROXY_DEFAULT_METHODS_ATTR = "proxyDefaultMethods";
6969

70+
private static final String ASYNC_EXECUTOR_ATTR = "asyncExecutor";
71+
72+
private static final String MAPPER_ATTR = "mapper";
73+
7074
@Override
7175
public BeanDefinition parse(final Element element, ParserContext parserContext) {
7276
boolean isNested = parserContext.isNested();
@@ -83,13 +87,13 @@ public BeanDefinition parse(final Element element, ParserContext parserContext)
8387

8488
String asyncExecutor = element.getAttribute("async-executor");
8589
if (!element.hasAttribute("async-executor") || StringUtils.hasLength(asyncExecutor)) {
86-
gatewayAttributes.put("asyncExecutor", asyncExecutor);
90+
gatewayAttributes.put(ASYNC_EXECUTOR_ATTR, asyncExecutor);
8791
}
8892
else {
89-
gatewayAttributes.put("asyncExecutor", null);
93+
gatewayAttributes.put(ASYNC_EXECUTOR_ATTR, null);
9094
}
9195

92-
gatewayAttributes.put("mapper", element.getAttribute("mapper"));
96+
gatewayAttributes.put(MAPPER_ATTR, element.getAttribute(MAPPER_ATTR));
9397
gatewayAttributes.put("defaultReplyTimeout",
9498
element.getAttribute(isNested ? "reply-timeout" : "default-reply-timeout"));
9599
gatewayAttributes.put("defaultRequestTimeout",
@@ -122,8 +126,10 @@ private static void headers(Element element, Map<String, Object> gatewayAttribut
122126
Map<String, Object> header = new HashMap<>();
123127
header.put(AbstractBeanDefinitionParser.NAME_ATTRIBUTE,
124128
e.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE));
125-
header.put("value", e.getAttribute("value"));
126-
header.put("expression", e.getAttribute("expression"));
129+
header.put(IntegrationNamespaceUtils.VALUE_ATTRIBUTE,
130+
e.getAttribute(IntegrationNamespaceUtils.VALUE_ATTRIBUTE));
131+
header.put(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE,
132+
e.getAttribute(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE));
127133
headers.add(header);
128134
}
129135
gatewayAttributes.put("defaultHeaders", headers.toArray(new Map<?, ?>[0]));
@@ -146,7 +152,7 @@ private static void methods(Element element, ParserContext parserContext,
146152
methodMetadataBuilder.addPropertyValue("requestTimeout", methodElement.getAttribute("request-timeout"));
147153
methodMetadataBuilder.addPropertyValue("replyTimeout", methodElement.getAttribute("reply-timeout"));
148154

149-
boolean hasMapper = StringUtils.hasText(element.getAttribute("mapper"));
155+
boolean hasMapper = StringUtils.hasText(element.getAttribute(MAPPER_ATTR));
150156
String payloadExpression = methodElement.getAttribute("payload-expression");
151157
Assert.state(!hasMapper || !StringUtils.hasText(payloadExpression),
152158
"'payload-expression' is not allowed when a 'mapper' is provided");
@@ -165,7 +171,8 @@ private static void methods(Element element, ParserContext parserContext,
165171
Map<String, Object> headerExpressions = new ManagedMap<>();
166172
for (Element headerElement : invocationHeaders) {
167173
BeanDefinition expressionDef = IntegrationNamespaceUtils
168-
.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext,
174+
.createExpressionDefinitionFromValueOrExpression(
175+
IntegrationNamespaceUtils.VALUE_ATTRIBUTE, "expression", parserContext,
169176
headerElement, true);
170177

171178
headerExpressions.put(headerElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE),
@@ -193,8 +200,8 @@ private static BeanDefinitionHolder buildBeanDefinition(Map<String, Object> gate
193200
String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel");
194201
String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel");
195202
String errorChannel = (String) gatewayAttributes.get("errorChannel");
196-
String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor");
197-
String mapper = (String) gatewayAttributes.get("mapper");
203+
String asyncExecutor = (String) gatewayAttributes.get(ASYNC_EXECUTOR_ATTR);
204+
String mapper = (String) gatewayAttributes.get(MAPPER_ATTR);
198205
String proxyDefaultMethods = (String) gatewayAttributes.get(PROXY_DEFAULT_METHODS_ATTR);
199206

200207
boolean hasMapper = StringUtils.hasText(mapper);
@@ -229,13 +236,13 @@ private static BeanDefinitionHolder buildBeanDefinition(Map<String, Object> gate
229236
gatewayProxyBuilder.addPropertyValue("errorChannelName", errorChannel);
230237
}
231238
if (asyncExecutor == null || AnnotationConstants.NULL.equals(asyncExecutor)) {
232-
gatewayProxyBuilder.addPropertyValue("asyncExecutor", null);
239+
gatewayProxyBuilder.addPropertyValue(ASYNC_EXECUTOR_ATTR, null);
233240
}
234241
else if (StringUtils.hasText(asyncExecutor)) {
235-
gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor);
242+
gatewayProxyBuilder.addPropertyReference(ASYNC_EXECUTOR_ATTR, asyncExecutor);
236243
}
237244
if (StringUtils.hasText(mapper)) {
238-
gatewayProxyBuilder.addPropertyReference("mapper", mapper);
245+
gatewayProxyBuilder.addPropertyReference(MAPPER_ATTR, mapper);
239246
}
240247
if (StringUtils.hasText(proxyDefaultMethods)) {
241248
gatewayProxyBuilder.addPropertyValue(PROXY_DEFAULT_METHODS_ATTR, proxyDefaultMethods);
@@ -247,7 +254,7 @@ else if (StringUtils.hasText(asyncExecutor)) {
247254
gatewayAttributes.get("defaultReplyTimeout"));
248255
gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods"));
249256

250-
String id = (String) gatewayAttributes.get("name");
257+
String id = (String) gatewayAttributes.get(AbstractBeanDefinitionParser.NAME_ATTRIBUTE);
251258
if (!StringUtils.hasText(id)) {
252259
BeanNameGenerator beanNameGenerator =
253260
IntegrationConfigUtils.annotationBeanNameGenerator(registry);
@@ -281,8 +288,8 @@ private static BeanDefinition getMethodMetadataBeanDefinition(String defaultPayl
281288
if (!ObjectUtils.isEmpty(defaultHeaders)) {
282289
Map<String, Object> headerExpressions = new ManagedMap<>();
283290
for (Map<String, Object> header : defaultHeaders) {
284-
String headerValue = (String) header.get("value");
285-
String headerExpression = (String) header.get("expression");
291+
String headerValue = (String) header.get(IntegrationNamespaceUtils.VALUE_ATTRIBUTE);
292+
String headerExpression = (String) header.get(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE);
286293
boolean hasValue = StringUtils.hasText(headerValue);
287294

288295
if (hasValue == StringUtils.hasText(headerExpression)) {
@@ -295,7 +302,7 @@ private static BeanDefinition getMethodMetadataBeanDefinition(String defaultPayl
295302
expressionDef.getConstructorArgumentValues()
296303
.addGenericArgumentValue(hasValue ? headerValue : headerExpression);
297304

298-
headerExpressions.put((String) header.get("name"), expressionDef);
305+
headerExpressions.put((String) header.get(AbstractBeanDefinitionParser.NAME_ATTRIBUTE), expressionDef);
299306
}
300307
methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
301308
}

spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -71,6 +71,8 @@ public abstract class IntegrationNamespaceUtils {
7171

7272
public static final String REF_ATTRIBUTE = "ref";
7373

74+
public static final String VALUE_ATTRIBUTE = "value";
75+
7476
public static final String METHOD_ATTRIBUTE = "method";
7577

7678
public static final String ORDER = "order";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Provides classes for Java DSL to support GraphQL components.
3+
*/
4+
package org.springframework.integration.graphql.dsl;

spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2022 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.
@@ -78,59 +78,55 @@ protected void onInit() {
7878
}
7979

8080
@Override
81-
@SuppressWarnings({"unchecked", "rawtypes"})
81+
@SuppressWarnings({ "unchecked", "rawtypes" })
8282
protected void handleMessageInternal(final Message<?> message) {
8383
Object objectToStore = message;
8484
if (this.extractPayload) {
8585
objectToStore = message.getPayload();
8686
}
8787

88-
DistributedObject distributedObject = getDistributedObject(message);
88+
DistributedObject object = getDistributedObject(message);
8989

90-
if (distributedObject instanceof Map) {
91-
Map map = (Map) distributedObject;
90+
if (object instanceof Map map) {
9291
if (objectToStore instanceof Map) {
9392
map.putAll((Map) objectToStore);
9493
}
95-
else if (objectToStore instanceof Map.Entry) {
96-
Map.Entry entry = (Map.Entry) objectToStore;
94+
else if (objectToStore instanceof Map.Entry entry) {
9795
map.put(entry.getKey(), entry.getValue());
9896
}
9997
else {
10098
map.put(getKey(message), objectToStore);
10199
}
102100
}
103-
else if (distributedObject instanceof MultiMap) {
104-
MultiMap map = (MultiMap) distributedObject;
101+
else if (object instanceof MultiMap map) {
105102
if (objectToStore instanceof Map) {
106103
Map<?, ?> mapToStore = (Map) objectToStore;
107104
for (Map.Entry entry : mapToStore.entrySet()) {
108105
map.put(entry.getKey(), entry.getValue());
109106
}
110107
}
111-
else if (objectToStore instanceof Map.Entry) {
112-
Map.Entry entry = (Map.Entry) objectToStore;
108+
else if (objectToStore instanceof Map.Entry entry) {
113109
map.put(entry.getKey(), entry.getValue());
114110
}
115111
else {
116112
map.put(getKey(message), objectToStore);
117113
}
118114
}
119-
else if (distributedObject instanceof ITopic) {
120-
((ITopic) distributedObject).publish(objectToStore);
115+
else if (object instanceof ITopic) {
116+
((ITopic) object).publish(objectToStore);
121117
}
122-
else if (distributedObject instanceof Collection) {
118+
else if (object instanceof Collection) {
123119
if (objectToStore instanceof Collection) {
124-
((Collection) distributedObject).addAll((Collection) objectToStore);
120+
((Collection) object).addAll((Collection) objectToStore);
125121
}
126122
else {
127-
((Collection) distributedObject).add(objectToStore);
123+
((Collection) object).add(objectToStore);
128124
}
129125
}
130126
else {
131-
throw new IllegalStateException("The 'distributedObject' for 'HazelcastCacheWritingMessageHandler' " +
127+
throw new IllegalStateException("The 'object' for 'HazelcastCacheWritingMessageHandler' " +
132128
"must be of 'IMap', 'MultiMap', 'ITopic', 'ISet' or 'IList' type, " +
133-
"but gotten: [" + distributedObject + "].");
129+
"but gotten: [" + object + "].");
134130
}
135131
}
136132

@@ -144,7 +140,7 @@ else if (this.cacheExpression != null) {
144140
}
145141
else if (message.getHeaders().containsKey(HazelcastHeaders.CACHE_NAME)) {
146142
return getBeanFactory()
147-
.getBean(message.getHeaders().get(HazelcastHeaders.CACHE_NAME, String.class),
143+
.getBean(message.getHeaders().get(HazelcastHeaders.CACHE_NAME, String.class), // NOSONAR
148144
DistributedObject.class);
149145
}
150146
else {

spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ public void handleError(Throwable throwable) {
257257
try {
258258
sent = errorChannel.send(new ErrorMessage(throwable), 10000); // NOSONAR
259259
}
260-
catch (Throwable errorDeliveryError) { //NOSONAR
260+
catch (Throwable errorDeliveryError) { // NOSONAR
261261
// message will be logged only
262262
logger.warn("Error message was not delivered.", errorDeliveryError);
263-
if (errorDeliveryError instanceof Error) { // NOSONAR
263+
if (errorDeliveryError instanceof Error) { // NOSONAR
264264
throw (Error) errorDeliveryError;
265265
}
266266
}

0 commit comments

Comments
 (0)