Skip to content

Instantly share code, notes, and snippets.

@phiSgr
Last active December 26, 2019 21:07
Show Gist options
  • Save phiSgr/adfad98266c171548ab1f0d5ee4537b8 to your computer and use it in GitHub Desktop.
Save phiSgr/adfad98266c171548ab1f0d5ee4537b8 to your computer and use it in GitHub Desktop.
ConcurrentModificationException with subList
val list = ArrayList<Int>()
val subList = list.subList(0, 0)
list.add(1) // modCount++
subList + 1
/*
Exception in thread "main" java.util.ConcurrentModificationException
at java.base/java.util.ArrayList$SubList.checkForComodification(ArrayList.java:1444)
at java.base/java.util.ArrayList$SubList.size(ArrayList.java:1184)
at kotlin.collections.CollectionsKt___CollectionsKt.plus(_Collections.kt:2036)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment