Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transient lazy vals should not null out fields and NPE #9365

Closed
scabug opened this issue Jun 25, 2015 · 3 comments
Closed

Transient lazy vals should not null out fields and NPE #9365

scabug opened this issue Jun 25, 2015 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 25, 2015

When lazy vals are transient, the optimization in #720 is invalid, leading to NPEs. For instance

class Test(x: => Object) extends Serializable {
  @transient lazy val foo = x
}

object Foo {
  def main(args: Array[String]): Unit = {
    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)
  }
}
foo
Exception in thread "main" java.lang.NullPointerException
	at test.Test.foo$lzycompute(Foo.scala:33)
	at test.Test.foo(Foo.scala:33)
	at test.Foo$.main(Foo.scala:46)
	at test.Foo.main(Foo.scala)
@scabug
Copy link
Author

scabug commented Jun 25, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9365?orig=1
Reporter: @dragos
Affected Versions: 2.11.7
See #720

@scabug
Copy link
Author

scabug commented Jul 27, 2015

@retronym said:
I just prepared a patch for this one.

scala/scala#4661

@lrytz Just saw you self-assigned this yesterday, hopefully you hadn't started work on it.

@scabug scabug closed this as completed Jul 28, 2015
@scabug
Copy link
Author

scabug commented Jul 28, 2015

@lrytz said:
thanks for work stealing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants