Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

BinaryPickle - unpickling something that contains empty Maps fails #303

Open
@ktoso

Description

@ktoso
package com.typesafe

import akka.util.ByteString
import akka.actor.Address
import akka.serialization.Serializer
import scala.pickling._
import scala.pickling.Defaults._
import scala.pickling.binary._

import scala.pickling.binary.BinaryPickle

class SanitySpec extends AkkaUnitTest {

  case class MyValue(protocol: String, servicePort: Int, serviceName: String)

  "Binary and Map[String, Map[String, MyValue]" should {

    // this is OK:
    "pickle" in {
      val bytes = Map("hello" -> Map("one" -> MyValue("pop", 23, "email"))).pickle.value
      val got = BinaryPickle(bytes).unpickle[Map[String, Map[String, MyValue]]]
    }

    // this is OK:
    "pickle empty inner - with types" in {
      val bytes = Map("hello" -> Map[String, MyValue]()).pickle.value
      val got = BinaryPickle(bytes).unpickle[Map[String, Map[String, MyValue]]]
    }


   // this FAILS:
    "pickle empty inner - no types" in {
      val bytes = Map("hello" -> Map()).pickle.value
      info("pickle = " + ByteString(bytes).utf8String)
      val got = BinaryPickle(bytes).unpickle[Map[String, Map[String, MyValue]]]
/*
[info] - should pickle empty inner - no types *** FAILED ***
[info]   java.lang.ArrayIndexOutOfBoundsException: 263
[info]   at scala.pickling.binary.ByteArrayInput.getInt(BinaryInput.scala:156)
[info]   at scala.pickling.binary.BinaryPickleReader.readLength(BinaryPickle.scala:255)
[info]   at scala.pickling.pickler.TravPickler$$anon$1.unpickle(Iterable.scala:59)
[info]   at com.typesafe.SanitySpec$$anonfun$2$$anonfun$apply$mcV$sp$4$ScalaTuple2$u005BjavaLangString$u002CscalaCollectionImmutableMap$u005BjavaLangString$u002CScalaPicklingSerializerSpecThisMyValue$u005D$u005DUnpickler$macro$619$2$.unpickle(ScalaPicklingSerializerSpec.scala:58)
[info]   at scala.pickling.Unpickler$class.unpickleEntry(Pickler.scala:81)
[info]   at com.typesafe.SanitySpec$$anonfun$2$$anonfun$apply$mcV$sp$4$ScalaTuple2$u005BjavaLangString$u002CscalaCollectionImmutableMap$u005BjavaLangString$u002CScalaPicklingSerializerSpecThisMyValue$u005D$u005DUnpickler$macro$619$2$.unpickleEntry(ScalaPicklingSerializerSpec.scala:58)
[info]   at scala.pickling.pickler.TravPickler$$anon$1.unpickle(Iterable.scala:64)
[info]   at scala.pickling.Unpickler$class.unpickleEntry(Pickler.scala:81)
[info]   at scala.pickling.pickler.TravPickler$$anon$1.unpickleEntry(Iterable.scala:18)
[info]   at scala.pickling.functions$.unpickle(functions.scala:11)
[info]   ...
*/
    }

  }
}

The pickled bytes look like this:

[info]   + pickle = lscala.collection.immutable.Map[java.lang.String,scala.collection.immutable.Map[scala.Nothing,scala.Nothing]]Zscala.Tuple2[java.lang.String,scala.collection.immutable.Map[scala.Nothing,scala.Nothing]]hello(scala.collection.immutable.Map$EmptyMap$

So yeah, Nothing is inferred and captures, but it still should be able to deserialize I think, using an empty Map literal is very useful at times - initialising empty data structures etc.

// this was on 0.10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions