From 57cd2a368aa890ddebda4dce567446700eca9c9e Mon Sep 17 00:00:00 2001 From: Clemente Date: Fri, 7 Jun 2024 07:30:49 +0200 Subject: [PATCH 1/4] Remove nullability check --- CHANGELOG.md | 1 + .../kotlin/io/realm/kotlin/exceptions/RealmException.kt | 6 +++--- .../io/realm/kotlin/mongodb/exceptions/AppException.kt | 2 +- .../io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt | 4 ++-- .../io/realm/kotlin/mongodb/internal/SubscriptionSetImpl.kt | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 840126c351..4828478bd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed * [Sync] Fatal sync exceptions are now thrown as `UnrecoverableSyncException`. (Issue [#1767](https://github.com/realm/realm-kotlin/issues/1767) [RKOTLIN-1096](https://jira.mongodb.org/browse/RKOTLIN-1096)). +* [Sync] Fix `NullPointerException` in `SubscriptionSet.waitForSynchronization`. (Issue [#1777](https://github.com/realm/realm-kotlin/issues/1777) [RKOTLIN-1102](https://jira.mongodb.org/browse/RKOTLIN-1102)). ### Compatibility * File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later). diff --git a/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt b/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt index 761e7c88c1..7ed41d4b6e 100644 --- a/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt +++ b/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt @@ -9,7 +9,7 @@ package io.realm.kotlin.exceptions */ public open class RealmException : RuntimeException { public constructor() : super() - public constructor(message: String) : super(message) - public constructor(message: String, cause: Throwable) : super(message, cause) - public constructor(cause: Throwable) : super(cause) + public constructor(message: String?) : super(message) + public constructor(message: String?, cause: Throwable) : super(message, cause) + public constructor(cause: Throwable?) : super(cause) } diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/AppException.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/AppException.kt index 54eba9b83f..63dcf9e363 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/AppException.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/AppException.kt @@ -94,5 +94,5 @@ import io.realm.kotlin.exceptions.RealmException * @see SyncException */ public open class AppException internal constructor( - message: String, + message: String?, ) : RealmException(message) diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt index 2e6806062d..ce4da552f7 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt @@ -31,7 +31,7 @@ import io.realm.kotlin.types.RealmAny * * @see io.realm.kotlin.mongodb.sync.SyncConfiguration.Builder.errorHandler */ -public open class SyncException internal constructor(message: String) : AppException(message) +public open class SyncException internal constructor(message: String?) : AppException(message) /** * Thrown when something has gone wrong with Device Sync in a way that is not recoverable. @@ -60,7 +60,7 @@ public class WrongSyncTypeException internal constructor(message: String) : Sync * Thrown when the server does not support one or more of the queries defined in the * [io.realm.kotlin.mongodb.sync.SubscriptionSet]. */ -public class BadFlexibleSyncQueryException internal constructor(message: String) : +public class BadFlexibleSyncQueryException internal constructor(message: String?) : SyncException(message) /** diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/SubscriptionSetImpl.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/SubscriptionSetImpl.kt index 9a82592ec0..6f0baef67b 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/SubscriptionSetImpl.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/SubscriptionSetImpl.kt @@ -127,7 +127,7 @@ internal class SubscriptionSetImpl( if (result) { return true } else { - throw BadFlexibleSyncQueryException(errorMessage!!) + throw BadFlexibleSyncQueryException(errorMessage) } } else -> throw IllegalStateException("Unexpected value: $result") From 2db251a1b8f5b987cd34dcb347259c934bf50cb0 Mon Sep 17 00:00:00 2001 From: Clemente Date: Fri, 7 Jun 2024 09:45:07 +0200 Subject: [PATCH 2/4] Fix expected message --- .../io/realm/kotlin/test/mongodb/common/CredentialsTests.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt index d76391c980..53f3bf8fb8 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt @@ -369,7 +369,7 @@ class CredentialsTests { payload = mapOf("mail" to TestHelper.randomEmail(), "id" to 0) ) - assertFailsWithMessage("unauthorized") { + assertFailsWithMessage("Authentication failed") { runBlocking { app.login(credentials) } From 749004d8e418d75a015d2a5356ba2ef1ca54b436 Mon Sep 17 00:00:00 2001 From: Clemente Date: Fri, 7 Jun 2024 13:43:53 +0200 Subject: [PATCH 3/4] add test packages into sha calculation --- .github/workflows/include-check-cache.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/include-check-cache.yml b/.github/workflows/include-check-cache.yml index 5ce3783432..c7bfb275e4 100644 --- a/.github/workflows/include-check-cache.yml +++ b/.github/workflows/include-check-cache.yml @@ -93,7 +93,7 @@ jobs: # This also include changes to Realm Core as they are hashed as part of `/packages/external/core` - name: Calculate ./packages SHAs id: packages-cache-key - run: echo "sha=${{ hashFiles('./packages/**', './buildSrc/**', '!./packages/test-base/**', '!./packages/test-sync/**') }}" >> $GITHUB_OUTPUT + run: echo "sha=${{ hashFiles('./packages/**', './buildSrc/**') }}" >> $GITHUB_OUTPUT - name: Calculate ./benchmarks SHAs id: calculate-benchmarks-cache-key From fbe91f464b433e30d9b7a3427d20dab05bade001 Mon Sep 17 00:00:00 2001 From: Clemente Date: Fri, 7 Jun 2024 14:01:44 +0200 Subject: [PATCH 4/4] Modify nullability for cause parameter --- .../kotlin/io/realm/kotlin/exceptions/RealmException.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt b/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt index 7ed41d4b6e..bc0f9d945d 100644 --- a/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt +++ b/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/exceptions/RealmException.kt @@ -10,6 +10,6 @@ package io.realm.kotlin.exceptions public open class RealmException : RuntimeException { public constructor() : super() public constructor(message: String?) : super(message) - public constructor(message: String?, cause: Throwable) : super(message, cause) + public constructor(message: String?, cause: Throwable?) : super(message, cause) public constructor(cause: Throwable?) : super(cause) }