Skip to content

Commit

Permalink
Sonar Address new issues in LambdaMessageProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Nov 20, 2018
1 parent c9ae6c7 commit aa8068a
Showing 1 changed file with 22 additions and 17 deletions.
Expand Up @@ -47,7 +47,7 @@
*/
public class LambdaMessageProcessor implements MessageProcessor<Object>, BeanFactoryAware {

private static final Log logger = LogFactory.getLog(LambdaMessageProcessor.class);
private static final Log logger = LogFactory.getLog(LambdaMessageProcessor.class); // NOSONAR lower case static

private final Object target;

Expand Down Expand Up @@ -96,6 +96,26 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {

@Override
public Object processMessage(Message<?> message) {
Object[] args = buildArgs(message);

try {
return this.method.invoke(this.target, args);
}
catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ClassCastException) {
logger.error("Could not invoke the method due to a class cast exception, if using a lambda in the DSL, "
+ "consider using an overloaded EIP method that takes a Class<?> argument to explicitly "
+ "specify the type. An example of when this often occurs is if the lambda is configured to "
+ "receive a Message<?> argument.", e.getCause());
}
throw new MessageHandlingException(message, e.getCause());
}
catch (Exception e) {
throw new MessageHandlingException(message, e);
}
}

private Object[] buildArgs(Message<?> message) {
Object[] args = new Object[this.parameterTypes.length];
for (int i = 0; i < this.parameterTypes.length; i++) {
Class<?> parameterType = this.parameterTypes[i];
Expand Down Expand Up @@ -125,22 +145,7 @@ else if (Map.class.isAssignableFrom(parameterType)) {
}
}
}

try {
return this.method.invoke(this.target, args);
}
catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ClassCastException) {
logger.error("Could not invoke the method due to a class cast exception, if using a lambda in the DSL, "
+ "consider using an overloaded EIP method that takes a Class<?> argument to explicitly "
+ "specify the type. An example of when this often occurs is if the lambda is configured to "
+ "receive a Message<?> argument.", e.getCause());
}
throw new MessageHandlingException(message, e.getCause());
}
catch (Exception e) {
throw new MessageHandlingException(message, e);
}
return args;
}

}

0 comments on commit aa8068a

Please sign in to comment.