Repository navigation
Conversation
SimpleAliasRegistry checks for circular references when an alias is
registered and when resolveAliases() resolves an alias to a new name,
but not when only the target name of an alias changes. A placeholder
in the target name of an alias, for example
<alias name="${target}" alias="alias1"/>, could therefore resolve to
an alias that already points back to alias1. The circle was then
registered silently and canonicalName() looped forever on the next
lookup of either alias.
Invoke checkForAliasCircle() in that branch as well, so that such a
configuration fails with the same IllegalStateException as a direct
registration of the circle.
Signed-off-by: junhyeong9812 <pickjog@gmail.com>
Member
|
This has been merged into Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
SimpleAliasRegistryrejects circular aliases when they are registered, butresolveAliases()skips that check when only the target name of an alias changes. A placeholder in the target name can therefore introduce a circle that is registered silently, and the next lookup of either alias loops forever incanonicalName(). This PR adds the missingcheckForAliasCircle()call.Problem
resolveAliases()handles three cases for each alias:null, or both resolve to the same value: the entry is removed.checkForAliasCircle(resolvedName, resolvedAlias)is invoked before the new entry is stored.aliasMap.put(alias, resolvedName), without a circle check.For example:
With
target=alias2, case 3 turnsalias1 -> ${target}intoalias1 -> alias2whilealias2 -> alias1already exists. No exception is thrown, andgetBean("alias1")then spins incanonicalName(). Registering the same two aliases directly fails immediately withCircular reference - 'alias2' is a direct or indirect alias for 'alias1' already.The early detection in
registerAlias()was introduced for exactly this kind of endless loop in SPR-7274 (gh-11933).Fix
checkForAliasCircle(resolvedName, alias)is now invoked in case 3 before the entry is updated, in the same way as in case 2. Resolution of a circle introduced through a placeholder now fails with the sameIllegalStateExceptionas a direct registration, and the alias map is left unchanged for that alias.A new test in
SimpleAliasRegistryTestsreproduces the scenario above. It fails before the change (no exception is thrown) and passes after it. The spring-core and spring-beans test suites pass.