I've just starting playing with Scala 2.8 (nightly builds) on a largish
project. I've noticed some changed behaviour for @transient annotations.
I wanted to check here with those more familiar with 2.8 before logging a
bug. Executing Test.run in the test code below returns null in Scala 2.7,
which is what I expect since 'message' is transient, and "foo" in Scala
2.8:
object Test {
trait IMyMessage extends java.io.Serializable {
@transient var message:String = null
}
class MyMessage extends IMyMessage
import java.io._
def serialize = {
val buf = new ByteArrayOutputStream(10000)
val out = new ObjectOutputStream(buf)
val m = new MyMessage
m.message = "foo"
out.writeObject(m)
out.flush
buf.toByteArray
}
def unserialize(buf:Array[Byte]) = {
val in = new ObjectInputStream(new ByteArrayInputStream(buf))
in.readObject.asInstanceOf[MyMessage]
}
def run = {
val m = unserialize(serialize)
m.message
}
}
This seems to only occur when the transient annotation is in an inherited
trait.
For me, it breaks my application when Wicket or DB4O try to serialise
something that wasn't meant to be serialised.
Cheers,
Sam.