diff options
author | Paul Phillips <paulp@improving.org> | 2009-12-01 18:28:55 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-12-01 18:28:55 +0000 |
commit | a3bf3f136caaefa98268607a3529b7554df5fc80 (patch) | |
tree | 220322df1130f864af06661baca1b7f4434ee32d /src/library/scala/collection/immutable/HashMap.scala | |
parent | c2359ccec521ed24641fb010774e7b39b4ae62b2 (diff) | |
download | scala-a3bf3f136caaefa98268607a3529b7554df5fc80.tar.gz scala-a3bf3f136caaefa98268607a3529b7554df5fc80.tar.bz2 scala-a3bf3f136caaefa98268607a3529b7554df5fc80.zip |
[This patch submitted by ismael juma - commit m...
[This patch submitted by ismael juma - commit message his words,
but condensed.]
Fix ticket #1600: Serialization and deserialization of hash-based
collections should not re-use hashCode. The collection is rebuilt
on deserialization - note that this is not compatible with the previous
serialization format. All @SerialVersionUIDs have been reset to 1.
WeakHashMap is not Serializable and should not be so. TreeHashMap has
not been reintegrated yet. OpenHashMap has not been updated. (I think
this collection is flawed and should be removed or reimplemented.)
Diffstat (limited to 'src/library/scala/collection/immutable/HashMap.scala')
-rw-r--r-- | src/library/scala/collection/immutable/HashMap.scala | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index a036a9abfb..7825d62527 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -33,15 +33,15 @@ import annotation.unchecked.uncheckedVariance * @version 2.0, 19/01/2007 * @since 2.3 */ -@serializable @SerialVersionUID(8886909077084990906L) +@serializable @SerialVersionUID(1L) class HashMap[A, +B] extends Map[A,B] with MapLike[A, B, HashMap[A, B]] with mutable.HashTable[A] { type Entry = scala.collection.mutable.DefaultEntry[A, Any] - protected var later: HashMap[A, B @uncheckedVariance] = null - protected var oldKey: A = _ - protected var oldValue: Option[B @uncheckedVariance] = _ - protected var deltaSize: Int = _ + @transient protected var later: HashMap[A, B @uncheckedVariance] = null + @transient protected var oldKey: A = _ + @transient protected var oldValue: Option[B @uncheckedVariance] = _ + @transient protected var deltaSize: Int = _ override def empty = HashMap.empty[A, B] @@ -125,10 +125,12 @@ class HashMap[A, +B] extends Map[A,B] with MapLike[A, B, HashMap[A, B]] with mut private def logLimit: Int = math.sqrt(table.length).toInt private[this] def markUpdated(key: A, ov: Option[B], delta: Int) { - val lv = loadFactor + val lf = loadFactor later = new HashMap[A, B] { override def initialSize = 0 - override def loadFactor = lv + /* We need to do this to avoid a reference to the outer HashMap */ + _loadFactor = lf + override def loadFactor = _loadFactor table = HashMap.this.table tableSize = HashMap.this.tableSize threshold = HashMap.this.threshold @@ -174,6 +176,14 @@ class HashMap[A, +B] extends Map[A,B] with MapLike[A, B, HashMap[A, B]] with mut while (m.later != null) m = m.later if (m ne this) makeCopy(m) } + + private def writeObject(out: java.io.ObjectOutputStream) { + serializeTo(out, _.value) + } + + private def readObject(in: java.io.ObjectInputStream) { + init[B](in, new Entry(_, _)) + } } /** A factory object for immutable HashMaps. |