Add missing precondition check to AutowireUtils.resolveDependency
See gh-2060
This commit is contained in:
parent
02be21d0dc
commit
d4f544d42f
|
|
@ -334,7 +334,7 @@ public abstract class AutowireUtils {
|
|||
* that declares the parameter
|
||||
* @param containingClass the concrete class that contains the parameter; this may
|
||||
* differ from the class that declares the parameter in that it may be a subclass
|
||||
* thereof, potentially substituting type variables
|
||||
* thereof, potentially substituting type variables (must not be {@code null})
|
||||
* @param beanFactory the {@code AutowireCapableBeanFactory} from which to resolve
|
||||
* the dependency (must not be {@code null})
|
||||
* @return the resolved object, or {@code null} if none found
|
||||
|
|
@ -351,6 +351,7 @@ public abstract class AutowireUtils {
|
|||
throws BeansException {
|
||||
|
||||
Assert.notNull(parameter, "Parameter must not be null");
|
||||
Assert.notNull(containingClass, "Containing class must not be null");
|
||||
Assert.notNull(beanFactory, "AutowireCapableBeanFactory must not be null");
|
||||
|
||||
AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex);
|
||||
|
|
|
|||
|
|
@ -159,15 +159,24 @@ public class AutowireUtilsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveDependencyPreconditionsForBeanFactory() throws Exception {
|
||||
Method method = getClass().getDeclaredMethod("autowirableMethod", String.class, String.class, String.class, String.class);
|
||||
Parameter parameter = method.getParameters()[0];
|
||||
|
||||
public void resolveDependencyPreconditionsForContainingClass() throws Exception {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("AutowireCapableBeanFactory must not be null");
|
||||
AutowireUtils.resolveDependency(parameter, 0, null, null);
|
||||
exception.expectMessage("Containing class must not be null");
|
||||
AutowireUtils.resolveDependency(getParameter(), 0, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveDependencyPreconditionsForBeanFactory() throws Exception {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("AutowireCapableBeanFactory must not be null");
|
||||
AutowireUtils.resolveDependency(getParameter(), 0, getClass(), null);
|
||||
}
|
||||
|
||||
private Parameter getParameter() throws NoSuchMethodException {
|
||||
Method method = getClass().getDeclaredMethod("autowirableMethod", String.class, String.class, String.class, String.class);
|
||||
return method.getParameters()[0];
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception {
|
||||
Constructor<?> constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue