Do not silently return null when no constructor candidate is found
This commit updates ConstructorOrFactoryMethodResolver to throw an exception if no constructor or factory method can be found for a given bean definition. This prevents code generation to happen on an incomplete view of the bean to instantiate. Closes gh-29052
This commit is contained in:
@@ -200,8 +200,9 @@ class ConstructorOrFactoryMethodResolverTests {
|
||||
BeanDefinition beanDefinition = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(MultiConstructorSample.class)
|
||||
.addConstructorArgValue(Locale.ENGLISH).getBeanDefinition();
|
||||
Executable executable = resolve(new DefaultListableBeanFactory(), beanDefinition);
|
||||
assertThat(executable).isNull();
|
||||
assertThatIllegalStateException().isThrownBy(() -> resolve(new DefaultListableBeanFactory(), beanDefinition))
|
||||
.withMessageContaining(MultiConstructorSample.class.getName())
|
||||
.withMessageContaining("and argument types [java.util.Locale]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -212,8 +213,9 @@ class ConstructorOrFactoryMethodResolverTests {
|
||||
.rootBeanDefinition(Locale.class, "getDefault")
|
||||
.getBeanDefinition())
|
||||
.getBeanDefinition();
|
||||
Executable executable = resolve(new DefaultListableBeanFactory(), beanDefinition);
|
||||
assertThat(executable).isNull();
|
||||
assertThatIllegalStateException().isThrownBy(() -> resolve(new DefaultListableBeanFactory(), beanDefinition))
|
||||
.withMessageContaining(MultiConstructorSample.class.getName())
|
||||
.withMessageContaining("and argument types [java.util.Locale]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -338,7 +340,6 @@ class ConstructorOrFactoryMethodResolverTests {
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private Executable resolve(DefaultListableBeanFactory beanFactory, BeanDefinition beanDefinition) {
|
||||
return new ConstructorOrFactoryMethodResolver(beanFactory).resolve(beanDefinition);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user