Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LANG-1350: Fix varargs array invokeConstructor #283

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -270,7 +274,8 @@ private static boolean isMatchingExecutable(final Executable method, final Class
}
return true;
}
return ClassUtils.isAssignable(parameterTypes, methodParameterTypes, true);

return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down