Skip to content

Conversation

@Jarvx
Copy link

@Jarvx Jarvx commented Oct 21, 2025

Issue: #11815

Bug description

When a bean is conditionally disabled by throwing a DisabledBeanException from a factory method, other beans that @require the disabled bean should also be considered unavailable.

Root Cause & Solutions

The test reproduces the reported issue: a factory method throws DisabledBeanException to disable a bean, and another bean annotated with @Requires(bean = MyBean.class) should therefore not be created.

In the original code, the DisabledBeanException thrown during dependency resolution was wrapped in a DependencyInjectionException, causing ctx.findBean(AnotherBean) to throw instead of returning an empty Optional, and the test failed as shown in the logs.

The patch modifies AbstractInitializableBeanDefinition.resolveBean to rethrow DisabledBeanException directly (except for the special EachBean case which remains a DisabledBeanException), instead of wrapping it in DependencyInjectionException. This allows the upstream context to recognize the disabled dependency and honor @requires, resulting in findBean returning an empty Optional and the test passing.

Steps to reproduce

Please use this command to execute the provided test:

./gradlew :test-suite-kotlin-ksp:test

@Jarvx Jarvx changed the title Fix 11815: changing the catch handler in resolveBean so that for the non-EachBean case the original DisabledBeanException is rethrown [GEnAI] Fix 11815: changing the catch handler in resolveBean so that for the non-EachBean case the original DisabledBeanException is rethrown Oct 24, 2025
@Jarvx Jarvx changed the title [GEnAI] Fix 11815: changing the catch handler in resolveBean so that for the non-EachBean case the original DisabledBeanException is rethrown [GenAI] Fix 11815: changing the catch handler in resolveBean so that for the non-EachBean case the original DisabledBeanException is rethrown Oct 24, 2025
@Jarvx Jarvx changed the title [GenAI] Fix 11815: changing the catch handler in resolveBean so that for the non-EachBean case the original DisabledBeanException is rethrown [GenAI] Fix 11815: Modifications on AbstractInitializableBeanDefinition.resolveBean Oct 31, 2025
@Jarvx
Copy link
Author

Jarvx commented Oct 31, 2025

The PR is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant