Java Collections Unmodifiable
Collections.unmodifiable*
can throw StackOverflowError
errors when used recursively. For example:
Exception in thread "main" java.lang.StackOverflowError
at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1039)
at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1038)
at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1039)
at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1038)
[...]
Reproducible Source:
List<Integer> list = Collections.unmodifiableList(Arrays.asList(0, 1, 2));
for (int i = 0; i < 10000; i++) {
list = Collections.unmodifiableList(list);
}
for (int i : list) {
System.out.println(i);
}
Just thought that was interesting.