summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2015-07-28 09:38:34 +0200
committerLukas Rytz <lukas.rytz@typesafe.com>2015-07-28 09:38:34 +0200
commitd8da39a197a9a4405806128bba49ad706677896b (patch)
tree78b85bde53a8fbf5b28efd0d1f718ed236923dcf /test
parent2279d3f3d94b3b870a2620f47ac7b7e17e35c830 (diff)
parent0c99742c51706ee4b60a56a8f5babb13682f9b10 (diff)
downloadscala-d8da39a197a9a4405806128bba49ad706677896b.tar.gz
scala-d8da39a197a9a4405806128bba49ad706677896b.tar.bz2
scala-d8da39a197a9a4405806128bba49ad706677896b.zip
Merge pull request #4661 from retronym/ticket/9365
SI-9365 Don't null out dependencies of transient lazy vals
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t720.scala48
-rw-r--r--test/files/run/t9365.check2
-rw-r--r--test/files/run/t9365.scala18
3 files changed, 68 insertions, 0 deletions
diff --git a/test/files/run/t720.scala b/test/files/run/t720.scala
new file mode 100644
index 0000000000..a5cb2495cf
--- /dev/null
+++ b/test/files/run/t720.scala
@@ -0,0 +1,48 @@
+class Lazy(f: => Int) {
+ lazy val get: Int = f
+}
+
+class UsedLater(f: => Int) {
+ lazy val get: Int = f
+ def other = f
+}
+
+class TransientLazy(f: => Int) {
+ @transient
+ lazy val get: Int = f
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ testLazy()
+ testUsedLater()
+ }
+
+ def testLazy() {
+ val o = new Lazy("".length)
+ val f = classOf[Lazy].getDeclaredField("f")
+ f.setAccessible(true)
+ assert(f.get(o) != null)
+ o.get
+ assert(f.get(o) == null)
+ }
+
+ def testUsedLater() {
+ val o = new UsedLater("".length)
+ val f = classOf[UsedLater].getDeclaredField("f")
+ f.setAccessible(true)
+ assert(f.get(o) != null)
+ o.get
+ assert(f.get(o) != null)
+ }
+
+ def testTransientLazy() {
+ val o = new TransientLazy("".length)
+ val f = classOf[TransientLazy].getDeclaredField("f")
+ f.setAccessible(true)
+ assert(f.get(o) != null)
+ o.get
+ assert(f.get(o) != null) // SI-9365
+ }
+}
+
diff --git a/test/files/run/t9365.check b/test/files/run/t9365.check
new file mode 100644
index 0000000000..0d55bed3a3
--- /dev/null
+++ b/test/files/run/t9365.check
@@ -0,0 +1,2 @@
+foo
+foo
diff --git a/test/files/run/t9365.scala b/test/files/run/t9365.scala
new file mode 100644
index 0000000000..0c4477dda9
--- /dev/null
+++ b/test/files/run/t9365.scala
@@ -0,0 +1,18 @@
+class Test(x: => Object) extends Serializable {
+ @transient lazy val foo = x
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ import java.io._
+ val t = new Test("foo")
+ println(t.foo)
+ val baos = new ByteArrayOutputStream
+ val dos = new ObjectOutputStream(baos)
+ dos.writeObject(t)
+ dos.close()
+ val dis = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))
+ val t1 = dis.readObject().asInstanceOf[Test]
+ println(t1.foo) // was NPE
+ }
+}