Skip to content

Commit

Permalink
Fix alias resolution error message in SimpleAliasRegistry
Browse files Browse the repository at this point in the history
Prior to this commit, the alias resolution error message in
SimpleAliasRegistry was misleading.

When a resolution conflict is detected, the IllegalStateException
thrown by resolveAliases(...) now states that the resolved alias is
already registered for an `existingName` instead of the `registeredName`.

See gh-31353
Closes gh-32025
  • Loading branch information
sbrannen committed Jan 14, 2024
1 parent 5d309d5 commit 7daff59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ else if (!resolvedAlias.equals(alias)) {
throw new IllegalStateException(
"Cannot register resolved alias '" + resolvedAlias + "' (original: '" + alias +
"') for name '" + resolvedName + "': It is already registered for name '" +
registeredName + "'.");
existingName + "'.");
}
checkForAliasCircle(resolvedName, resolvedAlias);
this.aliasMap.remove(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,36 +192,24 @@ void resolveAliasesWithPlaceholderReplacement() {
}

@Test
void resolveAliasesWithComplexPlaceholderReplacementAndConfigurationError() {
StringValueResolver valueResolver = new StubStringValueResolver(Map.of(
NAME3, NAME4,
ALIAS3, ALIAS4,
ALIAS4, ALIAS5
));
void resolveAliasesWithPlaceholderReplacementConflict() {
StringValueResolver valueResolver = new StubStringValueResolver(Map.of(ALIAS1, ALIAS2));

registerAlias(NAME3, ALIAS3);
registerAlias(NAME4, ALIAS4);
registerAlias(NAME5, ALIAS5);
registerAlias(NAME1, ALIAS1);
registerAlias(NAME2, ALIAS2);

// Original state:
// WARNING: Based on ConcurrentHashMap iteration order!
// ALIAS3 -> NAME3
// ALIAS5 -> NAME5
// ALIAS4 -> NAME4
// ALIAS1 -> NAME1
// ALIAS2 -> NAME2

// State after processing original entry (ALIAS3 -> NAME3):
// Note that duplicate entry (ALIAS4 -> NAME4) gets removed.
// ALIAS5 -> NAME5
// ALIAS4 -> NAME4

// State after processing original entry (ALIAS4 -> NAME4):
// ALIAS5 -> NAME5
// ALIAS4 -> NAME4
// ALIAS5 -> NAME4 --> Conflict: entry for ALIAS5 already exists
// State after processing original entry (ALIAS1 -> NAME1):
// ALIAS2 -> NAME1 --> Conflict: entry for ALIAS2 already exists
// ALIAS2 -> NAME2

assertThatIllegalStateException()
.isThrownBy(() -> registry.resolveAliases(valueResolver))
.withMessageStartingWith("Cannot register resolved alias");
.withMessage("Cannot register resolved alias '%s' (original: '%s') for name '%s': " +
"It is already registered for name '%s'.", ALIAS2, ALIAS1, NAME1, NAME2);
}

@Test
Expand Down

0 comments on commit 7daff59

Please sign in to comment.