realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
878 stars 52 forks source link

NoSuchElementException #1784

Open XilinJia opened 1 week ago

XilinJia commented 1 week ago

How frequently does the bug occur?

Always

Description

from the documentation:

realm.write {
    // Query for the parent frog object with ponds
    val frog = query<Frog>("name == $0", "Kermit").find().first()
    val ponds = frog.favoritePonds
    // Iterate over the list and delete each pond object
    if (ponds.isNotEmpty()) {
        ponds.forEach { pond ->
            delete(pond)
        }
    }
    // Delete the parent frog object
    val frogToDelete = findLatest(frog)
    if (frogToDelete != null) {
        delete(frogToDelete)
    }
}

The exception of java.util.NoSuchElementException at java.util.AbstractList$Itr.next(AbstractList.java:364) happens at the line of delete(pond)

To fix it, this line: val ponds = frog.favoritePonds needs to be changed to: val ponds = frog.favoritePonds.toList()

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

2.00

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 9

Build environment

Android Studio version: ... Android Build Tools version: ... Gradle version: ...

sync-by-unito[bot] commented 1 week ago

➤ PM Bot commented:

Jira ticket: RKOTLIN-1104