Skip to content

Commit 5eb3bfe

Browse files
committed
Fix new Sonar smells
* Some code clean up in the affected classes
1 parent fc4c85a commit 5eb3bfe

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.integration.http.support.DefaultHttpHeaderMapper;
3737
import org.springframework.integration.http.support.IntegrationWebExchangeBindException;
3838
import org.springframework.integration.mapping.HeaderMapper;
39+
import org.springframework.lang.Nullable;
3940
import org.springframework.messaging.MessageHeaders;
4041
import org.springframework.util.Assert;
4142
import org.springframework.util.ClassUtils;
@@ -190,7 +191,7 @@ protected HeaderMapper<HttpHeaders> getHeaderMapper() {
190191
* Specify the type of payload to be generated when the inbound HTTP request
191192
* content is read by the converters/encoders.
192193
* By default this value is null which means at runtime any "text" Content-Type will
193-
* result in String while all others default to <code>byte[].class</code>.
194+
* result in String while all others default to {@code byte[].class}.
194195
* @param requestPayloadType The payload type.
195196
*/
196197
public void setRequestPayloadTypeClass(Class<?> requestPayloadType) {
@@ -201,7 +202,7 @@ public void setRequestPayloadTypeClass(Class<?> requestPayloadType) {
201202
* Specify the type of payload to be generated when the inbound HTTP request
202203
* content is read by the converters/encoders.
203204
* By default this value is null which means at runtime any "text" Content-Type will
204-
* result in String while all others default to <code>byte[].class</code>.
205+
* result in String while all others default to {@code byte[].class}.
205206
* @param requestPayloadType The payload type.
206207
*/
207208
public void setRequestPayloadType(ResolvableType requestPayloadType) {
@@ -350,15 +351,6 @@ public IntegrationPatternType getIntegrationPatternType() {
350351
return this.expectReply ? super.getIntegrationPatternType() : IntegrationPatternType.inbound_channel_adapter;
351352
}
352353

353-
/**
354-
* Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request).
355-
* @param httpMethod the HTTP method to check
356-
* @return true or false if HTTP request can contain the body
357-
*/
358-
protected boolean isReadable(HttpMethod httpMethod) {
359-
return !(CollectionUtils.containsInstance(NON_READABLE_BODY_HTTP_METHODS, httpMethod));
360-
}
361-
362354
protected void validate(Object value) {
363355
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(value, "requestPayload");
364356
ValidationUtils.invokeValidator(this.validator, value, errors);
@@ -367,4 +359,13 @@ protected void validate(Object value) {
367359
}
368360
}
369361

362+
/**
363+
* Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request).
364+
* @param httpMethod the HTTP method to check
365+
* @return true or false if HTTP request can contain the body
366+
*/
367+
protected static boolean isReadable(@Nullable HttpMethod httpMethod) {
368+
return !(CollectionUtils.containsInstance(NON_READABLE_BODY_HTTP_METHODS, httpMethod));
369+
}
370+
370371
}

spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ public ExpressionEvaluatingParameterSourceFactory(@Nullable BeanFactory beanFact
6868
*/
6969
public void setParameters(List<JpaParameter> parameters) {
7070
Assert.notEmpty(parameters, "parameters must not be null or empty.");
71-
72-
for (JpaParameter parameter : parameters) {
73-
Assert.notNull(parameter, "The provided list (parameters) cannot contain null values.");
74-
}
71+
Assert.noNullElements(parameters, "The provided list (parameters) cannot contain null values.");
7572

7673
this.parameters.addAll(parameters);
7774
this.expressionEvaluator.getEvaluationContext().setVariable("staticParameters",
@@ -108,12 +105,11 @@ protected ExpressionEvaluatingParameterSource(Object input, List<JpaParameter> p
108105
this.parametersMap.put(parameter.getName(), parameter);
109106
}
110107
this.values.putAll(ExpressionEvaluatingParameterSourceUtils.convertStaticParameters(parameters));
111-
112108
}
113109

114110
@Override
111+
@Nullable
115112
public Object getValueByPosition(int position) {
116-
117113
Assert.isTrue(position >= 0, "The position must be non-negative.");
118114

119115
if (position <= this.parameters.size()) {
@@ -148,10 +144,10 @@ public Object getValueByPosition(int position) {
148144
}
149145

150146
return null;
151-
152147
}
153148

154149
@Override
150+
@Nullable
155151
public Object getValue(String paramName) {
156152
if (this.values.containsKey(paramName)) {
157153
return this.values.get(paramName);

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpoint.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,14 @@ private Mono<Void> doHandle(ServerWebExchange exchange) {
167167
}
168168

169169
private Mono<?> extractRequestBody(ServerWebExchange exchange) {
170-
if (isReadable(exchange.getRequest().getMethod())) {
170+
ServerHttpRequest request = exchange.getRequest();
171+
if (isReadable(request.getMethod())) {
171172
return extractReadableRequestBody(exchange)
172173
.cast(Object.class)
173-
.switchIfEmpty(queryParams(exchange));
174+
.switchIfEmpty(queryParams(request));
174175
}
175176
else {
176-
return queryParams(exchange);
177+
return queryParams(request);
177178
}
178179
}
179180

@@ -515,8 +516,8 @@ private static List<MediaType> getProducibleTypes(ServerWebExchange exchange,
515516
return (mediaTypes != null ? new ArrayList<>(mediaTypes) : producibleTypesSupplier.get());
516517
}
517518

518-
private static Mono<?> queryParams(ServerWebExchange exchange) {
519-
return Mono.just(exchange.getRequest().getQueryParams());
519+
private static Mono<?> queryParams(ServerHttpRequest request) {
520+
return Mono.just(request.getQueryParams());
520521
}
521522

522523
private static MediaType selectMoreSpecificMediaType(MediaType acceptable, MediaType producible) {

0 commit comments

Comments
 (0)