Skip to content

Commit 0cc9bc9

Browse files
fix: null pointer in updateHasSynced (#118)
* fix: revert updateHasSynced change that removed null pointer handling * fix: timestamp null pointer * docs: update changelog * chore: add null check * chore: add null check
1 parent 0c38635 commit 0cc9bc9

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.0.0-BETA22
4+
* Fix `updateHasSynced` internal null pointer exception
5+
36
## 1.0.0-BETA21
47

58
* Improve error handling for Swift by adding @Throws annotation so errors can be handled in Swift

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,24 @@ internal class PowerSyncDatabaseImpl(
279279
}
280280

281281
private suspend fun updateHasSynced() {
282-
// Query the database to see if any data has been synced.
282+
data class SyncedAt(
283+
val syncedAt: String?,
284+
)
285+
// Query the database to see if any data has been synced
283286
val timestamp =
284-
internalDb.getOptional("SELECT powersync_last_synced_at() as synced_at", null) { cursor ->
285-
cursor.getString(0) ?: ""
287+
internalDb
288+
.getOptional("SELECT powersync_last_synced_at() as synced_at", null) { cursor ->
289+
SyncedAt(syncedAt = cursor.getStringOptional("synced_at"))
290+
}?.syncedAt
291+
if (timestamp != null) {
292+
val hasSynced = true
293+
if (currentStatus.hasSynced != null && hasSynced != currentStatus.hasSynced) {
294+
val formattedDateTime = "${timestamp.replace(" ", "T").toLocalDateTime()}Z"
295+
val lastSyncedAt = Instant.parse(formattedDateTime)
296+
currentStatus.update(hasSynced = hasSynced, lastSyncedAt = lastSyncedAt)
286297
}
287-
288-
val hasSynced = timestamp != ""
289-
if (hasSynced != currentStatus.hasSynced) {
290-
val formattedDateTime = "${timestamp!!.replace(" ", "T").toLocalDateTime()}Z"
291-
val lastSyncedAt = Instant.parse(formattedDateTime)
292-
currentStatus.update(hasSynced = hasSynced, lastSyncedAt = lastSyncedAt)
298+
} else {
299+
currentStatus.update(hasSynced = false)
293300
}
294301
}
295302

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ development=true
1717
RELEASE_SIGNING_ENABLED=true
1818
# Library config
1919
GROUP=com.powersync
20-
LIBRARY_VERSION=1.0.0-BETA21
20+
LIBRARY_VERSION=1.0.0-BETA22
2121
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
2222
# POM
2323
POM_URL=https://github.com/powersync-ja/powersync-kotlin/

0 commit comments

Comments
 (0)