diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/FixedMethodFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/util/FixedMethodFilter.java index ee3455270e..427fe727bc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/FixedMethodFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/FixedMethodFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2013 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. @@ -17,6 +17,7 @@ package org.springframework.integration.util; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -28,8 +29,9 @@ import org.springframework.util.Assert; * the same Method instance within a single-element list if it is * present in the candidate list. If the Method is not present * in the candidate list, it will return an empty list. - * + * * @author Mark Fisher + * @author Gary Russell * @since 2.0 */ public class FixedMethodFilter implements MethodFilter { @@ -45,7 +47,9 @@ public class FixedMethodFilter implements MethodFilter { public List filter(List methods) { if (methods != null && methods.contains(this.method)) { - return Collections.singletonList(this.method); + List filteredList = new ArrayList(1); + filteredList.add(this.method); + return filteredList; } return Collections.emptyList(); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java index 2dbfecc3ce..6b078bf311 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java @@ -28,10 +28,11 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; import org.junit.Rule; import org.junit.Test; -import org.hamcrest.TypeSafeMatcher; import org.junit.rules.ExpectedException; +import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.integration.Message; import org.springframework.integration.MessageHandlingException; import org.springframework.integration.annotation.Header; @@ -300,6 +301,15 @@ public class MethodInvokingMessageProcessorTests { assertEquals("foo", processor.processMessage(new GenericMessage("foo"))); } + @Test + public void testProcessMessageMethodNotFound() throws Exception { + expected.expect(new ExceptionCauseMatcher(SpelEvaluationException.class)); + TestDifferentErrorService service = new TestDifferentErrorService(); + Method method = TestErrorService.class.getMethod("checked", String.class); + MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method); + processor.processMessage(new GenericMessage("foo")); + } + @Test public void messageAndHeaderWithAnnotatedMethod() throws Exception { AnnotatedTestService service = new AnnotatedTestService(); @@ -348,7 +358,7 @@ public class MethodInvokingMessageProcessorTests { private static class ExceptionCauseMatcher extends TypeSafeMatcher { private Throwable cause; - private Class type; + private final Class type; public ExceptionCauseMatcher(Class type) { this.type = type; @@ -378,6 +388,13 @@ public class MethodInvokingMessageProcessorTests { } } + @SuppressWarnings("unused") + private static class TestDifferentErrorService { + public String checked(String input) throws Exception { + throw new CheckedException("Expected test exception"); + } + } + @SuppressWarnings("serial") public static final class CheckedException extends Exception { public CheckedException(String string) {