summaryrefslogtreecommitdiff
path: root/test/files/run/t10075.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-11-30 13:42:36 -0800
committerAdriaan Moors <adriaan@lightbend.com>2016-12-05 08:47:34 +0100
commit7a57c6eec6c37e8ca3a7f182f0cf2604d7bc80df (patch)
treee880de7e67ec2144096660faa3ab4b5dbf41d6f9 /test/files/run/t10075.scala
parent0339663cbbd4d22b0758257f2ce078b5a007f316 (diff)
downloadscala-7a57c6eec6c37e8ca3a7f182f0cf2604d7bc80df.tar.gz
scala-7a57c6eec6c37e8ca3a7f182f0cf2604d7bc80df.tar.bz2
scala-7a57c6eec6c37e8ca3a7f182f0cf2604d7bc80df.zip
SI-10075 annotations go to lazy val's underlying field
This likely regressed in #5294. Review feedback from retronym: - Tie annotation triaging a bit closer together durban kindly provided initial version of test/files/run/t10075.scala And pointed out you must force `lazy val`, since `null`-valued field is serializable regardless of its type. Test test/files/run/t10075b courtesy of retronym
Diffstat (limited to 'test/files/run/t10075.scala')
-rw-r--r--test/files/run/t10075.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/files/run/t10075.scala b/test/files/run/t10075.scala
new file mode 100644
index 0000000000..e7564c5c8b
--- /dev/null
+++ b/test/files/run/t10075.scala
@@ -0,0 +1,35 @@
+class NotSerializable
+
+trait SerializableActually {
+ @transient
+ lazy val notSerializedTLV: NotSerializable = new NotSerializable
+
+ @transient
+ val notSerializedTL: NotSerializable = new NotSerializable
+
+ @transient
+ var notSerializedTR: NotSerializable = new NotSerializable
+}
+
+class SerializableBecauseTransient extends Serializable with SerializableActually {
+ @transient
+ lazy val notSerializedLV: NotSerializable = new NotSerializable
+
+ @transient
+ val notSerializedL: NotSerializable = new NotSerializable
+
+ @transient
+ var notSerializedR: NotSerializable = new NotSerializable
+}
+
+// Indirectly check that the @transient annotation on `notSerialized` made it to the underyling field in bytecode.
+// If it doesn't, `writeObject` will fail to serialize the field `notSerialized`, because `NotSerializable` is not serializable
+object Test {
+ def main(args: Array[String]): Unit = {
+ val obj = new SerializableBecauseTransient
+ // must force, since `null` valued field is serialized regardless of its type
+ val forceTLV = obj.notSerializedTLV
+ val forceLV = obj.notSerializedLV
+ new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream) writeObject obj
+ }
+}