Skip to content

Instantly share code, notes, and snippets.

@nesterchung
Created June 7, 2018 09:18
Show Gist options
  • Save nesterchung/6905c09f142a7a493e95f2a2bd3b20ce to your computer and use it in GitHub Desktop.
Save nesterchung/6905c09f142a7a493e95f2a2bd3b20ce to your computer and use it in GitHub Desktop.
Serializable crash demo
class A : Serializable {
var b: B? = null
}
// without serializable
class B {
}
fun main(args: Array<String>) {
val a = A()
val oos = ObjectOutputStream(ByteArrayOutputStream())
oos.writeObject(a)
oos.close() //ok
val a2 = A()
a2.b = B() // put an non serializable object
val oos2 = ObjectOutputStream(ByteArrayOutputStream())
oos2.writeObject(a2)
oos2.close() //gg
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment