in src/main/java/org/apache/sling/contentparser/api/ParserHelper.java [75:99]
public static Object convertSingleTypeArray(Object[] values) {
if (values.length == 0) {
return values;
}
Class<?> itemType = null;
for (Object value : values) {
if (value == null) {
throw new IllegalArgumentException("Multi-value array must not contain null values.");
}
if (value instanceof Map) {
throw new IllegalArgumentException("Multi-value array must not contain maps/objects.");
}
if (itemType == null) {
itemType = value.getClass();
} else if (itemType != value.getClass()) {
throw new IllegalArgumentException("Multi-value array must not contain values with different types "
+ "(" + itemType.getName() + ", " + value.getClass().getName() + ").");
}
}
Object convertedArray = Array.newInstance(itemType, values.length);
for (int i = 0; i < values.length; i++) {
Array.set(convertedArray, i, values[i]);
}
return convertedArray;
}