diff options
author | Philipp Haller <hallerp@gmail.com> | 2010-03-24 09:58:24 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2010-03-24 09:58:24 +0000 |
commit | 172b58c99fbbcc32c79a27605e351da936e734f5 (patch) | |
tree | f01c04b080c7f42237c91147854ad679441d2d84 /src/library | |
parent | 787e286505f4094e76da75038edd44f6e6d5a37f (diff) | |
download | scala-172b58c99fbbcc32c79a27605e351da936e734f5.tar.gz scala-172b58c99fbbcc32c79a27605e351da936e734f5.tar.bz2 scala-172b58c99fbbcc32c79a27605e351da936e734f5.zip |
Fixed the serialization test.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Enumeration.scala | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 205cf1cf84..09504046ea 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -70,19 +70,25 @@ abstract class Enumeration(initial: Int, names: String*) { def this() = this(0, null) def this(names: String*) = this(0, names: _*) - Enumeration.emap.get(getClass) match { - case None => - Enumeration.emap += (getClass -> this) - case Some(_) => - /* do nothing */ + Enumeration.synchronized { + Enumeration.emap.get(getClass) match { + case None => + Enumeration.emap += (getClass -> this) + case Some(_) => + /* do nothing */ + } } - private def readResolve(): AnyRef = Enumeration.emap.get(getClass) match { - case None => - Enumeration.emap += (getClass -> this) - this - case Some(existing) => - existing + /* Note that `readResolve` cannot be private, since otherwise + the JVM does not invoke it when deserializing subclasses. */ + protected def readResolve(): AnyRef = Enumeration.synchronized { + Enumeration.emap.get(getClass) match { + case None => + Enumeration.emap += (getClass -> this) + this + case Some(existing) => + existing + } } /** The name of this enumeration. @@ -267,10 +273,12 @@ abstract class Enumeration(initial: Int, names: String*) { override def toString() = if (name eq null) Enumeration.this.nameOf(i) else name - private def readResolve(): AnyRef = { - val enum = Enumeration.emap.get(Enumeration.this.getClass) match { - case None => Enumeration.this - case Some(existing) => existing + protected def readResolve(): AnyRef = { + val enum = Enumeration.synchronized { + Enumeration.emap.get(Enumeration.this.getClass) match { + case None => Enumeration.this + case Some(existing) => existing + } } if (enum.vmap ne null) enum.vmap(i) else this |