[LANG-1350] ConstructorUtils.invokeConstructor(Class, Object...)

regression
This commit is contained in:
Gary Gregory 2017-08-21 09:28:01 -06:00
parent 05d9518038
commit cc94767e7e
3 changed files with 21 additions and 1 deletions

View File

@ -47,6 +47,7 @@ The <action> type attribute can be add,update,fix,remove.
<release version="3.7" date="tba" description="tba">
<action issue="LANG-1346" type="update" dev="pschumacher">Remove deprecation from RandomStringUtils</action>
<action issue="LANG-1350" type="update" dev="ggregory" due-to="Brett Kail">ConstructorUtils.invokeConstructor(Class, Object...) regression</action>
</release>
<release version="3.6" date="2017-06-08" description="New features and bug fixes. Requires Java 7.">

View File

@ -255,6 +255,10 @@ static boolean isMatchingConstructor(final Constructor<?> method, final Class<?>
private static boolean isMatchingExecutable(final Executable method, final Class<?>[] parameterTypes) {
final Class<?>[] methodParameterTypes = method.getParameterTypes();
if (ClassUtils.isAssignable(parameterTypes, methodParameterTypes, true)) {
return true;
}
if (method.isVarArgs()) {
int i;
for (i = 0; i < methodParameterTypes.length - 1 && i < parameterTypes.length; i++) {
@ -270,7 +274,8 @@ private static boolean isMatchingExecutable(final Executable method, final Class
}
return true;
}
return ClassUtils.isAssignable(parameterTypes, methodParameterTypes, true);
return false;
}
/**

View File

@ -77,6 +77,11 @@ public TestBean(final String... s) {
varArgs = s;
}
public TestBean(final BaseClass bc, String... s) {
toString = "(BaseClass, String...)";
varArgs = s;
}
public TestBean(final Integer i, final String... s) {
toString = "(Integer, String...)";
varArgs = s;
@ -101,6 +106,10 @@ void verify(final String str, final String[] args) {
}
}
private static class BaseClass {}
private static class SubClass extends BaseClass {}
static class PrivateClass {
@SuppressWarnings("unused")
public PrivateClass() {
@ -157,6 +166,8 @@ public void testInvokeConstructor() throws Exception {
.verify("(String...)", new String[]{"a", "b"});
ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.INTEGER_ONE, "a", "b")
.verify("(Integer, String...)", new String[]{"a", "b"});
ConstructorUtils.invokeConstructor(TestBean.class, new SubClass(), new String[]{"a", "b"})
.verify("(BaseClass, String...)", new String[]{"a", "b"});
}
@Test
@ -252,6 +263,9 @@ public void testGetMatchingAccessibleMethod() throws Exception {
singletonArray(Double.class), singletonArray(Double.TYPE));
expectMatchingAccessibleConstructorParameterTypes(TestBean.class,
singletonArray(Double.TYPE), singletonArray(Double.TYPE));
expectMatchingAccessibleConstructorParameterTypes(TestBean.class,
new Class<?>[]{SubClass.class, String[].class},
new Class<?>[]{BaseClass.class, String[].class});
}
@Test