Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.5.27 regression] serializedSize does not work with java serialization #121

Closed
eiennohito opened this issue Jun 1, 2016 · 1 comment
Closed

Comments

@eiennohito
Copy link
Contributor

eiennohito commented Jun 1, 2016

Do not use 0.5.27, 0.5.28 if you serialize case classes with java serialization and then serialize them as protobufs.

I am working on the fix.

@eiennohito
Copy link
Contributor Author

eiennohito commented Jun 1, 2016

Reproducible as:

  def checkJavaSerialization[T <: GeneratedMessage](a: T) = {
    val baos = new ByteArrayOutputStream()
    val oos = new ObjectOutputStream(baos)

    oos.writeObject(a)
    oos.close()

    val ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray))
    val b = ois.readObject().asInstanceOf[T]
    val abytes = a.toByteArray
    val bbytes = b.toByteArray //crashes here

    abytes mustBe bbytes
  }

Stacktrace like:

com.google.protobuf.CodedOutputStream$OutOfSpaceException: CodedOutputStream was writing to a flat byte array and ran out of space.
    at com.google.protobuf.CodedOutputStream.refreshBuffer(CodedOutputStream.java:990)
    at com.google.protobuf.CodedOutputStream.writeRawByte(CodedOutputStream.java:1069)
    at com.google.protobuf.CodedOutputStream.writeRawByte(CodedOutputStream.java:1078)
    at com.google.protobuf.CodedOutputStream.writeRawVarint32(CodedOutputStream.java:1231)
    at com.google.protobuf.CodedOutputStream.writeTag(CodedOutputStream.java:1216)
    at com.google.protobuf.CodedOutputStream.writeString(CodedOutputStream.java:233)
    at com.trueaccord.proto.e2e.repeatables.RepeatablesTest$$anonfun$writeTo$4.apply(RepeatablesTest.scala:45)
    at com.trueaccord.proto.e2e.repeatables.RepeatablesTest$$anonfun$writeTo$4.apply(RepeatablesTest.scala:44)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at com.trueaccord.proto.e2e.repeatables.RepeatablesTest.writeTo(RepeatablesTest.scala:44)
    at com.trueaccord.scalapb.GeneratedMessage$class.toByteArray(GeneratedMessageCompanion.scala:81)
    at com.trueaccord.proto.e2e.repeatables.RepeatablesTest.toByteArray(RepeatablesTest.scala:11)
    at JavaSerializationSpec.checkJavaSerialization(JavaSerializationSpec.scala:33)

thesamet added a commit that referenced this issue Jun 1, 2016
fixes #121: java serialization breaks serializedSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant