From 3c31c38053bcd6a6a6a98e82f50528e39a59df97 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 25 Apr 2013 16:20:45 -0400 Subject: [PATCH] INT-2972 FixedMethodFilter - Return Mutable List Compatibility with SF 3.2.2 Previously the filter returned a Collections.singletonList() when a match is found. Spring 3.2.2 attempts to sort the results of MethodFilter.filter() which fails because the list is immutable. Continue to return Collections.emptyList() with no match; this does not cause the sort to fail. Several tests in MethodInvokingMessageProcessorTests reproduce this problem with Spring 3.2.2. Add a test to confirm the Collections.emptyList() does not cause any problems. --- .../integration/util/FixedMethodFilter.java | 10 ++++++--- .../MethodInvokingMessageProcessorTests.java | 21 +++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) 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) {