INT-3626: More Sonar Fixes
JIRA: https://jira.spring.io/browse/INT-3626 Remove Direct Array Usages. With the increased use of java configuration and DSL, it is no longer safe to directly use array arguments. (Except in simple wrapper objects). Avoid (or mark //NOSONAR) catch Throwable. Remove unused field.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 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. You may obtain a copy of the License at
|
||||
@@ -31,10 +31,11 @@ public class SequenceNumberComparator implements Comparator<Message<?>> {
|
||||
* doesn't then the numbered message comes first, or finally of neither has a sequence number then they are equal in
|
||||
* rank.
|
||||
*/
|
||||
@Override
|
||||
public int compare(Message<?> o1, Message<?> o2) {
|
||||
Integer sequenceNumber1 = new IntegrationMessageHeaderAccessor(o1).getSequenceNumber();
|
||||
Integer sequenceNumber2 = new IntegrationMessageHeaderAccessor(o2).getSequenceNumber();
|
||||
if (sequenceNumber1 == sequenceNumber2) {
|
||||
if (sequenceNumber1 == sequenceNumber2) {//NOSONAR - early exit optimization
|
||||
return 0;
|
||||
}
|
||||
if (sequenceNumber1 == null) {
|
||||
|
||||
@@ -142,7 +142,7 @@ public class MessagePublishingInterceptor implements MethodInterceptor, BeanFact
|
||||
context.setVariable(PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME, returnValue);
|
||||
return returnValue;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable t) {//NOSONAR - rethrown below
|
||||
context.setVariable(PublisherMetadataSource.EXCEPTION_VARIABLE_NAME, t);
|
||||
throw t;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -396,7 +396,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
try {
|
||||
interceptor.afterSendCompletion(message, channel, sent, ex);
|
||||
}
|
||||
catch (Throwable ex2) {
|
||||
catch (Exception ex2) {
|
||||
logger.error("Exception from afterSendCompletion in " + interceptor, ex2);
|
||||
}
|
||||
}
|
||||
@@ -443,7 +443,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
try {
|
||||
interceptor.afterReceiveCompletion(message, channel, ex);
|
||||
}
|
||||
catch (Throwable ex2) {
|
||||
catch (Exception ex2) {
|
||||
logger.error("Exception from afterReceiveCompletion in " + interceptor, ex2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -67,6 +67,7 @@ public class MessagePublishingErrorHandler implements ErrorHandler, BeanFactoryA
|
||||
this.sendTimeout = sendTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
Assert.notNull(beanFactory, "beanFactory must not be null");
|
||||
if (this.channelResolver == null) {
|
||||
@@ -74,6 +75,7 @@ public class MessagePublishingErrorHandler implements ErrorHandler, BeanFactoryA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void handleError(Throwable t) {
|
||||
MessageChannel errorChannel = this.resolveErrorChannel(t);
|
||||
boolean sent = false;
|
||||
@@ -86,10 +88,14 @@ public class MessagePublishingErrorHandler implements ErrorHandler, BeanFactoryA
|
||||
sent = errorChannel.send(new ErrorMessage(t));
|
||||
}
|
||||
}
|
||||
catch (Throwable errorDeliveryError) { // message will be logged only
|
||||
catch (Throwable errorDeliveryError) {//NOSONAR
|
||||
// message will be logged only
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Error message was not delivered.", errorDeliveryError);
|
||||
}
|
||||
if (errorDeliveryError instanceof Error) {
|
||||
throw ((Error) errorDeliveryError);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!sent && logger.isErrorEnabled()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.channel.interceptor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -23,6 +25,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
public class GlobalChannelInterceptorWrapper implements Ordered {
|
||||
@@ -59,7 +62,7 @@ public class GlobalChannelInterceptorWrapper implements Ordered {
|
||||
}
|
||||
|
||||
public void setPatterns(String[] patterns) {
|
||||
this.patterns = patterns;
|
||||
this.patterns = Arrays.copyOf(patterns, patterns.length);
|
||||
}
|
||||
|
||||
public String[] getPatterns() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -115,7 +115,7 @@ public class MethodInvokingMessageSource extends AbstractMessageSource<Object>
|
||||
}
|
||||
return ReflectionUtils.invokeMethod(this.method, this.object);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
catch (Exception e) {
|
||||
throw new MessagingException("Failed to invoke method", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,6 @@ import java.util.concurrent.Future;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import reactor.core.Environment;
|
||||
import reactor.core.composable.Promise;
|
||||
import reactor.core.composable.spec.Promises;
|
||||
import reactor.function.Functions;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.SimpleTypeConverter;
|
||||
@@ -68,6 +63,11 @@ import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import reactor.core.Environment;
|
||||
import reactor.core.composable.Promise;
|
||||
import reactor.core.composable.spec.Promises;
|
||||
import reactor.function.Functions;
|
||||
|
||||
/**
|
||||
* Generates a proxy for the provided service interface to enable interaction
|
||||
* with messaging components without application code being aware of them allowing
|
||||
@@ -373,7 +373,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
|
||||
try {
|
||||
return this.invokeGatewayMethod(invocation);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
catch (Throwable e) {//NOSONAR - ok to catch, rethrown below
|
||||
this.rethrowExceptionCauseIfPossible(e, invocation.getMethod());
|
||||
return null; // preceding call should always throw something
|
||||
}
|
||||
@@ -638,7 +638,10 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
|
||||
try {
|
||||
return doInvoke(this.invocation);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Error e) {//NOSONAR
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable t) {//NOSONAR
|
||||
if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException) t;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -34,9 +34,9 @@ public final class MethodArgsHolder {
|
||||
|
||||
private final Object[] args;
|
||||
|
||||
public MethodArgsHolder(Method method, Object[] args) {
|
||||
public MethodArgsHolder(Method method, Object[] args) {//NOSONAR - direct storage
|
||||
this.method = method;
|
||||
this.args = args;
|
||||
this.args = args;//NOSONAR - direct storage
|
||||
}
|
||||
|
||||
public final Method getMethod() {
|
||||
@@ -44,7 +44,7 @@ public final class MethodArgsHolder {
|
||||
}
|
||||
|
||||
public final Object[] getArgs() {
|
||||
return args;
|
||||
return args;//NOSONAR - direct access
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -67,7 +67,7 @@ public abstract class AbstractMessageHandler extends IntegrationObjectSupport im
|
||||
@Override
|
||||
public final void handleMessage(Message<?> message) {
|
||||
Assert.notNull(message, "Message must not be null");
|
||||
Assert.notNull(message.getPayload(), "Message payload must not be null");
|
||||
Assert.notNull(message.getPayload(), "Message payload must not be null");//NOSONAR - false positive
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug(this + " received message: " + message);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -73,10 +73,10 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp
|
||||
try {
|
||||
return invocation.proceed();
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e) {//NOSONAR - catch necessary so we can wrap Errors
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
catch (Throwable e) {//NOSONAR - ok to catch; unwrapped and rethrown below
|
||||
throw new ThrowableHolderException(e);
|
||||
}
|
||||
}
|
||||
@@ -97,10 +97,10 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp
|
||||
" so please raise an issue if you see this exception");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e) {//NOSONAR - catch necessary so we can wrap Errors
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
catch (Throwable e) {//NOSONAR - ok to catch; unwrapped and rethrown below
|
||||
throw new ThrowableHolderException(e);
|
||||
}
|
||||
}
|
||||
@@ -132,10 +132,9 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp
|
||||
*/
|
||||
protected Exception unwrapExceptionIfNecessary(Exception e) {
|
||||
Exception actualException = e;
|
||||
if (e instanceof ThrowableHolderException) {
|
||||
if (e.getCause() instanceof Exception) {
|
||||
actualException = (Exception) e.getCause();
|
||||
}
|
||||
if (e instanceof ThrowableHolderException
|
||||
&& e.getCause() instanceof Exception) {
|
||||
actualException = (Exception) e.getCause();
|
||||
}
|
||||
return actualException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -26,9 +26,10 @@ import org.springframework.util.ErrorHandler;
|
||||
* A {@link TaskExecutor} implementation that wraps an existing Executor
|
||||
* instance in order to catch any exceptions. If an exception is thrown, it
|
||||
* will be handled by the provided {@link ErrorHandler}.
|
||||
*
|
||||
*
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class ErrorHandlingTaskExecutor implements TaskExecutor {
|
||||
|
||||
@@ -45,13 +46,15 @@ public class ErrorHandlingTaskExecutor implements TaskExecutor {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(final Runnable task) {
|
||||
this.executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
task.run();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable t) {//NOSONAR
|
||||
errorHandler.handleError(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -36,6 +36,7 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.annotation.Gateway;
|
||||
import org.springframework.integration.annotation.GatewayHeader;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -87,6 +88,34 @@ public class AsyncGatewayTests {
|
||||
assertEquals("foobar", ((Message<?>) result).getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void futureWithError() throws Exception {
|
||||
final Error error = new Error("error");
|
||||
DirectChannel channel = new DirectChannel() {
|
||||
|
||||
@Override
|
||||
protected boolean doSend(Message<?> message, long timeout) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
};
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setDefaultRequestChannel(channel);
|
||||
proxyFactory.setServiceInterface(TestEchoService.class);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.setBeanFactory(mock(BeanFactory.class));
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestEchoService service = (TestEchoService) proxyFactory.getObject();
|
||||
Future<Message<?>> f = service.returnMessage("foo");
|
||||
try {
|
||||
f.get(1000, TimeUnit.MILLISECONDS);
|
||||
fail("Expected Exception");
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
assertEquals(error, e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenableFutureWithMessageReturned() throws Exception {
|
||||
QueueChannel requestChannel = new QueueChannel();
|
||||
|
||||
Reference in New Issue
Block a user