From 01b64129c86f522bd36edc96635941603b780f1c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 26 May 2020 23:33:02 +0200 Subject: [PATCH] Consistently determine minimum number of arguments from specified index Closes gh-25130 --- .../beans/factory/support/ConstructorResolver.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index c81c4260446d..1a90b850c7da 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,7 +202,6 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd, LinkedList causes = null; for (Constructor candidate : candidates) { - int parameterCount = candidate.getParameterCount(); if (constructorToUse != null && argsToUse != null && argsToUse.length > parameterCount) { @@ -516,8 +515,8 @@ public BeanWrapper instantiateUsingFactoryMethod( LinkedList causes = null; for (Method candidate : candidates) { - int parameterCount = candidate.getParameterCount(); + if (parameterCount >= minNrOfArgs) { ArgumentsHolder argsHolder; @@ -680,7 +679,7 @@ private int resolveConstructorArguments(String beanName, RootBeanDefinition mbd, throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Invalid constructor argument index: " + index); } - if (index > minNrOfArgs) { + if (index + 1 > minNrOfArgs) { minNrOfArgs = index + 1; } ConstructorArgumentValues.ValueHolder valueHolder = entry.getValue();