diff --git a/runtime/src/main/kotlin/kotlin/Exceptions.kt b/runtime/src/main/kotlin/kotlin/Exceptions.kt index 73aef785d00..fa77f467de0 100644 --- a/runtime/src/main/kotlin/kotlin/Exceptions.kt +++ b/runtime/src/main/kotlin/kotlin/Exceptions.kt @@ -134,7 +134,7 @@ public actual open class AssertionError : Error { actual constructor() - constructor(message: String?) : super(message) + constructor(cause: Throwable?) : super(cause) actual constructor(message: Any?) : super(message.toString()) diff --git a/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt b/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt index ecaacab3190..b30638335a0 100644 --- a/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt +++ b/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt @@ -330,6 +330,7 @@ actual class ArrayList private constructor( } override fun remove() { + check(lastIndex != -1) { "Call next() or previous() before removing element from the iterator." } list.removeAt(lastIndex) index = lastIndex lastIndex = -1 diff --git a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt index b6d4d475fbc..8154ab8db41 100644 --- a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt +++ b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt @@ -552,7 +552,7 @@ actual class HashMap private constructor( internal class KeysItr(map: HashMap) : Itr(map), MutableIterator { override fun next(): K { - if (index >= map.length) throw IndexOutOfBoundsException() + if (index >= map.length) throw NoSuchElementException() lastIndex = index++ val result = map.keysArray[lastIndex] initNext() @@ -563,7 +563,7 @@ actual class HashMap private constructor( internal class ValuesItr(map: HashMap) : Itr(map), MutableIterator { override fun next(): V { - if (index >= map.length) throw IndexOutOfBoundsException() + if (index >= map.length) throw NoSuchElementException() lastIndex = index++ val result = map.valuesArray!![lastIndex] initNext() @@ -574,7 +574,7 @@ actual class HashMap private constructor( internal class EntriesItr(map: HashMap) : Itr(map), MutableIterator> { override fun next(): EntryRef { - if (index >= map.length) throw IndexOutOfBoundsException() + if (index >= map.length) throw NoSuchElementException() lastIndex = index++ val result = EntryRef(map, lastIndex) initNext() @@ -582,7 +582,7 @@ actual class HashMap private constructor( } internal fun nextHashCode(): Int { - if (index >= map.length) throw IndexOutOfBoundsException() + if (index >= map.length) throw NoSuchElementException() lastIndex = index++ val result = map.keysArray[lastIndex].hashCode() xor map.valuesArray!![lastIndex].hashCode() initNext() @@ -590,7 +590,7 @@ actual class HashMap private constructor( } fun nextAppendString(sb: StringBuilder) { - if (index >= map.length) throw IndexOutOfBoundsException() + if (index >= map.length) throw NoSuchElementException() lastIndex = index++ val key = map.keysArray[lastIndex] if (key == map) sb.append("(this Map)") else sb.append(key)