Skip to content

Commit 93d7c58

Browse files
artembilangaryrussell
authored andcommitted
Enable ModifierOrderCheck Checkstyle rule (#2673)
* Enable ModifierOrderCheck Checkstyle rule * Fix violations for `static` and `abstract` modifier * Remove redundant code in the `TcpNioConnection` * Mark `connectionFactoryName` as `@Nullable` in the `TcpConnectionSupport` ctor and its inheritors * Fix some smells according IDEA suggestions in the affected classes * This should fix some Sonar smells as well * * Fix `HeaderMapperTests` * * Polishing `TcpConnection` code style and fix Javdocs
1 parent a01d09f commit 93d7c58

File tree

56 files changed

+633
-563
lines changed

Some content is hidden

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

56 files changed

+633
-563
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public void setErrorMessageStrategy(ErrorMessageStrategy errorMessageStrategy) {
310310
this.errorMessageStrategy = errorMessageStrategy;
311311
}
312312

313-
protected synchronized final void setConnectionFactory(ConnectionFactory connectionFactory) {
313+
protected final synchronized void setConnectionFactory(ConnectionFactory connectionFactory) {
314314
this.connectionFactory = connectionFactory;
315315
}
316316

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2016 the original author or authors.
2+
* Copyright 2015-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.
@@ -28,11 +28,13 @@
2828
* Base class for {@link KryoRegistrar} implementations.
2929
*
3030
* @author David Turanski
31+
* @author Artem Bilan
32+
*
3133
* @since 4.2
3234
*/
3335
public abstract class AbstractKryoRegistrar implements KryoRegistrar {
3436

35-
protected final static Kryo kryo = new Kryo();
37+
protected static final Kryo kryo = new Kryo();
3638

3739
protected final Log log = LogFactory.getLog(this.getClass());
3840

@@ -55,7 +57,7 @@ private void register(Kryo kryo, Registration registration) {
5557
Registration existing = kryo.getRegistration(id);
5658

5759
if (existing != null) {
58-
throw new RuntimeException((String.format("registration already exists %s", existing)));
60+
throw new RuntimeException("registration already exists " + existing);
5961
}
6062

6163
if (this.log.isInfoEnabled()) {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2016 the original author or authors.
2+
* Copyright 2015-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.
@@ -20,12 +20,14 @@
2020
* Default registration ids for serializers provided by the framework.
2121
*
2222
* @author Gary Russell
23+
* @author Artem Bilan
24+
*
2325
* @since 4.2
2426
*
2527
*/
2628
public final class RegistrationIds {
2729

28-
public final static int DEFAULT_FILE_REGISTRATION_ID = 40;
30+
public static final int DEFAULT_FILE_REGISTRATION_ID = 40;
2931

3032
public static final int DEFAULT_MESSAGEHEADERS_ID = 41;
3133

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class DefaultConfiguringBeanFactoryPostProcessor
8989

9090
private static final Log logger = LogFactory.getLog(DefaultConfiguringBeanFactoryPostProcessor.class);
9191

92-
private final static IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER =
92+
private static final IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER =
9393
new IntegrationConverterInitializer();
9494

9595
private static final Set<Integer> registriesProcessed = new HashSet<>();
@@ -152,17 +152,22 @@ public void afterSingletonsInstantiated() {
152152
*/
153153
private void registerNullChannel() {
154154
if (this.beanFactory.containsBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
155-
BeanDefinition nullChannelDefinition;
155+
BeanDefinition nullChannelDefinition = null;
156156
if (this.beanFactory.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
157157
nullChannelDefinition =
158158
this.beanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
159159
}
160160
else {
161-
nullChannelDefinition =
162-
((BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory())
163-
.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); // NOSONAR not null
161+
BeanDefinitionRegistry parentBeanFactory =
162+
(BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory();
163+
if (parentBeanFactory != null) {
164+
nullChannelDefinition =
165+
parentBeanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
166+
}
164167
}
165-
if (!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
168+
169+
if (nullChannelDefinition != null &&
170+
!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
166171
throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME
167172
+ "' is reserved.");
168173
}

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 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.
@@ -27,26 +27,27 @@
2727
* FactoryBean for creating Expression instances.
2828
*
2929
* @author Mark Fisher
30+
* @author Artem Bilan
31+
*
3032
* @since 2.0
3133
*/
3234
public class ExpressionFactoryBean extends AbstractFactoryBean<Expression> {
3335

34-
private final static ExpressionParser DEFAULT_PARSER = new SpelExpressionParser();
35-
36+
private static final ExpressionParser DEFAULT_PARSER = new SpelExpressionParser();
3637

3738
private final String expressionString;
3839

39-
private volatile ExpressionParser parser = DEFAULT_PARSER;
40+
private ExpressionParser parser = DEFAULT_PARSER;
4041

4142

4243
public ExpressionFactoryBean(String expressionString) {
43-
Assert.hasText(expressionString, "expressionString must not be empty or null");
44+
Assert.hasText(expressionString, "'expressionString' must not be empty or null");
4445
this.expressionString = expressionString;
4546
}
4647

4748

4849
public void setParserConfiguration(SpelParserConfiguration parserConfiguration) {
49-
Assert.notNull(parserConfiguration, "parserConfiguration must not be null");
50+
Assert.notNull(parserConfiguration, "'parserConfiguration' must not be null");
5051
this.parser = new SpelExpressionParser(parserConfiguration);
5152
}
5253

@@ -57,7 +58,7 @@ public Class<?> getObjectType() {
5758
}
5859

5960
@Override
60-
protected Expression createInstance() throws Exception {
61+
protected Expression createInstance() {
6162
return this.parser.parseExpression(this.expressionString);
6263
}
6364

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -32,23 +32,27 @@
3232
* @author Oleg Zhurakousky
3333
* @author Mark Fisher
3434
* @author Artem Bilan
35+
*
3536
* @since 2.0
3637
*/
3738
public class ConverterParser extends AbstractBeanDefinitionParser {
3839

39-
private final static IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER = new IntegrationConverterInitializer();
40+
private static final IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER =
41+
new IntegrationConverterInitializer();
4042

4143
@Override
4244
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
4345
BeanDefinitionRegistry registry = parserContext.getRegistry();
44-
BeanComponentDefinition converterDefinition = IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
46+
BeanComponentDefinition converterDefinition =
47+
IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
4548
if (converterDefinition != null) {
4649
INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, converterDefinition);
4750
}
4851
else {
4952
String beanName = element.getAttribute("ref");
5053
Assert.isTrue(StringUtils.hasText(beanName),
51-
"Either a 'ref' attribute pointing to a Converter or a <bean> sub-element defining a Converter is required.");
54+
"Either a 'ref' attribute pointing to a Converter " +
55+
"or a <bean> sub-element defining a Converter is required.");
5256
INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, new RuntimeBeanReference(beanName));
5357
}
5458
return null;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public abstract class IntegrationComponentSpec<S extends IntegrationComponentSpec<S, T>, T>
3838
implements FactoryBean<T>, InitializingBean, DisposableBean {
3939

40-
protected final static SpelExpressionParser PARSER = new SpelExpressionParser();
40+
protected static final SpelExpressionParser PARSER = new SpelExpressionParser();
4141

4242
protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR
4343

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

+26-20
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
import org.springframework.integration.transformer.PayloadTypeConvertingTransformer;
4343
import org.springframework.integration.transformer.StreamTransformer;
4444
import org.springframework.integration.transformer.SyslogToMapTransformer;
45+
import org.springframework.lang.Nullable;
4546
import org.springframework.messaging.Message;
46-
import org.springframework.util.Assert;
4747

4848
import reactor.core.publisher.Flux;
4949
import reactor.core.publisher.Mono;
@@ -58,14 +58,16 @@
5858
*/
5959
public abstract class Transformers {
6060

61-
private final static SpelExpressionParser PARSER = new SpelExpressionParser();
61+
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
6262

6363
public static ObjectToStringTransformer objectToString() {
6464
return objectToString(null);
6565
}
6666

67-
public static ObjectToStringTransformer objectToString(String charset) {
68-
return charset != null ? new ObjectToStringTransformer(charset) : new ObjectToStringTransformer();
67+
public static ObjectToStringTransformer objectToString(@Nullable String charset) {
68+
return charset != null
69+
? new ObjectToStringTransformer(charset)
70+
: new ObjectToStringTransformer();
6971
}
7072

7173
public static ObjectToMapTransformer toMap() {
@@ -100,20 +102,21 @@ public static ObjectToJsonTransformer toJson() {
100102
return toJson(null, null, null);
101103
}
102104

103-
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper) {
105+
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper) {
104106
return toJson(jsonObjectMapper, null, null);
105107
}
106108

107-
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper,
108-
ObjectToJsonTransformer.ResultType resultType) {
109+
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper,
110+
@Nullable ObjectToJsonTransformer.ResultType resultType) {
109111
return toJson(jsonObjectMapper, resultType, null);
110112
}
111113

112-
public static ObjectToJsonTransformer toJson(String contentType) {
114+
public static ObjectToJsonTransformer toJson(@Nullable String contentType) {
113115
return toJson(null, null, contentType);
114116
}
115117

116-
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper, String contentType) {
118+
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper,
119+
@Nullable String contentType) {
117120
return toJson(jsonObjectMapper, null, contentType);
118121
}
119122

@@ -124,16 +127,18 @@ public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMa
124127
* @return the ObjectToJsonTransformer
125128
* @since 5.0.9
126129
*/
127-
public static ObjectToJsonTransformer toJson(ObjectToJsonTransformer.ResultType resultType) {
130+
public static ObjectToJsonTransformer toJson(@Nullable ObjectToJsonTransformer.ResultType resultType) {
128131
return toJson(null, resultType, null);
129132
}
130133

131-
public static ObjectToJsonTransformer toJson(ObjectToJsonTransformer.ResultType resultType, String contentType) {
134+
public static ObjectToJsonTransformer toJson(@Nullable ObjectToJsonTransformer.ResultType resultType,
135+
@Nullable String contentType) {
132136
return toJson(null, resultType, contentType);
133137
}
134138

135-
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper,
136-
ObjectToJsonTransformer.ResultType resultType, String contentType) {
139+
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper,
140+
@Nullable ObjectToJsonTransformer.ResultType resultType, @Nullable String contentType) {
141+
137142
ObjectToJsonTransformer transformer;
138143
if (jsonObjectMapper != null) {
139144
if (resultType != null) {
@@ -159,23 +164,25 @@ public static JsonToObjectTransformer fromJson() {
159164
return fromJson(null, null);
160165
}
161166

162-
public static JsonToObjectTransformer fromJson(Class<?> targetClass) {
167+
public static JsonToObjectTransformer fromJson(@Nullable Class<?> targetClass) {
163168
return fromJson(targetClass, null);
164169
}
165170

166-
public static JsonToObjectTransformer fromJson(JsonObjectMapper<?, ?> jsonObjectMapper) {
171+
public static JsonToObjectTransformer fromJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper) {
167172
return fromJson(null, jsonObjectMapper);
168173
}
169174

170-
public static JsonToObjectTransformer fromJson(Class<?> targetClass, JsonObjectMapper<?, ?> jsonObjectMapper) {
175+
public static JsonToObjectTransformer fromJson(@Nullable Class<?> targetClass,
176+
@Nullable JsonObjectMapper<?, ?> jsonObjectMapper) {
177+
171178
return new JsonToObjectTransformer(targetClass, jsonObjectMapper);
172179
}
173180

174181
public static PayloadSerializingTransformer serializer() {
175182
return serializer(null);
176183
}
177184

178-
public static PayloadSerializingTransformer serializer(Serializer<Object> serializer) {
185+
public static PayloadSerializingTransformer serializer(@Nullable Serializer<Object> serializer) {
179186
PayloadSerializingTransformer transformer = new PayloadSerializingTransformer();
180187
if (serializer != null) {
181188
transformer.setSerializer(serializer);
@@ -187,7 +194,7 @@ public static PayloadDeserializingTransformer deserializer(String... whiteListPa
187194
return deserializer(null, whiteListPatterns);
188195
}
189196

190-
public static PayloadDeserializingTransformer deserializer(Deserializer<Object> deserializer,
197+
public static PayloadDeserializingTransformer deserializer(@Nullable Deserializer<Object> deserializer,
191198
String... whiteListPatterns) {
192199
PayloadDeserializingTransformer transformer = new PayloadDeserializingTransformer();
193200
transformer.setWhiteListPatterns(whiteListPatterns);
@@ -198,7 +205,6 @@ public static PayloadDeserializingTransformer deserializer(Deserializer<Object>
198205
}
199206

200207
public static <T, U> PayloadTypeConvertingTransformer<T, U> converter(Converter<T, U> converter) {
201-
Assert.notNull(converter, "The Converter<?, ?> is required for the PayloadTypeConvertingTransformer");
202208
PayloadTypeConvertingTransformer<T, U> transformer = new PayloadTypeConvertingTransformer<>();
203209
transformer.setConverter(converter);
204210
return transformer;
@@ -276,7 +282,7 @@ public static StreamTransformer fromStream() {
276282
* @param charset the charset.
277283
* @return the {@link StreamTransformer} instance.
278284
*/
279-
public static StreamTransformer fromStream(String charset) {
285+
public static StreamTransformer fromStream(@Nullable String charset) {
280286
return new StreamTransformer(charset);
281287
}
282288

0 commit comments

Comments
 (0)