From c92d877c241e14005ff1dab7b4facb90460ffde3 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 18 Jul 2011 09:41:37 -0400 Subject: [PATCH] INT-1969 ensuring that interface weight results are always odd to offset with even class results. Also fixed typo: 'matchedIntefaces' --- .../integration/router/PayloadTypeRouter.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/PayloadTypeRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/PayloadTypeRouter.java index b1a2005db6..7490006dfc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/PayloadTypeRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/PayloadTypeRouter.java @@ -101,19 +101,20 @@ public class PayloadTypeRouter extends AbstractMessageRouter { if (type.getName().equals(candidate)) { return level; } - List matchingIntefaces = new ArrayList(); + List matchingInterfaces = new ArrayList(); for (Class iface : type.getInterfaces()) { if (iface.getName().equals(candidate)) { - matchingIntefaces.add(candidate); + matchingInterfaces.add(candidate); } - if (matchingIntefaces.size() > 1) { + if (matchingInterfaces.size() > 1) { throw new IllegalStateException("Found more than one matching interface at the same level of " + "the hierarchy while attempting to find closest match for [" + type.getName() + "]."); } - if (matchingIntefaces.size() == 1) { - return level + 1; + if (matchingInterfaces.size() == 1) { + // if level is odd, the base type is an interface + return (level % 2 == 1) ? level + 2 : level + 1; } - // check interface hierarchy + // no match at this level, continue up the hierarchy for (Class superInterface : iface.getInterfaces()) { int weight = this.determineTypeDifferenceWeight(candidate, superInterface, level + 3); if (weight < Integer.MAX_VALUE) {