I have code
private List<Field> subFields;
private Collection<Field> subFieldsCollection;
...
try {
if (subFields == null && subFieldsCollection != null && !subFieldsCollection.isEmpty()) {
subFields = new ArrayList<>();
subFields.addAll(subFieldsCollection);
}
} catch (IllegalStateException e) {
...
}
and I'm wondering how can it happen for IllegalStateException
to be thrown. It apparently happened to a user of my app, but I'm not able to track what was wrong.
The documentation of Collection.addAll()
says:
IllegalArgumentException - if not all the elements can be added at this time due to insertion restrictions
But what are the insertion restrictions?
I guess it depends on the exact type of the collection. I'm using ArrayList, so let's check docs for addAll()
of List
interface:
IllegalArgumentException - if some property of an element of the specified collection prevents it from being added to this list
Well, what element property could prevent the element to be added to the List? My both Collections are of the same type, I should be able to add null values..
Can anybody explain this to me, please?