From 031369f75a84be49765d6f10a79532e3f24cee65 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Fri, 17 Apr 2026 20:39:39 +0300 Subject: [PATCH] Avoid EmptyList cannot be cast to ArrayList warning --- app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt | 8 ++++++-- app/src/main/kotlin/com/tutpro/baresip/Message.kt | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt index cc8eacd9..6be81d16 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt @@ -84,7 +84,9 @@ class CallHistoryNew(val aor: String, val peerUri: String, val direction: String val fis = FileInputStream(file) val ois = ObjectInputStream(fis) @Suppress("UNCHECKED_CAST") - BaresipService.callHistory = ois.readObject() as ArrayList + val restoredHistory = ois.readObject() as? List + if (restoredHistory != null) + BaresipService.callHistory = ArrayList(restoredHistory) ois.close() fis.close() Log.d(TAG, "Restored history of ${BaresipService.callHistory.size} calls") @@ -132,7 +134,9 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) : val fis = FileInputStream(file) val ois = ObjectInputStream(fis) @Suppress("UNCHECKED_CAST") - result = ois.readObject() as ArrayList + val restoredHistory = ois.readObject() as? List + if (restoredHistory != null) + result = ArrayList(restoredHistory) ois.close() fis.close() Log.d(TAG, "Got history of ${result.size} calls") diff --git a/app/src/main/kotlin/com/tutpro/baresip/Message.kt b/app/src/main/kotlin/com/tutpro/baresip/Message.kt index d175951c..bf27a753 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Message.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Message.kt @@ -123,7 +123,9 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim val fis = FileInputStream(file) val ois = ObjectInputStream(fis) @Suppress("UNCHECKED_CAST") - BaresipService.messages = ois.readObject() as ArrayList + val restoredMessages = ois.readObject() as? List + if (restoredMessages != null) + BaresipService.messages = restoredMessages ois.close() fis.close() Log.d(TAG, "Restored ${BaresipService.messages.size} messages")