From 24a8c528d05b8a6e250dc10cac78c4d4afbc34ab Mon Sep 17 00:00:00 2001 From: AsamK Date: Wed, 5 Apr 2023 11:22:43 +0200 Subject: [PATCH] Filter null from db result --- .../manager/storage/identities/IdentityKeyStore.java | 5 ++++- .../signal/manager/storage/sessions/SessionStore.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/identities/IdentityKeyStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/identities/IdentityKeyStore.java index 9ae8dda8..b1d89628 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/identities/IdentityKeyStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/identities/IdentityKeyStore.java @@ -15,6 +15,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; import java.util.List; +import java.util.Objects; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.subjects.PublishSubject; @@ -153,7 +154,9 @@ public class IdentityKeyStore { """ ).formatted(TABLE_IDENTITY); try (final var statement = connection.prepareStatement(sql)) { - return Utils.executeQueryForStream(statement, this::getIdentityInfoFromResultSet).toList(); + return Utils.executeQueryForStream(statement, this::getIdentityInfoFromResultSet) + .filter(Objects::nonNull) + .toList(); } } catch (SQLException e) { throw new RuntimeException("Failed read from identity store", e); diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/sessions/SessionStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/sessions/SessionStore.java index 564df1d0..0f267583 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/sessions/SessionStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/sessions/SessionStore.java @@ -247,7 +247,9 @@ public class SessionStore implements SignalServiceSessionStore { try (final var statement = connection.prepareStatement(sql)) { statement.setInt(1, accountIdType); records = Utils.executeQueryForStream(statement, - res -> new Pair<>(getKeyFromResultSet(res), getSessionRecordFromResultSet(res))).toList(); + res -> new Pair<>(getKeyFromResultSet(res), getSessionRecordFromResultSet(res))) + .filter(Objects::nonNull) + .toList(); } for (final var record : records) { record.second().archiveCurrentState(); @@ -274,7 +276,9 @@ public class SessionStore implements SignalServiceSessionStore { statement.setInt(1, accountIdType); statement.setBytes(2, serviceId.toByteArray()); records = Utils.executeQueryForStream(statement, - res -> new Pair<>(getKeyFromResultSet(res), getSessionRecordFromResultSet(res))).toList(); + res -> new Pair<>(getKeyFromResultSet(res), getSessionRecordFromResultSet(res))) + .filter(Objects::nonNull) + .toList(); } for (final var record : records) { record.second().archiveCurrentState();