[GenAI] Fix 11815: Modifications on AbstractInitializableBeanDefinition.resolveBean #12148
+43
−1
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.
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
DisabledBeanExceptionthrown during dependency resolution was wrapped in a DependencyInjectionException, causingctx.findBean(AnotherBean) to throw instead of returning an empty Optional, and the test failed as shown in the logs.The patch modifies
AbstractInitializableBeanDefinition.resolveBeanto rethrowDisabledBeanExceptiondirectly (except for the special EachBean case which remains aDisabledBeanException), instead of wrapping it inDependencyInjectionException. This allows the upstream context to recognize the disabled dependency and honor @requires, resulting infindBeanreturning an empty Optional and the test passing.Steps to reproduce
Please use this command to execute the provided test: