Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log alias removal in DefaultListableBeanFactory #34070

Closed
mathewm3 opened this issue Dec 11, 2024 · 0 comments
Closed

Log alias removal in DefaultListableBeanFactory #34070

mathewm3 opened this issue Dec 11, 2024 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@mathewm3
Copy link

mathewm3 commented Dec 11, 2024

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);
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 11, 2024
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Dec 11, 2024
@sbrannen sbrannen changed the title Logging for alias removal in DefaultListableBeanFactory Log alias removal in DefaultListableBeanFactory Dec 11, 2024
@sbrannen sbrannen self-assigned this Dec 11, 2024
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 11, 2024
@sbrannen sbrannen added this to the 6.2.1 milestone Dec 11, 2024
@sbrannen sbrannen added the for: backport-to-6.1.x Marks an issue as a candidate for backport to 6.1.x label Dec 11, 2024
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.1.x Marks an issue as a candidate for backport to 6.1.x labels Dec 11, 2024
sbrannen added a commit that referenced this issue Dec 11, 2024
Prior to this commit, information was logged when a bean definition
overrode an existing bean definition, but nothing was logged when the
registration of a bean definition resulted in the removal of an alias.

With this commit, an INFO message is now logged whenever an alias is
removed in DefaultListableBeanFactory.

Closes gh-34070

(cherry picked from commit 41d9f21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants