Skip to content

Log alias removal in DefaultListableBeanFactory #34070

Closed
@mathewm3

Description

@mathewm3

Issue

The following code was added in DefaultListableBeanFactory from 6.x to check whether an alias for the beanName exists.

If it exists, the corresponding alias is removed.

if (isAlias(beanName)) {
    String aliasedName = canonicalName(beanName);
    if (!isBeanDefinitionOverridable(aliasedName)) {
        if (containsBeanDefinition(aliasedName)) {  // alias for existing bean definition
            throw new BeanDefinitionOverrideException(
                    beanName, beanDefinition, getBeanDefinition(aliasedName));
        }
        else {  // alias pointing to non-existing bean definition
            throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName,
                    "Cannot register bean definition for bean '" + beanName +
                    "' since there is already an alias for bean '" + aliasedName + "' bound.");
        }
    }
    else {
        removeAlias(beanName);
    }
}

However, there is no log message to indicate that an alias was removed, which can lead to errors without any warning message to the user.

Proposal

Include logging for removal of an alias, similar to how it is done when there is a duplicate bean name with logBeanDefinitionOverriding().

if (existingDefinition != null) {
    if (!isBeanDefinitionOverridable(beanName)) {
        throw new BeanDefinitionOverrideException(beanName, beanDefinition, existingDefinition);
    }
    else {
        logBeanDefinitionOverriding(beanName, beanDefinition, existingDefinition);
    }
    this.beanDefinitionMap.put(beanName, beanDefinition);
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions