diff --git a/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java b/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java index 2178707e9d9..56aa0f7fceb 100644 --- a/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java @@ -102,7 +102,9 @@ public class SimpleAliasRegistry implements AliasRegistry { String registeredName = entry.getValue(); if (registeredName.equals(name)) { String registeredAlias = entry.getKey(); - return (registeredAlias.equals(alias) || hasAlias(registeredAlias, alias)); + if (registeredAlias.equals(alias) || hasAlias(registeredAlias, alias)) { + return true; + } } } return false; diff --git a/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java b/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java new file mode 100644 index 00000000000..6aa5658bd60 --- /dev/null +++ b/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java @@ -0,0 +1,63 @@ +/* + * Copyright 2002-2018 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.core; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Juergen Hoeller + */ +public class SimpleAliasRegistryTests { + + @Test + public void testAliasChaining() { + SimpleAliasRegistry registry = new SimpleAliasRegistry(); + registry.registerAlias("test", "testAlias"); + registry.registerAlias("testAlias", "testAlias2"); + registry.registerAlias("testAlias2", "testAlias3"); + + assertTrue(registry.hasAlias("test", "testAlias")); + assertTrue(registry.hasAlias("test", "testAlias2")); + assertTrue(registry.hasAlias("test", "testAlias3")); + assertSame("test", registry.canonicalName("testAlias")); + assertSame("test", registry.canonicalName("testAlias2")); + assertSame("test", registry.canonicalName("testAlias3")); + } + + @Test // SPR-17191 + public void testAliasChainingWithMultipleAliases() { + SimpleAliasRegistry registry = new SimpleAliasRegistry(); + registry.registerAlias("name", "alias_a"); + registry.registerAlias("name", "alias_b"); + assertTrue(registry.hasAlias("name", "alias_a")); + assertTrue(registry.hasAlias("name", "alias_b")); + + registry.registerAlias("real_name", "name"); + assertTrue(registry.hasAlias("real_name", "name")); + assertTrue(registry.hasAlias("real_name", "alias_a")); + assertTrue(registry.hasAlias("real_name", "alias_b")); + + registry.registerAlias("name", "alias_c"); + assertTrue(registry.hasAlias("real_name", "name")); + assertTrue(registry.hasAlias("real_name", "alias_a")); + assertTrue(registry.hasAlias("real_name", "alias_b")); + assertTrue(registry.hasAlias("real_name", "alias_c")); + } + +}