Skip to content

Commit e3d3c67

Browse files
committed
fix for #114: issue with specialized types in WrappedArray instances
1 parent 636b1b4 commit e3d3c67

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

chill-scala/src/main/scala/com/twitter/chill/WrappedArraySerializer.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,25 @@ package com.twitter.chill
1818

1919
import scala.collection.mutable.{WrappedArray, WrappedArrayBuilder}
2020

21-
class WrappedArraySerializer[T] extends KSerializer[WrappedArray[T]] {
21+
class WrappedArraySerializer[T: ClassManifest] extends KSerializer[WrappedArray[T]] {
2222

2323
def write(kser: Kryo, out: Output, obj: WrappedArray[T]) {
24-
// Write the class-manifest, we don't use writeClass because it
25-
// uses the registration system, and this class might not be registered
26-
kser.writeObject(out, obj.elemManifest.erasure)
2724
out.writeInt(obj.size, true)
2825
obj.foreach { t =>
2926
val tRef = t.asInstanceOf[AnyRef]
30-
kser.writeObject(out, tRef)
27+
kser.writeClassAndObject(out, tRef)
3128
// After each intermediate object, flush
32-
out.flush
29+
out.flush()
3330
}
3431
}
3532

3633
def read(kser: Kryo, in: Input, cls: Class[WrappedArray[T]]) = {
37-
// Write the class-manifest, we don't use writeClass because it
38-
// uses the registration system, and this class might not be registered
39-
val clazz = kser.readObject(in, classOf[Class[T]]).asInstanceOf[Class[T]]
4034
val size = in.readInt(true)
41-
val bldr = new WrappedArrayBuilder[T](ClassManifest.fromClass[T](clazz))
35+
val bldr = new WrappedArrayBuilder[T](classManifest[T])
4236
bldr.sizeHint(size)
4337
(0 until size).foreach { idx =>
44-
bldr += kser.readObject(in, clazz)
38+
bldr += kser.readClassAndObject(in).asInstanceOf[T]
4539
}
46-
bldr.result
40+
bldr.result()
4741
}
4842
}

chill-scala/src/test/scala/com/twitter/chill/KryoSpec.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ class KryoSpec extends Specification with BaseProperties {
9797
arrayRT(Array(0.1))
9898
arrayRT(Array("hey"))
9999
arrayRT(Array((0,1)))
100+
arrayRT(Array((0,1), (1,0)))
100101
arrayRT(Array(None, Nil, None, Nil))
101102
}
103+
"handle WrappedArray instances" in {
104+
val tests = Seq(
105+
Array((1,1), (2,2), (3,3)).toSeq,
106+
Array((1.0, 1.0), (2.0, 2.0)).toSeq,
107+
Array((1.0, "1.0"), (2.0, "2.0")).toSeq)
108+
tests.foreach { test => rt(test) must be_==(test) }
109+
}
102110
"handle lists of lists" in {
103111
val lol = List(("us", List(1)), ("jp", List(3, 2)), ("gb", List(3, 1)))
104112
rt(lol) must be_==(lol)

0 commit comments

Comments
 (0)