diff --git a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt index 74984145984..63893db0d85 100644 --- a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt +++ b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt @@ -386,15 +386,15 @@ actual class HashMap private constructor( private fun contentEquals(other: Map<*, *>): Boolean = _size == other.size && containsAllEntries(other.entries) - internal fun containsAllEntries(m: Collection>): Boolean { + internal fun containsAllEntries(m: Collection<*>): Boolean { val it = m.iterator() while (it.hasNext()) { val entry = it.next() try { @Suppress("UNCHECKED_CAST") // todo: get rid of unchecked cast here somehow - if (!containsEntry(entry as Map.Entry)) + if (entry == null || !containsEntry(entry as Map.Entry)) return false - } catch(e: ClassCastException) { + } catch (e: ClassCastException) { return false } } @@ -676,9 +676,7 @@ internal class HashMapEntrySet internal constructor( override fun retainAll(elements: Collection>): Boolean = backing.retainAllEntries(elements) override fun equals(other: Any?): Boolean = - other === this || - other is Set<*> && - contentEquals(other) + other === this || other is Set<*> && contentEquals(other) override fun hashCode(): Int { var result = 0