java.util.Collection
or java.util.Map
is a collection or map itself.
This includes adding a collection to itself, for example, calling hashCode()
on the self-containing collection, which can lead to a java.lang.StackOverflowError
.
Such situations may occur in the code with raw types as a result of copy-paste.
Example:
ArrayList list = new ArrayList<>();
list.add(list);
return list.hashCode(); // throws StackOverflowException