mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Don't crash on unexpected deserialization error
This commit is contained in:
parent
bb850cf99e
commit
c5e0589751
@ -21,7 +21,7 @@ interface Job {
|
||||
fun getFactoryKey(): String
|
||||
|
||||
interface Factory<T : Job> {
|
||||
|
||||
fun create(data: Data): T
|
||||
|
||||
fun create(data: Data): T?
|
||||
}
|
||||
}
|
@ -104,17 +104,29 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
||||
|
||||
class Factory : Job.Factory<MessageSendJob> {
|
||||
|
||||
override fun create(data: Data): MessageSendJob {
|
||||
override fun create(data: Data): MessageSendJob? {
|
||||
val serializedMessage = data.getByteArray(MESSAGE_KEY)
|
||||
val serializedDestination = data.getByteArray(DESTINATION_KEY)
|
||||
val kryo = Kryo()
|
||||
// Message
|
||||
val messageInput = Input(serializedMessage)
|
||||
val message = kryo.readClassAndObject(messageInput) as Message
|
||||
val message: Message
|
||||
try {
|
||||
message = kryo.readClassAndObject(messageInput) as Message
|
||||
} catch (e: Exception) {
|
||||
Log.e("Loki", "Couldn't deserialize message send job.", e)
|
||||
return null
|
||||
}
|
||||
messageInput.close()
|
||||
// Destination
|
||||
val destinationInput = Input(serializedDestination)
|
||||
val destination = kryo.readClassAndObject(destinationInput) as Destination
|
||||
val destination: Destination
|
||||
try {
|
||||
destination = kryo.readClassAndObject(destinationInput) as Destination
|
||||
} catch (e: Exception) {
|
||||
Log.e("Loki", "Couldn't deserialize message send job.", e)
|
||||
return null
|
||||
}
|
||||
destinationInput.close()
|
||||
// Return
|
||||
return MessageSendJob(message, destination)
|
||||
|
Loading…
Reference in New Issue
Block a user