Sonar fixes
* exposing internal objects * boolean complexity * names, methods with _ * missing `default` in switch * lost stack trace * unnecessary null check before instanceof * unused parameter * Fix method name
This commit is contained in:
committed by
Artem Bilan
parent
9780a6c893
commit
ebbcb9df48
@@ -65,7 +65,7 @@ public class MessageGroupExpiredEvent extends IntegrationEvent {
|
||||
}
|
||||
|
||||
public Date getExpired() {
|
||||
return this.expired;
|
||||
return (Date) this.expired.clone();
|
||||
}
|
||||
|
||||
public boolean isDiscarded() {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class GlobalChannelInterceptorWrapper implements Ordered {
|
||||
}
|
||||
|
||||
public String[] getPatterns() {
|
||||
return this.patterns;
|
||||
return this.patterns; // NOSONAR - expose internals
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -132,9 +132,13 @@ public class FilterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
@Override
|
||||
protected boolean canBeUsedDirect(AbstractMessageProducingHandler handler) {
|
||||
return handler instanceof MessageFilter
|
||||
|| (!(handler instanceof MessageSelector)
|
||||
&& this.discardChannel == null && this.throwExceptionOnRejection == null
|
||||
&& this.discardWithinAdvice == null);
|
||||
|| (!(handler instanceof MessageSelector) && noFilterAttributesProvided());
|
||||
}
|
||||
|
||||
private boolean noFilterAttributesProvided() {
|
||||
return this.discardChannel == null
|
||||
&& this.throwExceptionOnRejection == null
|
||||
&& this.discardWithinAdvice == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -152,7 +152,7 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
}
|
||||
|
||||
protected boolean noRouterAttributesProvided() {
|
||||
return this.channelMappings == null && this.defaultOutputChannel == null
|
||||
return this.channelMappings == null && this.defaultOutputChannel == null // NOSONAR boolean complexity
|
||||
&& getSendTimeout() == null && this.resolutionRequired == null && this.applySequence == null
|
||||
&& this.ignoreSendFailures == null;
|
||||
}
|
||||
|
||||
@@ -395,9 +395,12 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
|
||||
String receiveTimeout = this.beanFactory.resolveEmbeddedValue(poller.receiveTimeout());
|
||||
|
||||
if (StringUtils.hasText(ref)) {
|
||||
Assert.state(!StringUtils.hasText(triggerRef) && !StringUtils.hasText(executorRef) &&
|
||||
!StringUtils.hasText(cron) && !StringUtils.hasText(fixedDelayValue) &&
|
||||
!StringUtils.hasText(fixedRateValue) && !StringUtils.hasText(maxMessagesPerPollValue),
|
||||
Assert.state(!StringUtils.hasText(triggerRef)
|
||||
&& !StringUtils.hasText(executorRef)
|
||||
&& !StringUtils.hasText(cron)
|
||||
&& !StringUtils.hasText(fixedDelayValue)
|
||||
&& !StringUtils.hasText(fixedRateValue)
|
||||
&& !StringUtils.hasText(maxMessagesPerPollValue), // NOSONAR boolean complexity
|
||||
"The '@Poller' 'ref' attribute is mutually exclusive with other attributes.");
|
||||
pollerMetadata = this.beanFactory.getBean(ref, PollerMetadata.class);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class RouterAnnotationPostProcessor extends AbstractMethodAnnotationPostP
|
||||
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
|
||||
String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, "ignoreSendFailures",
|
||||
String.class);
|
||||
return StringUtils.hasText(defaultOutputChannel) || !ObjectUtils.isEmpty(channelMappings)
|
||||
return StringUtils.hasText(defaultOutputChannel) || !ObjectUtils.isEmpty(channelMappings) // NOSONAR complexity
|
||||
|| StringUtils.hasText(prefix) || StringUtils.hasText(suffix) || StringUtils.hasText(resolutionRequired)
|
||||
|| StringUtils.hasText(applySequence) || StringUtils.hasText(ignoreSendFailures);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class AbstractInboundGatewayParser extends AbstractSimpleBeanDef
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !attributeName.equals("name") && !attributeName.equals("request-channel")
|
||||
return !attributeName.equals("name") && !attributeName.equals("request-channel") // NOSONAR boolean complexity
|
||||
&& !attributeName.equals("error-channel")
|
||||
&& !attributeName.equals("reply-channel") && super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@@ -65,16 +65,16 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh
|
||||
boolean hasExpressionElement = expressionElement != null;
|
||||
boolean hasMethod = StringUtils.hasText(methodName);
|
||||
|
||||
if (!hasInnerDef && !hasRef && !hasExpression && !hasScriptElement && !hasExpressionElement) {
|
||||
if (!hasInnerDef && !hasRef && !hasExpression && !hasScriptElement && !hasExpressionElement) { // NOSONAR
|
||||
parserContext.getReaderContext().error(
|
||||
"Exactly one of the 'ref', 'expression', inner bean, <script> or <expression> is required.", element);
|
||||
"Exactly one of the 'ref', 'expression', inner bean, <script> or <expression> is required.", element);
|
||||
}
|
||||
|
||||
if (hasInnerDef) {
|
||||
if (hasRef || hasExpression) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Neither 'ref' nor 'expression' are permitted when an inner bean (<bean/>) is configured on element " +
|
||||
IntegrationNamespaceUtils.createElementDescription(element) + ".", source);
|
||||
"Neither 'ref' nor 'expression' are permitted when an inner bean (<bean/>) is configured on "
|
||||
+ "element " + IntegrationNamespaceUtils.createElementDescription(element) + ".", source);
|
||||
return null;
|
||||
}
|
||||
if (hasMethod) {
|
||||
@@ -87,8 +87,9 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh
|
||||
else if (hasScriptElement) {
|
||||
if (hasRef || hasMethod || hasExpression) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Neither 'ref' and 'method' nor 'expression' are permitted when an inner script element is configured on element " +
|
||||
IntegrationNamespaceUtils.createElementDescription(element) + ".", source);
|
||||
"Neither 'ref' and 'method' nor 'expression' are permitted when an inner script element is "
|
||||
+ "configured on element "
|
||||
+ IntegrationNamespaceUtils.createElementDescription(element) + ".", source);
|
||||
return null;
|
||||
}
|
||||
BeanDefinition scriptBeanDefinition = parserContext.getDelegate().parseCustomElement(scriptElement);
|
||||
@@ -101,7 +102,8 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh
|
||||
else if (hasExpression || hasExpressionElement) {
|
||||
if (hasRef || hasMethod) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The 'ref' and 'method' attributes can't be used with 'expression' attribute or inner <expression>.", element);
|
||||
"The 'ref' and 'method' attributes can't be used with 'expression' attribute or inner "
|
||||
+ "<expression>.", element);
|
||||
return null;
|
||||
}
|
||||
if (hasExpression & hasExpressionElement) {
|
||||
@@ -124,9 +126,11 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh
|
||||
return result;
|
||||
}
|
||||
|
||||
private BeanMetadataElement parseMethodInvokingSource(BeanMetadataElement targetObject, String methodName, Element element,
|
||||
ParserContext parserContext) {
|
||||
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingMessageSource.class);
|
||||
private BeanMetadataElement parseMethodInvokingSource(BeanMetadataElement targetObject, String methodName,
|
||||
Element element, ParserContext parserContext) {
|
||||
|
||||
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(MethodInvokingMessageSource.class);
|
||||
sourceBuilder.addPropertyValue("object", targetObject);
|
||||
sourceBuilder.addPropertyValue("methodName", methodName);
|
||||
this.parseHeaderExpressions(sourceBuilder, element, parserContext);
|
||||
@@ -135,7 +139,9 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh
|
||||
|
||||
private BeanMetadataElement parseExpression(String expressionString, Element expressionElement, Element element,
|
||||
ParserContext parserContext) {
|
||||
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionEvaluatingMessageSource.class);
|
||||
|
||||
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(ExpressionEvaluatingMessageSource.class);
|
||||
|
||||
BeanDefinition expressionDef = null;
|
||||
|
||||
@@ -166,8 +172,9 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh
|
||||
ManagedMap<String, Object> headerExpressions = new ManagedMap<String, Object>();
|
||||
for (Element headerElement : headerElements) {
|
||||
String headerName = headerElement.getAttribute("name");
|
||||
BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value",
|
||||
"expression", parserContext, headerElement, true);
|
||||
BeanDefinition expressionDef = IntegrationNamespaceUtils
|
||||
.createExpressionDefinitionFromValueOrExpression("value",
|
||||
"expression", parserContext, headerElement, true);
|
||||
headerExpressions.put(headerName, expressionDef);
|
||||
}
|
||||
builder.addPropertyValue("headerExpressions", headerExpressions);
|
||||
|
||||
@@ -60,23 +60,24 @@ public class IdempotentReceiverInterceptorParser extends AbstractBeanDefinitionP
|
||||
|
||||
String endpoints = element.getAttribute("endpoint");
|
||||
|
||||
if (!hasSelector & !(hasKeyStrategy | hasKeyExpression)) {
|
||||
if (!hasSelector && !(hasKeyStrategy || hasKeyExpression)) {
|
||||
parserContext.getReaderContext().error("One of the 'selector', 'key-strategy' or 'key-expression' " +
|
||||
"attributes must be provided", source);
|
||||
}
|
||||
|
||||
if (hasSelector & (hasStore | hasKeyStrategy | hasKeyExpression | hasValueStrategy | hasValueExpression)) {
|
||||
if (hasSelector && (hasStore || hasKeyStrategy || hasKeyExpression || hasValueStrategy // NOSONAR complexity
|
||||
|| hasValueExpression)) {
|
||||
parserContext.getReaderContext().error("The 'selector' attribute is mutually exclusive with " +
|
||||
"'metadata-store', 'key-strategy', 'key-expression', 'value-strategy' " +
|
||||
"or 'value-expression'", source);
|
||||
}
|
||||
|
||||
if (hasKeyStrategy & hasKeyExpression) {
|
||||
if (hasKeyStrategy && hasKeyExpression) {
|
||||
parserContext.getReaderContext().error("The 'key-strategy' and 'key-expression' attributes " +
|
||||
"are mutually exclusive", source);
|
||||
}
|
||||
|
||||
if (hasValueStrategy & hasValueExpression) {
|
||||
if (hasValueStrategy && hasValueExpression) {
|
||||
parserContext.getReaderContext().error("The 'value-strategy' and 'value-expression' attributes " +
|
||||
"are mutually exclusive", source);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ public class AggregateMessageDeliveryException extends MessageDeliveryException
|
||||
@Override
|
||||
public String getMessage() {
|
||||
String baseMessage = super.getMessage();
|
||||
StringBuilder message = new StringBuilder(appendPeriodIfNecessary(baseMessage) + " Multiple causes:\n");
|
||||
StringBuilder message = new StringBuilder(appendPeriodIfNecessary(baseMessage))
|
||||
.append(" Multiple causes:\n");
|
||||
for (Exception exception : this.aggregatedExceptions) {
|
||||
message.append(" " + exception.getMessage() + "\n");
|
||||
}
|
||||
|
||||
@@ -3114,7 +3114,7 @@ public abstract class IntegrationFlowDefinition<B extends IntegrationFlowDefinit
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected final B _this() {
|
||||
protected final B _this() { // NOSONAR name
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,10 @@ class IntegrationFlowLifecycleAdvice implements MethodInterceptor {
|
||||
result = this.delegate.getPhase();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -547,10 +547,10 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
if (t instanceof RuntimeException
|
||||
if (t instanceof RuntimeException // NOSONAR boolean complexity
|
||||
&& !(t instanceof MessagingException)
|
||||
&& !(t instanceof UndeclaredThrowableException)
|
||||
&& !(t instanceof IllegalStateException && ("Unexpected exception thrown").equals(t.getMessage()))) {
|
||||
&& !(t instanceof IllegalStateException && "Unexpected exception thrown".equals(t.getMessage()))) {
|
||||
throw t;
|
||||
}
|
||||
t = t.getCause();
|
||||
|
||||
@@ -85,9 +85,9 @@ public class LoggingHandler extends AbstractMessageHandler {
|
||||
return Level.valueOf(level.toUpperCase());
|
||||
}
|
||||
catch (@SuppressWarnings("unused") IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException("Invalid log level '" + level
|
||||
throw new IllegalArgumentException("Invalid log level '" + level // NOSONAR lost stack trace
|
||||
+ "'. The (case-insensitive) supported values are: "
|
||||
+ StringUtils.arrayToCommaDelimitedString(Level.values())); // NOSONAR lost stack trace
|
||||
+ StringUtils.arrayToCommaDelimitedString(Level.values()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class AbstractHandleMessageAdvice extends IntegrationObjectSuppo
|
||||
Method method = invocation.getMethod();
|
||||
Object invocationThis = invocation.getThis();
|
||||
Object[] arguments = invocation.getArguments();
|
||||
boolean isMessageHandler = invocationThis != null && invocationThis instanceof MessageHandler;
|
||||
boolean isMessageHandler = invocationThis instanceof MessageHandler;
|
||||
boolean isMessageMethod = method.getName().equals("handleMessage")
|
||||
&& (arguments.length == 1 && arguments[0] instanceof Message);
|
||||
if (!isMessageHandler || !isMessageMethod) {
|
||||
@@ -59,6 +59,6 @@ public abstract class AbstractHandleMessageAdvice extends IntegrationObjectSuppo
|
||||
return doInvoke(invocation, message);
|
||||
}
|
||||
|
||||
protected abstract Object doInvoke(MethodInvocation invocation, Message<?> message) throws Throwable;
|
||||
protected abstract Object doInvoke(MethodInvocation invocation, Message<?> message) throws Throwable; // NOSONAR
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class JsonPropertyAccessor implements PropertyAccessor {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getSpecificTargetClasses() {
|
||||
return SUPPORTED_CLASSES;
|
||||
return SUPPORTED_CLASSES; // NOSONAR - expose internals
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MapBuilder<B extends MapBuilder<B, K, V>, K, V> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected final B _this() {
|
||||
protected final B _this() { // NOSONAR name
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class MutableMessage<T> implements Message<T>, Serializable {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj != null && obj instanceof MutableMessage<?>) {
|
||||
if (obj instanceof MutableMessage<?>) {
|
||||
MutableMessage<?> other = (MutableMessage<?>) obj;
|
||||
UUID thisId = this.headers.getId();
|
||||
UUID otherId = other.headers.getId();
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -260,7 +259,7 @@ public class EmbeddedJsonHeadersMessageMapper implements BytesMessageMapper {
|
||||
buffer.position(4);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> headers = this.objectMapper.readValue(bytes, buffer.position(), headersLen,
|
||||
HashMap.class);
|
||||
Map.class);
|
||||
|
||||
buffer.position(buffer.position() + headersLen);
|
||||
buffer.getInt();
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
|
||||
public class TransactionSynchronizationFactoryBean implements FactoryBean<DefaultTransactionSynchronizationFactory>,
|
||||
BeanFactoryAware {
|
||||
|
||||
private final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware
|
||||
if (sourceType != null) {
|
||||
Class<?> sourceClass = sourceType.getType();
|
||||
Class<?> targetClass = targetType.getType();
|
||||
if ((sourceClass == MessageHeaders.class && targetClass == MessageHeaders.class) ||
|
||||
if ((sourceClass == MessageHeaders.class && targetClass == MessageHeaders.class) || // NOSONAR
|
||||
(sourceClass == MessageHistory.class && targetClass == MessageHistory.class) ||
|
||||
(sourceType.isAssignableTo(targetType) && ClassUtils.isPrimitiveArray(sourceClass))) {
|
||||
return value;
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class MessagingAnnotationUtils {
|
||||
}
|
||||
|
||||
public static boolean hasValue(Object value) {
|
||||
return value != null && (!(value instanceof String) || (StringUtils.hasText((String) value)))
|
||||
return value != null && (!(value instanceof String) || (StringUtils.hasText((String) value))) // NOSONAR
|
||||
&& (!value.getClass().isArray() || ((Object[]) value).length > 0);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public final class MessagingAnnotationUtils {
|
||||
Annotation match = null;
|
||||
for (Annotation annotation : annotations) {
|
||||
Class<? extends Annotation> type = annotation.annotationType();
|
||||
if (type.equals(Payload.class)
|
||||
if (type.equals(Payload.class) // NOSONAR boolean complexity
|
||||
|| type.equals(Header.class)
|
||||
|| type.equals(Headers.class)
|
||||
|| (payloads && type.equals(Payloads.class))) {
|
||||
|
||||
@@ -41,7 +41,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class EmbeddedJsonHeadersMessageMapperTests {
|
||||
|
||||
@Test
|
||||
public void testEmbedAll() throws Exception {
|
||||
public void testEmbedAll() {
|
||||
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper();
|
||||
GenericMessage<String> message = new GenericMessage<>("foo");
|
||||
assertThat(mapper.toMessage(mapper.fromMessage(message))).isEqualTo(message);
|
||||
@@ -92,7 +92,7 @@ public class EmbeddedJsonHeadersMessageMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytesEmbedSome() throws Exception {
|
||||
public void testBytesEmbedSome() {
|
||||
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper("I*");
|
||||
GenericMessage<byte[]> message = new GenericMessage<>("foo".getBytes(), Collections.singletonMap("bar", "baz"));
|
||||
byte[] bytes = mapper.fromMessage(message);
|
||||
@@ -112,7 +112,7 @@ public class EmbeddedJsonHeadersMessageMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytesEmbedAllJson() throws Exception {
|
||||
public void testBytesEmbedAllJson() {
|
||||
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper();
|
||||
mapper.setRawBytes(false);
|
||||
GenericMessage<byte[]> message = new GenericMessage<>("foo".getBytes());
|
||||
@@ -126,7 +126,7 @@ public class EmbeddedJsonHeadersMessageMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytesDecodeAll() throws Exception {
|
||||
public void testBytesDecodeAll() {
|
||||
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper();
|
||||
GenericMessage<byte[]> message = new GenericMessage<>("foo".getBytes());
|
||||
Message<?> decoded = mapper.toMessage(mapper.fromMessage(message));
|
||||
|
||||
Reference in New Issue
Block a user