This page is no longer maintained — Please continue to the home page at

Problem in the compiler that break serialization: closures in inizializer of structural types

No replies
Joined: 2011-04-05,
User offline. Last seen 1 year 27 weeks ago.
In working on my scala layer on top of hadoop I have encontered the following issue with the code generated by the compiler that breaks serialization. It is not a big deal normally, but it is a very annoying and difficult problem to track, and if solved might help also the folks developing spark, which I heard ran into similar issues.


object SerializerBug {
def main(args: Array[String]): Unit = {
val a = 1
val b = "hello, world"
val obj = new { val f = () => println(a.toString + " " + b) }


new ObjectOutputStream(new ByteArrayOutputStream).writeObject(obj)

breaks with the following output:
1 hello, world
Exception in thread "main" SerializerBug$$anon$1
at SerializerBug$.main(SerializerBug.scala:14)
at SerializerBug.main(SerializerBug.scala)

I added it to jira:

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland