When using the mango-java driver: 3.12.1 getting NullPointerException exceptions when reading a collection containing null item from a document,
private <T> List<T> constructValuesList(final Object key, final Class<T> clazz, final List<T> defaultValue) {
List<?> value = get(key, List.class);
if (value == null) {
return defaultValue;
}
for (Object item : value) {
if (!clazz.isAssignableFrom(item.getClass())) { //NullPointerException if document contain list with null item
throw new ClassCastException(format("List element cannot be cast to %s", clazz.getName()));
}
}
return (List<T>) value;
}
how we can add small fix
if (item!=null && !clazz.isAssignableFrom(item.getClass()))