summaryrefslogtreecommitdiff
path: root/test/files/jvm/t1143.scala
blob: eb03c7224ee4274115e099806e30fc93523e781c (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
object Serialize {
  @throws(classOf[java.io.IOException])
  def write[A](o: A): Array[Byte] = {
    val ba = new java.io.ByteArrayOutputStream(512)
    val out = new java.io.ObjectOutputStream(ba)
    out.writeObject(o)
    out.close()
    ba.toByteArray()
  }
  @throws(classOf[java.io.IOException])
  @throws(classOf[ClassNotFoundException])
  def read[A](buffer: Array[Byte]): A = {
    val in =
      new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer))
    in.readObject().asInstanceOf[A]
  }
}

@SerialVersionUID(1L)
class VarModel[T](getter: => T, setter: T => Unit) extends Serializable {
  Serialize.write(getter)
  Serialize.write(setter)

  def this(getter: => T) = this(getter, null)

  def getObject: AnyRef = getter.asInstanceOf[AnyRef]

  def setObject(v: AnyRef) = {
    if (setter == null)
      throw new RuntimeException("Tried to set readonly model!")
    setter(v.asInstanceOf[T])
  }

  def detach = ()
}

@SerialVersionUID(1L)
class Printer(p: VarModel[String]) extends Serializable {
  def print = println(p.getObject)
}

@SerialVersionUID(1L)
class Component extends Serializable {
}

class Form extends Component {
}

@SerialVersionUID(1L)
class Main extends Serializable {
  var pass = "pass"
  def main(args: Array[String]) {
    val f = new Form {
      val p = new Printer(new VarModel(pass, s => pass = s))
    }
    ()
  }
}

object Test {
  def main(args: Array[String]) {
    (new Main).main(Array[String]())
  }
}