JDBC, JMS, JPA Sonar fixes

This commit is contained in:
Gary Russell
2018-10-26 14:26:43 -04:00
parent 1e66b6b55d
commit 2b9ba714e6
7 changed files with 29 additions and 17 deletions

View File

@@ -702,7 +702,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint
* @return the error message.
* @since 4.3.10
*/
protected final ErrorMessage buildErrorMessage(Message<?> requestMessage, Throwable throwable) {
protected final ErrorMessage buildErrorMessage(@Nullable Message<?> requestMessage, Throwable throwable) {
return this.errorMessageStrategy.buildErrorMessage(throwable, getErrorMessageAttributes(requestMessage));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.integration.support.DefaultMessageBuilderFactory;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
@@ -63,7 +64,7 @@ public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, I
* Specify a BeanFactory in order to enable resolution via <code>@beanName</code> in the expression.
*/
@Override
public void setBeanFactory(final BeanFactory beanFactory) {
public void setBeanFactory(final @Nullable BeanFactory beanFactory) {
if (beanFactory != null) {
this.beanFactory = beanFactory;
this.typeConverter.setBeanFactory(beanFactory);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcCallOperations;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedMetric;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
@@ -282,7 +283,7 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean {
* @return Map containing the stored procedure results if any.
*/
public Map<String, Object> executeStoredProcedure() {
return executeStoredProcedureInternal(new Object(), this.evaluateExpression(null));
return executeStoredProcedureInternal(new Object(), evaluateExpression(null));
}
/**
@@ -311,9 +312,10 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean {
}
private String evaluateExpression(Message<?> message) {
final String storedProcedureNameToUse = this.storedProcedureNameExpression.getValue(this.evaluationContext,
message, String.class);
private String evaluateExpression(@Nullable Message<?> message) {
final String storedProcedureNameToUse = message == null
? this.storedProcedureNameExpression.getValue(this.evaluationContext, String.class)
: this.storedProcedureNameExpression.getValue(this.evaluationContext, message, String.class);
Assert.hasText(storedProcedureNameToUse, String.format(
"Unable to resolve Stored Procedure/Function name for the provided Expression '%s'.",

View File

@@ -1416,11 +1416,11 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp
if (logger.isWarnEnabled()) {
logger.warn("Unexpected error obtaining destination description: " + e.getMessage());
}
return null;
return "";
}
}
else {
return null;
return "";
}
}

View File

@@ -22,6 +22,7 @@ import javax.jms.Destination;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.lang.Nullable;
/**
* Factory class for JMS components.
@@ -48,7 +49,9 @@ public final class Jms {
* @param connectionFactory the JMS ConnectionFactory to build on
* @return the {@link JmsPollableMessageChannelSpec} instance
*/
public static JmsPollableMessageChannelSpec<?> pollableChannel(String id, ConnectionFactory connectionFactory) {
public static JmsPollableMessageChannelSpec<?> pollableChannel(@Nullable String id,
ConnectionFactory connectionFactory) {
return new JmsPollableMessageChannelSpec<>(connectionFactory).id(id);
}
@@ -67,7 +70,7 @@ public final class Jms {
* @param connectionFactory the JMS ConnectionFactory to build on
* @return the {@link JmsMessageChannelSpec} instance
*/
public static JmsMessageChannelSpec<?> channel(String id, ConnectionFactory connectionFactory) {
public static JmsMessageChannelSpec<?> channel(@Nullable String id, ConnectionFactory connectionFactory) {
return new JmsMessageChannelSpec<>(connectionFactory)
.id(id);
}
@@ -87,7 +90,7 @@ public final class Jms {
* @param connectionFactory the JMS ConnectionFactory to build on
* @return the {@link JmsPublishSubscribeMessageChannelSpec} instance
*/
public static JmsPublishSubscribeMessageChannelSpec publishSubscribeChannel(String id,
public static JmsPublishSubscribeMessageChannelSpec publishSubscribeChannel(@Nullable String id,
ConnectionFactory connectionFactory) {
return new JmsPublishSubscribeMessageChannelSpec(connectionFactory).id(id);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.integration.jpa.support;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -59,7 +60,7 @@ public class JpaParameter {
* @param value If null, the expression property must be set
* @param expression If null, the value property must be set
*/
public JpaParameter(String name, Object value, String expression) {
public JpaParameter(String name, @Nullable Object value, @Nullable String expression) {
super();
Assert.hasText(name, "'name' must not be empty.");
@@ -76,7 +77,7 @@ public class JpaParameter {
* @param value If null, the expression property must be set
* @param expression If null, the value property must be set
*/
public JpaParameter(Object value, String expression) {
public JpaParameter(@Nullable Object value, @Nullable String expression) {
this.value = value;
this.setExpression(expression);
}

View File

@@ -30,6 +30,7 @@ import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionException;
import org.springframework.integration.jpa.support.JpaParameter;
import org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceUtils.ParameterExpressionEvaluator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -55,7 +56,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
this(null);
}
public ExpressionEvaluatingParameterSourceFactory(BeanFactory beanFactory) {
public ExpressionEvaluatingParameterSourceFactory(@Nullable BeanFactory beanFactory) {
this.parameters = new ArrayList<>();
this.expressionEvaluator.setBeanFactory(beanFactory);
}
@@ -78,6 +79,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
}
@Override
public PositionSupportingParameterSource createParameterSource(final Object input) {
return new ExpressionEvaluatingParameterSource(input, this.parameters, this.expressionEvaluator);
}
@@ -109,6 +111,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
}
@Override
public Object getValueByPosition(int position) {
Assert.isTrue(position >= 0, "The position must be non-negative.");
@@ -148,6 +151,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
}
@Override
public Object getValue(String paramName) {
if (this.values.containsKey(paramName)) {
return this.values.get(paramName);
@@ -178,6 +182,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
return value;
}
@Override
public boolean hasValue(String paramName) {
try {
final Object value = getValue(paramName);