Skip to content

Commit 16931f7

Browse files
author
Adrián García
authored
Add safe iteration over store subscriptions (#11)
1 parent 94aea14 commit 16931f7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8-
- No unreleased changes, yet!
8+
### Fixed
9+
- Fix `ConcurrentModificationException`s in store subscriptions' iteration by adding safe iteration over them.
910

1011
## [1.1.2] - 2020-02-07
1112
### Added

mini-common/src/main/java/mini/Store.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ abstract class Store<S> : Closeable {
7070

7171
@Suppress("UNCHECKED_CAST")
7272
open fun initialState(): S {
73-
val type = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
74-
as Class<S>
73+
val type = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<S>
7574
try {
7675
val constructor = type.getDeclaredConstructor()
7776
constructor.isAccessible = true
@@ -85,7 +84,7 @@ abstract class Store<S> : Closeable {
8584
//State mutation should to happen on UI thread
8685
if (newState != _state) {
8786
_state = newState
88-
listeners.forEach {
87+
listeners.toList().forEach {
8988
it(newState)
9089
}
9190
}

0 commit comments

Comments
 (0)