diff --git a/src/main/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverter.java b/src/main/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverter.java index cc1f0c4a..0f9b7b8c 100644 --- a/src/main/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverter.java +++ b/src/main/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverter.java @@ -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; } } diff --git a/src/test/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverterTest.java b/src/test/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverterTest.java index 2cae5a7a..b045743f 100644 --- a/src/test/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverterTest.java +++ b/src/test/java/com/tngtech/java/junit/dataprovider/internal/convert/ObjectArrayConverterTest.java @@ -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: