Skip to content

Commit

Permalink
* fix npe for null varargs
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Prinz committed Mar 7, 2016
1 parent edd22cb commit 1e836f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public Object[] convert(Object[] data, boolean isVarArgs, Class<?>[] parameterTy

private Object convertVarArgArgument(Object[] data, Class<?> varArgComponentType, int nonVarArgParameters) {
if (data.length > 0) {
Class<?> lastArgType = data[data.length - 1].getClass();
if (lastArgType.isArray() && lastArgType.getComponentType() == varArgComponentType) {
return data[data.length - 1];
Object date = data[data.length - 1];
Class<?> lastArgType = date != null ? date.getClass() : null;
if (lastArgType != null && lastArgType.isArray() && lastArgType.getComponentType() == varArgComponentType) {
return date;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public void testConvertShouldCreateEmptyVarargsArrayForMissingOnlyVarargsArgumen
assertThat(result).containsExactly(new int[0]);
}

@Test
public void testConvertShouldHandleNullElementAsSingleElement() throws Exception {
// Given:
Object[] data = new Object[] { null };
Class<?>[] parameterTypes = new Class<?>[] { String.class, int[].class };

// When:
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).containsExactly(null, new int[0]);
}

@Test
public void testConvertShouldCreateEmptyVarargsArrayForLastMissingVarargsArgument() {
// Given:
Expand Down

0 comments on commit 1e836f3

Please sign in to comment.