File: t2511.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (35 lines) | stat: -rw-r--r-- 854 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
object Test {

  import java.io._

  trait IMyMessage extends Serializable {
    @transient var message: String = null
    var message2: String = null
  }

  class MyMessage extends IMyMessage

  def serialize = {
    val buf = new ByteArrayOutputStream(10000)
    val out = new ObjectOutputStream(buf)
    val m = new MyMessage
    m.message = "foo"
    m.message2 = "bippy"
    out.writeObject(m)
    out.flush
    buf.toByteArray
  }

  def unserialize(buf:Array[Byte]) = {
    val in = new ObjectInputStream(new ByteArrayInputStream(buf))
    in.readObject.asInstanceOf[MyMessage]
  }

  def main(args: Array[String]) {
    val m = unserialize(serialize)
    // Xcheckinit freaks out here but its nullness is what we're testing
    try println(m.message)
    catch { case _: UninitializedFieldError => println("null") }
    println(m.message2)
  }
}