Skip to content

Commit 36c33bb

Browse files
garyrussellartembilan
authored andcommitted
Sonar fixes
- a few complexities - final method calls from ctor - raw exception throwing - useless overrides - loss of stack trace
1 parent 7569d0a commit 36c33bb

File tree

45 files changed

+134
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+134
-114
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AbstractMessageListenerContainerSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public AbstractMessageListenerContainerSpec(C listenerContainer) {
5252
}
5353

5454
@Override
55-
public S id(String id) {
55+
public S id(String id) { // NOSONAR - not useless, increases visibility
5656
return super.id(id);
5757
}
5858

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/GlobalChannelInterceptorWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GlobalChannelInterceptorWrapper implements Ordered {
3232

3333
private final ChannelInterceptor channelInterceptor;
3434

35-
private volatile String[] patterns = new String[]{"*"}; // default
35+
private volatile String[] patterns = { "*" }; // default
3636

3737
private volatile int order = 0;
3838

@@ -57,7 +57,7 @@ public void setOrder(int order) {
5757
}
5858

5959
@Override
60-
public int getOrder() {
60+
public final int getOrder() {
6161
return this.order;
6262
}
6363

spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/CompositeKryoRegistrar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public CompositeKryoRegistrar(List<KryoRegistrar> delegates) {
4343
}
4444

4545
@Override
46-
public List<Registration> getRegistrations() {
46+
public final List<Registration> getRegistrations() {
4747
List<Registration> registrations = new ArrayList<Registration>();
4848
for (KryoRegistrar registrar : this.delegates) {
4949
registrations.addAll(registrar.getRegistrations());
@@ -59,13 +59,13 @@ private void validateRegistrations() {
5959
Assert.isTrue(registration.getId() >= MIN_REGISTRATION_VALUE,
6060
"registration ID must be >= " + MIN_REGISTRATION_VALUE);
6161
if (ids.contains(registration.getId())) {
62-
throw new RuntimeException(String.format("Duplicate registration ID found: %d",
62+
throw new IllegalArgumentException(String.format("Duplicate registration ID found: %d",
6363
registration.getId()));
6464
}
6565
ids.add(registration.getId());
6666

6767
if (types.contains(registration.getType())) {
68-
throw new RuntimeException(String.format("Duplicate registration found for type: %s",
68+
throw new IllegalArgumentException(String.format("Duplicate registration found for type: %s",
6969
registration.getType()));
7070
}
7171
types.add(registration.getType());

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ protected MessageHandler createHandler(Object bean, Method method, List<Annotati
9494
router.setIgnoreSendFailures(resolveAttributeToBoolean(ignoreSendFailures));
9595
}
9696

97+
routerAttributes(annotations, router);
98+
99+
return router;
100+
}
101+
102+
private void routerAttributes(List<Annotation> annotations, AbstractMessageRouter router) {
97103
if (routerAttributesProvided(annotations)) {
98104

99105
MethodInvokingRouter methodInvokingRouter = (MethodInvokingRouter) router;
@@ -127,8 +133,6 @@ protected MessageHandler createHandler(Object bean, Method method, List<Annotati
127133
}
128134

129135
}
130-
131-
return router;
132136
}
133137

134138
private boolean routerAttributesProvided(List<Annotation> annotations) {

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,7 @@ protected final AbstractBeanDefinition parseInternal(Element element, ParserCont
144144
String inputChannelName = element.getAttribute(inputChannelAttributeName);
145145

146146
if (!parserContext.getRegistry().containsBeanDefinition(inputChannelName)) {
147-
if (parserContext.getRegistry()
148-
.containsBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) {
149-
150-
BeanDefinition channelRegistry = parserContext.getRegistry().
151-
getBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);
152-
ConstructorArgumentValues caValues = channelRegistry.getConstructorArgumentValues();
153-
ValueHolder vh = caValues.getArgumentValue(0, Collection.class);
154-
if (vh == null) { //although it should never happen if it does we can fix it
155-
caValues.addIndexedArgumentValue(0, new ManagedSet<String>());
156-
}
157-
158-
@SuppressWarnings("unchecked")
159-
Collection<String> channelCandidateNames =
160-
(Collection<String>) caValues.getArgumentValue(0, Collection.class).getValue(); // NOSONAR see comment above
161-
channelCandidateNames.add(inputChannelName); // NOSONAR
162-
}
163-
else {
164-
parserContext.getReaderContext().error("Failed to locate '" +
165-
IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME + "'",
166-
parserContext.getRegistry());
167-
}
147+
registerChannelForCreation(parserContext, inputChannelName);
168148
}
169149
IntegrationNamespaceUtils.checkAndConfigureFixedSubscriberChannel(element, parserContext, inputChannelName,
170150
handlerBeanName);
@@ -188,6 +168,30 @@ protected final AbstractBeanDefinition parseInternal(Element element, ParserCont
188168
return null;
189169
}
190170

171+
private void registerChannelForCreation(ParserContext parserContext, String inputChannelName) {
172+
if (parserContext.getRegistry()
173+
.containsBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) {
174+
175+
BeanDefinition channelRegistry = parserContext.getRegistry().
176+
getBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);
177+
ConstructorArgumentValues caValues = channelRegistry.getConstructorArgumentValues();
178+
ValueHolder vh = caValues.getArgumentValue(0, Collection.class);
179+
if (vh == null) { //although it should never happen if it does we can fix it
180+
caValues.addIndexedArgumentValue(0, new ManagedSet<String>());
181+
}
182+
183+
@SuppressWarnings("unchecked")
184+
Collection<String> channelCandidateNames =
185+
(Collection<String>) caValues.getArgumentValue(0, Collection.class).getValue(); // NOSONAR see comment above
186+
channelCandidateNames.add(inputChannelName); // NOSONAR
187+
}
188+
else {
189+
parserContext.getReaderContext().error("Failed to locate '" +
190+
IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME + "'",
191+
parserContext.getRegistry());
192+
}
193+
}
194+
191195
/**
192196
* Override to allow 'reply-channel' within a chain, for components where it
193197
* makes sense (e.g. enricher). Default is false for outbound gateways, else true.

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ else if (!this.hasDefaultOption()) {
101101
IntegrationNamespaceUtils.createElementDescription(element) + ".", source);
102102
return null;
103103
}
104+
methodAttribute(element, parserContext, source, builder, innerDefinition, hasRef, hasExpression,
105+
expressionElement);
106+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply");
107+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
108+
this.postProcess(builder, element, parserContext);
109+
return builder;
110+
}
111+
112+
private void methodAttribute(Element element, ParserContext parserContext, Object source,
113+
BeanDefinitionBuilder builder, BeanComponentDefinition innerDefinition, boolean hasRef,
114+
boolean hasExpression, Element expressionElement) {
104115
String method = element.getAttribute(METHOD_ATTRIBUTE);
105116
if (StringUtils.hasText(method)) {
106117
if (hasExpression || expressionElement != null) {
@@ -117,10 +128,6 @@ else if (!this.hasDefaultOption()) {
117128
IntegrationNamespaceUtils.createElementDescription(element) + ".", source);
118129
}
119130
}
120-
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply");
121-
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
122-
this.postProcess(builder, element, parserContext);
123-
return builder;
124131
}
125132

126133
/**

spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.integration.dsl;
1818

19-
import org.apache.commons.logging.Log;
20-
import org.apache.commons.logging.LogFactory;
21-
2219
import org.springframework.beans.factory.DisposableBean;
2320
import org.springframework.beans.factory.InitializingBean;
2421
import org.springframework.beans.factory.config.AbstractFactoryBean;
@@ -42,20 +39,18 @@ public abstract class IntegrationComponentSpec<S extends IntegrationComponentSpe
4239

4340
protected static final SpelExpressionParser PARSER = new SpelExpressionParser();
4441

45-
protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR
46-
4742
protected volatile T target; // NOSONAR
4843

4944
private String id;
5045

5146
/**
5247
* Configure the component identifier. Used as the {@code beanName} to register the
5348
* bean in the application context for this component.
54-
* @param id the id.
49+
* @param idToSet the id.
5550
* @return the spec.
5651
*/
57-
protected S id(String id) {
58-
this.id = id;
52+
protected S id(String idToSet) {
53+
this.id = idToSet;
5954
return _this();
6055
}
6156

spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class IntegrationFlowBuilder extends IntegrationFlowDefinition<Inte
2828
}
2929

3030
@Override
31-
public StandardIntegrationFlow get() {
31+
public StandardIntegrationFlow get() { // NOSONAR - not useless, increases visibility
3232
return super.get();
3333
}
3434

spring-integration-core/src/main/java/org/springframework/integration/dsl/MessageChannelSpec.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,17 @@ protected MessageChannelSpec() {
5757
super();
5858
}
5959

60-
@Override
61-
protected S id(String id) {
62-
return super.id(id);
63-
}
64-
65-
public S datatype(Class<?>... datatypes) {
66-
Assert.notNull(datatypes, "'datatypes' must not be null");
67-
Assert.noNullElements(datatypes, "'datatypes' must not contain null elements");
68-
this.datatypes.addAll(Arrays.asList(datatypes));
60+
public S datatype(Class<?>... types) {
61+
Assert.notNull(types, "'datatypes' must not be null");
62+
Assert.noNullElements(types, "'datatypes' must not contain null elements");
63+
this.datatypes.addAll(Arrays.asList(types));
6964
return _this();
7065
}
7166

72-
public S interceptor(ChannelInterceptor... interceptors) {
73-
Assert.notNull(interceptors, "'interceptors' must not be null");
74-
Assert.noNullElements(interceptors, "'interceptors' must not contain null elements");
75-
this.interceptors.addAll(Arrays.asList(interceptors));
67+
public S interceptor(ChannelInterceptor... interceptorArray) {
68+
Assert.notNull(interceptorArray, "'interceptorArray' must not be null");
69+
Assert.noNullElements(interceptorArray, "'interceptorArray' must not contain null elements");
70+
this.interceptors.addAll(Arrays.asList(interceptorArray));
7671
return _this();
7772
}
7873

@@ -111,8 +106,8 @@ public S wireTap(WireTapSpec wireTapSpec) {
111106
return interceptor(interceptor);
112107
}
113108

114-
public S messageConverter(MessageConverter messageConverter) {
115-
this.messageConverter = messageConverter;
109+
public S messageConverter(MessageConverter converter) {
110+
this.messageConverter = converter;
116111
return _this();
117112
}
118113

spring-integration-core/src/main/java/org/springframework/integration/dsl/PublishSubscribeSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class PublishSubscribeSpec extends PublishSubscribeChannelSpec<PublishSub
4141
}
4242

4343
@Override
44-
public PublishSubscribeSpec id(String id) {
44+
public PublishSubscribeSpec id(String id) { // NOSONAR - not useless, increases visibility
4545
return super.id(id);
4646
}
4747

0 commit comments

Comments
 (0)