Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent equals method for collection types #1669

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ expect object RealmInterop {
fun realm_get_backlinks(obj: RealmObjectPointer, sourceClassKey: ClassKey, sourcePropertyKey: PropertyKey): RealmResultsPointer
fun realm_list_size(list: RealmListPointer): Long
fun MemAllocator.realm_list_get(list: RealmListPointer, index: Long): RealmValue
fun realm_list_find(list: RealmListPointer, value: RealmValue): Long
fun realm_list_get_list(list: RealmListPointer, index: Long): RealmListPointer
fun realm_list_get_dictionary(list: RealmListPointer, index: Long): RealmMapPointer
fun realm_list_add(list: RealmListPointer, index: Long, transport: RealmValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,18 @@ actual object RealmInterop {
realmc.realm_list_get(list.cptr(), index, struct)
return RealmValue(struct)
}

actual fun realm_list_find(list: RealmListPointer, value: RealmValue): Long {
val index = LongArray(1)
val found = BooleanArray(1)
realmc.realm_list_find(list.cptr(), value.value, index, found)
return if (found[0]) {
index[0]
} else {
-1
}
}

actual fun realm_list_get_list(list: RealmListPointer, index: Long): RealmListPointer =
LongPointerWrapper(realmc.realm_list_get_list(list.cptr(), index))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,19 @@ actual object RealmInterop {
return RealmValue(struct)
}

actual fun realm_list_find(list: RealmListPointer, value: RealmValue): Long {
memScoped {
val index = alloc<ULongVar>()
val found = alloc<BooleanVar>()
checkedBooleanResult(realm_wrapper.realm_list_find(list.cptr(), value.value.readValue(), index.ptr, found.ptr))
return if (found.value) {
index.value.toLong()
} else {
-1
}
}
}

actual fun realm_list_get_list(list: RealmListPointer, index: Long): RealmListPointer =
CPointerWrapper(realm_wrapper.realm_list_get_list(list.cptr(), index.toULong()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.realm.kotlin.Versioned
import io.realm.kotlin.dynamic.DynamicRealmObject
import io.realm.kotlin.ext.asRealmObject
import io.realm.kotlin.ext.isManaged
import io.realm.kotlin.internal.RealmValueArgumentConverter.convertToQueryArgs
import io.realm.kotlin.internal.interop.Callback
import io.realm.kotlin.internal.interop.ClassKey
Expand Down Expand Up @@ -64,10 +65,8 @@
}

override fun toString(): String = "UnmanagedRealmList{${joinToString()}}"

Check failure on line 68 in packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmListInternal.kt

View workflow job for this annotation

GitHub Actions / Ktlint Results

no-blank-line-before-rbrace

Unexpected blank line(s) before "}"
override fun equals(other: Any?): Boolean = backingList == other

Check failure on line 69 in packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmListInternal.kt

View workflow job for this annotation

GitHub Actions / Ktlint Results

no-consecutive-blank-lines

Needless blank line(s)
override fun hashCode(): Int = backingList.hashCode()
}

/**
Expand All @@ -90,10 +89,23 @@
return operator.get(index)
}

override fun contains(element: E): Boolean {
return operator.contains(element)
}

override fun indexOf(element: E): Int {
return operator.indexOf(element)
}


Check failure on line 100 in packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmListInternal.kt

View workflow job for this annotation

GitHub Actions / Ktlint Results

no-consecutive-blank-lines

Needless blank line(s)
override fun add(index: Int, element: E) {
operator.insert(index, element)
}

override fun remove(element: E): Boolean {
return operator.remove(element)
}

// We need explicit overrides of these to ensure that we capture duplicate references to the
// same unmanaged object in our internal import caching mechanism
override fun addAll(elements: Collection<E>): Boolean = operator.insertAll(size, elements)
Expand Down Expand Up @@ -156,6 +168,19 @@
!nativePointer.isReleased() && RealmInterop.realm_list_is_valid(nativePointer)

override fun delete() = RealmInterop.realm_list_remove_all(nativePointer)

override fun equals(other: Any?): Boolean {
val o = other as? ManagedRealmList<*>
return when (o) {
null -> false
else -> RealmInterop.realm_equals(nativePointer, o.nativePointer)
}
}

override fun hashCode(): Int {
// TODO Improve distribution. Maybe something like parent.table + parent.ref + parent.key + version
return operator.realmReference.version().version.hashCode()
}
}

internal class RealmListChangeFlow<E>(producerScope: ProducerScope<ListChange<E>>) :
Expand Down Expand Up @@ -225,6 +250,10 @@

fun get(index: Int): E

fun contains(element: E): Boolean = indexOf(element) != -1

fun indexOf(element: E): Int

// TODO OPTIMIZE We technically don't need update policy and cache for primitive lists but right now RealmObjectHelper.assign doesn't know how to differentiate the calls to the operator
fun insert(
index: Int,
Expand All @@ -233,6 +262,14 @@
cache: UnmanagedToManagedObjectCache = mutableMapOf()
)

fun remove(element: E): Boolean = when (val index = indexOf(element)) {
-1 -> false
else -> {
RealmInterop.realm_list_erase(nativePointer, index.toLong())
true
}
}

fun insertAll(
index: Int,
elements: Collection<E>,
Expand Down Expand Up @@ -277,6 +314,14 @@
}
}

override fun indexOf(element: E): Int {
inputScope {
with(realmValueConverter) {
return RealmInterop.realm_list_find(nativePointer, publicToRealmValue(element)).toInt()
}
}
}

override fun insert(
index: Int,
element: E,
Expand All @@ -296,7 +341,7 @@
index: Int,
element: E,
updatePolicy: UpdatePolicy,
cache: UnmanagedToManagedObjectCache
cache: UnmanagedToManagedObjectCache,
): E {
return get(index).also {
inputScope {
Expand All @@ -310,7 +355,7 @@

override fun copy(
realmReference: RealmReference,
nativePointer: RealmListPointer
nativePointer: RealmListPointer,
): ListOperator<E> =
PrimitiveListOperator(mediator, realmReference, realmValueConverter, nativePointer)
}
Expand Down Expand Up @@ -354,6 +399,17 @@
}
}

override fun indexOf(element: RealmAny?): Int {
// Unmanaged objects are never found in a managed collections
if (element?.type == RealmAny.Type.OBJECT) {
if (!element.asRealmObject<RealmObjectInternal>().isManaged()) return -1
}
return inputScope {
val transport = realmAnyToRealmValueWithoutImport(element)
RealmInterop.realm_list_find(nativePointer, transport).toInt()
}
}

override fun insert(
index: Int,
element: RealmAny?,
Expand Down Expand Up @@ -461,6 +517,18 @@
realmValueToRealmObject(transport, clazz, mediator, realmReference) as E
}
}

override fun indexOf(element: E): Int {
// Unmanaged objects are never found in a managed collections
element?.also {
if (!(it as RealmObjectInternal).isManaged()) return -1
}
return inputScope {
val objRef = realmObjectToRealmReferenceOrError(element as BaseRealmObject?)
val transport = realmObjectTransport(objRef as RealmObjectInterop)
RealmInterop.realm_list_find(nativePointer, transport).toInt()
}
}
}

internal class RealmObjectListOperator<E : BaseRealmObject?>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,19 +768,7 @@

override fun toString(): String = entries.joinToString { (key, value) -> "[$key,$value]" }
.let { "UnmanagedRealmDictionary{$it}" }

Check failure on line 771 in packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmMapInternal.kt

View workflow job for this annotation

GitHub Actions / Ktlint Results

no-blank-line-before-rbrace

Unexpected blank line(s) before "}"
override fun equals(other: Any?): Boolean {
if (other !is RealmDictionary<*>) return false
if (this === other) return true
if (this.size == other.size && this.entries.containsAll(other.entries)) return true
return false
}

override fun hashCode(): Int {
var result = size.hashCode()
result = 31 * result + entries.hashCode()
return result
}
}

internal class ManagedRealmDictionary<V> constructor(
Expand Down Expand Up @@ -819,7 +807,18 @@
return "RealmDictionary{size=$size,owner=$owner,objKey=$objKey,version=$version}"
}

// TODO add equals and hashCode when https://github.com/realm/realm-kotlin/issues/1097 is fixed
override fun equals(other: Any?): Boolean {
val o = other as? ManagedRealmMap<*, *>
return when (o) {
null -> false
else -> RealmInterop.realm_equals(nativePointer, o.nativePointer)
}
}

override fun hashCode(): Int {
// TODO Improve distribution. Maybe something like parent.table + parent.ref + parent.key + version
return operator.realmReference.version().version.hashCode()
}
}

internal class RealmDictonaryChangeFlow<V>(scope: ProducerScope<MapChange<String, V>>) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,15 @@ internal object RealmObjectHelper {
if (other == null || obj::class != other::class) return false

other as BaseRealmObject

if (other.isManaged()) {
if (obj.isValid() != other.isValid()) return false
return obj.getIdentifierOrNull() == other.getIdentifierOrNull()
return if (obj.isManaged() && other.isManaged()) {
RealmInterop.realm_equals(
obj.realmObjectReference!!.objectPointer,
other.realmObjectReference!!.objectPointer
)
} else {
// If one of the objects are unmanaged, they are only equal if identical, which
// should have been caught at the top of this function.
return false
false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@
}

override fun toString(): String = "UnmanagedRealmSet{${joinToString()}}"

Check failure on line 69 in packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmSetInternal.kt

View workflow job for this annotation

GitHub Actions / Ktlint Results

no-blank-line-before-rbrace

Unexpected blank line(s) before "}"
override fun equals(other: Any?): Boolean = backingSet == other

Check failure on line 70 in packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmSetInternal.kt

View workflow job for this annotation

GitHub Actions / Ktlint Results

no-consecutive-blank-lines

Needless blank line(s)
override fun hashCode(): Int = backingSet.hashCode()
}

/**
Expand Down Expand Up @@ -205,6 +203,19 @@
override fun isValid(): Boolean {
return !nativePointer.isReleased() && RealmInterop.realm_set_is_valid(nativePointer)
}

override fun equals(other: Any?): Boolean {
val o = other as? ManagedRealmSet<*>
return when (o) {
null -> false
else -> RealmInterop.realm_equals(nativePointer, o.nativePointer)
}
}

override fun hashCode(): Int {
// TODO Improve distribution. Maybe something like parent.table + parent.ref + parent.key + version
return operator.realmReference.version().version.hashCode()
}
}

internal fun <E : BaseRealmObject> ManagedRealmSet<E>.query(
Expand Down Expand Up @@ -345,8 +356,8 @@
transport, null, mediator, realmReference,
issueDynamicObject,
issueDynamicMutableObject,
{ error("Set should never container lists") }
) { error("Set should never container dictionaries") }
{ error("Set should never contain lists") }
) { error("Set should never contain dictionaries") }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@
realm.query<JsonStyleRealmObject>("value[*] == 4").find().single().run {
assertEquals("LIST", id)
}
realm.query<JsonStyleRealmObject>("value[*] == {4, 5, 6}").find().single().run {
assertEquals("LIST", id)
}

// Matching dictionaries
realm.query<JsonStyleRealmObject>("value.key1 == 7").find().single().run {
Expand Down Expand Up @@ -606,5 +609,11 @@
realm.query<JsonStyleRealmObject>("value[*].key3[0] == 9").find().single().run {
assertEquals("EMBEDDED", id)
}
realm.query<JsonStyleRealmObject>("value[0][*] == {4, 5, 6}").find().single().run {
assertEquals("EMBEDDED", id)
}
realm.query<JsonStyleRealmObject>("value[*][*] == {4, 5, 6}").find().single().run {

Check failure on line 615 in packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt

View workflow job for this annotation

GitHub Actions / Unit Test Results - Base JVM Linux

io.realm.kotlin.test.common.RealmAnyNestedCollectionTests ► query[jvm]

Failed test found in: ./packages/test-base/build/test-results/jvmTest/TEST-io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.xml Error: java.util.NoSuchElementException: List is empty.
Raw output
java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.single(_Collections.kt:608)
	at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests$query$1.invokeSuspend(RealmAnyNestedCollectionTests.kt:615)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:22)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:21)
	at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.query(RealmAnyNestedCollectionTests.kt:534)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:108)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:57)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52)
	at jdk.internal.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

Check failure on line 615 in packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt

View workflow job for this annotation

GitHub Actions / Unit Test Results - Base JVM Windows

io.realm.kotlin.test.common.RealmAnyNestedCollectionTests ► query[jvm]

Failed test found in: ./packages/test-base/build/test-results/jvmTest/TEST-io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.xml Error: java.util.NoSuchElementException: List is empty.
Raw output
java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.single(_Collections.kt:608)
	at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests$query$1.invokeSuspend(RealmAnyNestedCollectionTests.kt:615)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:22)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:21)
	at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.query(RealmAnyNestedCollectionTests.kt:534)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:108)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:57)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52)
	at jdk.internal.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

Check failure on line 615 in packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt

View workflow job for this annotation

GitHub Actions / Unit Test Results - Base JVM MacOS x64

io.realm.kotlin.test.common.RealmAnyNestedCollectionTests ► query[jvm]

Failed test found in: ./packages/test-base/build/test-results/jvmTest/TEST-io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.xml Error: java.util.NoSuchElementException: List is empty.
Raw output
java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.single(_Collections.kt:608)
	at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests$query$1.invokeSuspend(RealmAnyNestedCollectionTests.kt:615)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:22)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:21)
	at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.query(RealmAnyNestedCollectionTests.kt:534)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:108)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:57)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52)
	at jdk.internal.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

Check failure on line 615 in packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt

View workflow job for this annotation

GitHub Actions / Unit Test Results - Android Base (Emulator)

io.realm.kotlin.test.android.InstrumentedTests ► io.realm.kotlin.test.common.RealmAnyNestedCollectionTests ► query

Failed test found in: ./packages/test-base/build/outputs/androidTest-results/connected/TEST-test(AVD) - 13-_test-base-.xml Error: java.util.NoSuchElementException: List is empty.
Raw output
java.util.NoSuchElementException: List is empty.
at kotlin.collections.CollectionsKt___CollectionsKt.single(_Collections.kt:608)
at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests$query$1.invokeSuspend(RealmAnyNestedCollectionTests.kt:615)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:22)
at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:21)
at io.realm.kotlin.test.common.RealmAnyNestedCollectionTests.query(RealmAnyNestedCollectionTests.kt:534)
assertEquals("EMBEDDED", id)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.realm.kotlin.entities.embedded.EmbeddedParent
import io.realm.kotlin.entities.embedded.embeddedSchema
import io.realm.kotlin.ext.asRealmObject
import io.realm.kotlin.ext.query
import io.realm.kotlin.ext.realmAnyListOf
import io.realm.kotlin.ext.realmDictionaryOf
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.ext.realmSetOf
Expand Down Expand Up @@ -489,9 +490,18 @@ class RealmAnyTests {
// Different objects of same type are not equal
assertNotEquals(RealmAny.create(Sample()), RealmAny.create(realmObject))
}
// Collections in RealmAny are tested in RealmAnyNestedCollections.kt
RealmAny.Type.LIST,
RealmAny.Type.DICTIONARY -> {}
RealmAny.Type.LIST -> {
val value = realmAnyListOf(1, "String", Sample())
// Lists are only comparing equal on referential equality
assertNotEquals(value, realmAnyListOf(1, "String", Sample()))
assertEquals(value, value)
}
RealmAny.Type.DICTIONARY -> {
val value = realmDictionaryOf("key1" to "String", "key2" to Sample())
// Lists are only comparing equal on referential equality
assertNotEquals(value, realmDictionaryOf("key1" to "String", "key2" to Sample()))
assertEquals(value, value)
}
}
}
}
Expand Down
Loading
Loading