Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

function MutableList<T>.moveDownAll() & moveUpAll() throw java.util.ConcurrentModificationException #1340

Open
shinobi9 opened this issue Aug 8, 2021 · 8 comments

Comments

@shinobi9
Copy link

shinobi9 commented Aug 8, 2021

I notice there is a modify operation in for-Each. Is that a mistake?

@SchweinchenFuntik
Copy link
Contributor

version:
kotlin
tornadofx
javaFX
JVM

@shinobi9
Copy link
Author

shinobi9 commented Aug 8, 2021

version:
kotlin: 1.5.21
tornadofx: 1.7.20
javaFX:
javafx.runtime.version=8.0.261
javafx.runtime.build=b12
JVM: 1.8 25.261-b12

@SchweinchenFuntik
Copy link
Contributor

snippet of the code in which the problem is reproduced

PS: I understand what the error is, but I want to make sure that it is not related to your code, but the problem is in tornadofx

@shinobi9
Copy link
Author

shinobi9 commented Aug 8, 2021

mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply { moveDownAll{ true } }.also { println(it) }

Is it my use wrong ?
The original code is missing. but just like this.

@SchweinchenFuntik
Copy link
Contributor

the problem is tornadofx. Although it is not clear why it began to reproduce right now. Try polle low version of Kotlin 1.4 or 1.3. Here is the code that fixes the problem.

inline fun <T> MutableList<T>.moveDownAll(crossinline predicate: (T) -> Boolean) = withIndex()
    .filter { predicate(it.value) }
    .forEach { moveDownAt(it.index) }

@shinobi9
Copy link
Author

shinobi9 commented Aug 9, 2021

ok,thank you.
i will try later

@shinobi9
Copy link
Author

shinobi9 commented Aug 9, 2021

It works well.

@shinobi9 shinobi9 closed this as completed Aug 9, 2021
@SchweinchenFuntik
Copy link
Contributor

I think it is not worth closing, since the problem in the library has not been fixed

@shinobi9 shinobi9 reopened this Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants