From 2b4b8bbe9ddf86bfbc1500cdab404fac2b687c14 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 3 Oct 2011 18:29:45 +0000 Subject: Repairing bitrot with serialization. The comment in SyntheticMethods and the comment in the serialization test said exactly opposite things. The logic at work all seems to be invalid anyway since nested objects are not treated like lazy vals, they have no bitmap. Serialize everything serializable. Review by plocinic. --- .../scala/tools/nsc/typechecker/SyntheticMethods.scala | 13 ++++--------- test/files/jvm/serialization.scala | 17 +++++------------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 95fb104f5f..eca33b1aa7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -340,18 +340,13 @@ trait SyntheticMethods extends ast.TreeDSL { ) /** If you serialize a singleton and then deserialize it twice, - * you will have two instances of your singleton, unless you implement - * the readResolve() method (see http://www.javaworld.com/javaworld/ - * jw-04-2003/jw-0425-designpatterns_p.html) + * you will have two instances of your singleton unless you implement + * readResolve. Here it is implemented for all objects which have + * no implementation and which are marked serializable (which is true + * for all case objects.) */ - - // Only nested objects inside objects should get readResolve automatically. - // Otherwise, after de-serialization we get null references for lazy accessors - // (nested object -> lazy val + class def) since the bitmap gets serialized but - // the moduleVar not. def needsReadResolve = ( clazz.isModuleClass - && clazz.owner.isModuleClass && clazz.isSerializable && !hasConcreteImpl(nme.readResolve) ) diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala index 1056f99848..af842f3e78 100644 --- a/test/files/jvm/serialization.scala +++ b/test/files/jvm/serialization.scala @@ -526,29 +526,22 @@ class Outer extends Serializable { object Test7 { val x = new Outer x.Inner // initialize - try { - val y:Outer = read(write(x)) - if (y.Inner == null) - println("Inner object is null") - } - catch { - case e: Exception => - println("Error in Test7: " + e) - } - + val y:Outer = read(write(x)) + if (y.Inner == null) + println("Inner object is null") } - // Verify that transient lazy vals don't get serialized class WithTransient extends Serializable { @transient lazy val a1 = 1 @transient private lazy val a2 = 2 @transient object B extends Serializable + @transient private object C extends Serializable def test = { println(a1) println(a2) - if (B == null) + if (B == null || C == null) println("Transient nested object failed to serialize properly") } } -- cgit v1.2.3