Skip to content

Commit 2b9ba71

Browse files
committed
JDBC, JMS, JPA Sonar fixes
1 parent 1e66b6b commit 2b9ba71

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ else if (headerValue instanceof String) {
702702
* @return the error message.
703703
* @since 4.3.10
704704
*/
705-
protected final ErrorMessage buildErrorMessage(Message<?> requestMessage, Throwable throwable) {
705+
protected final ErrorMessage buildErrorMessage(@Nullable Message<?> requestMessage, Throwable throwable) {
706706
return this.errorMessageStrategy.buildErrorMessage(throwable, getErrorMessageAttributes(requestMessage));
707707
}
708708

spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java

Lines changed: 3 additions & 2 deletions
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.
@@ -33,6 +33,7 @@
3333
import org.springframework.integration.support.DefaultMessageBuilderFactory;
3434
import org.springframework.integration.support.MessageBuilderFactory;
3535
import org.springframework.integration.support.utils.IntegrationUtils;
36+
import org.springframework.lang.Nullable;
3637
import org.springframework.messaging.Message;
3738
import org.springframework.messaging.MessageHandlingException;
3839

@@ -63,7 +64,7 @@ public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, I
6364
* Specify a BeanFactory in order to enable resolution via <code>@beanName</code> in the expression.
6465
*/
6566
@Override
66-
public void setBeanFactory(final BeanFactory beanFactory) {
67+
public void setBeanFactory(final @Nullable BeanFactory beanFactory) {
6768
if (beanFactory != null) {
6869
this.beanFactory = beanFactory;
6970
this.typeConverter.setBeanFactory(beanFactory);

spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcExecutor.java

Lines changed: 7 additions & 5 deletions
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.
@@ -48,6 +48,7 @@
4848
import org.springframework.jmx.export.annotation.ManagedAttribute;
4949
import org.springframework.jmx.export.annotation.ManagedMetric;
5050
import org.springframework.jmx.export.annotation.ManagedResource;
51+
import org.springframework.lang.Nullable;
5152
import org.springframework.messaging.Message;
5253
import org.springframework.messaging.MessageHeaders;
5354
import org.springframework.util.Assert;
@@ -282,7 +283,7 @@ private SimpleJdbcCall createSimpleJdbcCall(String storedProcedureName) {
282283
* @return Map containing the stored procedure results if any.
283284
*/
284285
public Map<String, Object> executeStoredProcedure() {
285-
return executeStoredProcedureInternal(new Object(), this.evaluateExpression(null));
286+
return executeStoredProcedureInternal(new Object(), evaluateExpression(null));
286287
}
287288

288289
/**
@@ -311,9 +312,10 @@ public Map<String, Object> executeStoredProcedure(Message<?> message) {
311312

312313
}
313314

314-
private String evaluateExpression(Message<?> message) {
315-
final String storedProcedureNameToUse = this.storedProcedureNameExpression.getValue(this.evaluationContext,
316-
message, String.class);
315+
private String evaluateExpression(@Nullable Message<?> message) {
316+
final String storedProcedureNameToUse = message == null
317+
? this.storedProcedureNameExpression.getValue(this.evaluationContext, String.class)
318+
: this.storedProcedureNameExpression.getValue(this.evaluationContext, message, String.class);
317319

318320
Assert.hasText(storedProcedureNameToUse, String.format(
319321
"Unable to resolve Stored Procedure/Function name for the provided Expression '%s'.",

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,11 +1416,11 @@ else if (super.getDestination() != null) {
14161416
if (logger.isWarnEnabled()) {
14171417
logger.warn("Unexpected error obtaining destination description: " + e.getMessage());
14181418
}
1419-
return null;
1419+
return "";
14201420
}
14211421
}
14221422
else {
1423-
return null;
1423+
return "";
14241424
}
14251425
}
14261426

spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.jms.core.JmsTemplate;
2323
import org.springframework.jms.listener.AbstractMessageListenerContainer;
2424
import org.springframework.jms.listener.DefaultMessageListenerContainer;
25+
import org.springframework.lang.Nullable;
2526

2627
/**
2728
* Factory class for JMS components.
@@ -48,7 +49,9 @@ public static JmsPollableMessageChannelSpec<?> pollableChannel(ConnectionFactory
4849
* @param connectionFactory the JMS ConnectionFactory to build on
4950
* @return the {@link JmsPollableMessageChannelSpec} instance
5051
*/
51-
public static JmsPollableMessageChannelSpec<?> pollableChannel(String id, ConnectionFactory connectionFactory) {
52+
public static JmsPollableMessageChannelSpec<?> pollableChannel(@Nullable String id,
53+
ConnectionFactory connectionFactory) {
54+
5255
return new JmsPollableMessageChannelSpec<>(connectionFactory).id(id);
5356
}
5457

@@ -67,7 +70,7 @@ public static JmsMessageChannelSpec<?> channel(ConnectionFactory connectionFacto
6770
* @param connectionFactory the JMS ConnectionFactory to build on
6871
* @return the {@link JmsMessageChannelSpec} instance
6972
*/
70-
public static JmsMessageChannelSpec<?> channel(String id, ConnectionFactory connectionFactory) {
73+
public static JmsMessageChannelSpec<?> channel(@Nullable String id, ConnectionFactory connectionFactory) {
7174
return new JmsMessageChannelSpec<>(connectionFactory)
7275
.id(id);
7376
}
@@ -87,7 +90,7 @@ public static JmsPublishSubscribeMessageChannelSpec publishSubscribeChannel(Conn
8790
* @param connectionFactory the JMS ConnectionFactory to build on
8891
* @return the {@link JmsPublishSubscribeMessageChannelSpec} instance
8992
*/
90-
public static JmsPublishSubscribeMessageChannelSpec publishSubscribeChannel(String id,
93+
public static JmsPublishSubscribeMessageChannelSpec publishSubscribeChannel(@Nullable String id,
9194
ConnectionFactory connectionFactory) {
9295

9396
return new JmsPublishSubscribeMessageChannelSpec(connectionFactory).id(id);

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

Lines changed: 4 additions & 3 deletions
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.
@@ -19,6 +19,7 @@
1919
import org.springframework.expression.Expression;
2020
import org.springframework.expression.ExpressionParser;
2121
import org.springframework.expression.spel.standard.SpelExpressionParser;
22+
import org.springframework.lang.Nullable;
2223
import org.springframework.util.Assert;
2324

2425
/**
@@ -59,7 +60,7 @@ public JpaParameter() {
5960
* @param value If null, the expression property must be set
6061
* @param expression If null, the value property must be set
6162
*/
62-
public JpaParameter(String name, Object value, String expression) {
63+
public JpaParameter(String name, @Nullable Object value, @Nullable String expression) {
6364
super();
6465

6566
Assert.hasText(name, "'name' must not be empty.");
@@ -76,7 +77,7 @@ public JpaParameter(String name, Object value, String expression) {
7677
* @param value If null, the expression property must be set
7778
* @param expression If null, the value property must be set
7879
*/
79-
public JpaParameter(Object value, String expression) {
80+
public JpaParameter(@Nullable Object value, @Nullable String expression) {
8081
this.value = value;
8182
this.setExpression(expression);
8283
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.expression.ExpressionException;
3131
import org.springframework.integration.jpa.support.JpaParameter;
3232
import org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceUtils.ParameterExpressionEvaluator;
33+
import org.springframework.lang.Nullable;
3334
import org.springframework.util.Assert;
3435

3536
/**
@@ -55,7 +56,7 @@ public ExpressionEvaluatingParameterSourceFactory() {
5556
this(null);
5657
}
5758

58-
public ExpressionEvaluatingParameterSourceFactory(BeanFactory beanFactory) {
59+
public ExpressionEvaluatingParameterSourceFactory(@Nullable BeanFactory beanFactory) {
5960
this.parameters = new ArrayList<>();
6061
this.expressionEvaluator.setBeanFactory(beanFactory);
6162
}
@@ -78,6 +79,7 @@ public void setParameters(List<JpaParameter> parameters) {
7879

7980
}
8081

82+
@Override
8183
public PositionSupportingParameterSource createParameterSource(final Object input) {
8284
return new ExpressionEvaluatingParameterSource(input, this.parameters, this.expressionEvaluator);
8385
}
@@ -109,6 +111,7 @@ protected ExpressionEvaluatingParameterSource(Object input, List<JpaParameter> p
109111

110112
}
111113

114+
@Override
112115
public Object getValueByPosition(int position) {
113116

114117
Assert.isTrue(position >= 0, "The position must be non-negative.");
@@ -148,6 +151,7 @@ public Object getValueByPosition(int position) {
148151

149152
}
150153

154+
@Override
151155
public Object getValue(String paramName) {
152156
if (this.values.containsKey(paramName)) {
153157
return this.values.get(paramName);
@@ -178,6 +182,7 @@ public Object getValue(String paramName) {
178182
return value;
179183
}
180184

185+
@Override
181186
public boolean hasValue(String paramName) {
182187
try {
183188
final Object value = getValue(paramName);

0 commit comments

Comments
 (0)