Skip to content

NodeSeq.Empty is not serializable #10445

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

Closed
joescii opened this issue Aug 1, 2017 · 5 comments
Closed

NodeSeq.Empty is not serializable #10445

joescii opened this issue Aug 1, 2017 · 5 comments

Comments

@joescii
Copy link

joescii commented Aug 1, 2017

It appears that the typical use case of NodeSeq serializes with no problems (I'm speaking of Node, which we can see here is marked as Serializable), but the NodeSeq.Empty surprisingly doesn't. I would expect it to behave like String where the empty string is trivially serializable.

Is there any reason that NodeSeq should not extend Serializable? The offender in the case of NodeSeq.Empty could trivially be marked to extend Serializable here

You can see the behavior below in this console session. Note that java version details are printed at the end. This was run on a MBP running Sierra 10.12.6.

[info] Starting scala interpreter...
[info] 
Welcome to Scala 2.12.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> import java.io._
import java.io._

scala> import scala.xml.NodeSeq
import scala.xml.NodeSeq

scala>       def serialize(in: Any): Array[Byte] = {
     |         val bos = new ByteArrayOutputStream()
     |         val oos = new ObjectOutputStream(bos)
     |         oos.writeObject(in)
     |         oos.flush()
     |         bos.toByteArray()
     |       }
serialize: (in: Any)Array[Byte]

scala> serialize("joescii")
res0: Array[Byte] = Array(-84, -19, 0, 5, 116, 0, 7, 106, 111, 101, 115, 99, 105, 105)

scala> serialize("")
res3: Array[Byte] = Array(-84, -19, 0, 5, 116, 0, 0)

scala> serialize(<joescii/>)
res1: Array[Byte] = Array(-84, -19, 0, 5, 115, 114, 0, 14, 115, 99, 97, 108, 97, 46, 120, 109, 108, 46, 69, 108, 101, 109, -121, -95, 0, -70, 78, 93, -40, -69, 2, 0, 6, 90, 0, 13, 109, 105, 110, 105, 109, 105, 122, 101, 69, 109, 112, 116, 121, 76, 0, 10, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 116, 0, 20, 76, 115, 99, 97, 108, 97, 47, 120, 109, 108, 47, 77, 101, 116, 97, 68, 97, 116, 97, 59, 76, 0, 5, 99, 104, 105, 108, 100, 116, 0, 22, 76, 115, 99, 97, 108, 97, 47, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 47, 83, 101, 113, 59, 76, 0, 5, 108, 97, 98, 101, 108, 116, 0, 18, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 76, 0, 6, 112, 114, 101, 102, 105, 120, 113, 0, 126, 0, 3, 76, 0, 5, 115, 99, 111, 112, 101, 11...

scala> val xml = <joescii/>
xml: scala.xml.Elem = <joescii/>

scala> serialize(xml)
res4: Array[Byte] = Array(-84, -19, 0, 5, 115, 114, 0, 14, 115, 99, 97, 108, 97, 46, 120, 109, 108, 46, 69, 108, 101, 109, -121, -95, 0, -70, 78, 93, -40, -69, 2, 0, 6, 90, 0, 13, 109, 105, 110, 105, 109, 105, 122, 101, 69, 109, 112, 116, 121, 76, 0, 10, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 116, 0, 20, 76, 115, 99, 97, 108, 97, 47, 120, 109, 108, 47, 77, 101, 116, 97, 68, 97, 116, 97, 59, 76, 0, 5, 99, 104, 105, 108, 100, 116, 0, 22, 76, 115, 99, 97, 108, 97, 47, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 47, 83, 101, 113, 59, 76, 0, 5, 108, 97, 98, 101, 108, 116, 0, 18, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 76, 0, 6, 112, 114, 101, 102, 105, 120, 113, 0, 126, 0, 3, 76, 0, 5, 115, 99, 111, 112, 101, 11...

scala> serialize(NodeSeq.Empty)
java.io.NotSerializableException: scala.xml.NodeSeq$$anon$1

  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1182)
  at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
  at .serialize(<console>:18)
  ... 39 elided

scala> 
descartes:lift-framework joescii$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
@joescii joescii changed the title NodeSeq.Empty is not serializable NodeSeq.Empty is not serializable Aug 1, 2017
@SethTisue
Copy link
Member

SethTisue commented Aug 2, 2017

good catch! but please open this issue at https://github.com/scala/scala-xml/issues instead (if it doesn't already exist there)

@som-snytt
Copy link

Probably this issue should be opened at https://github.com/scala/scala-xml/issues

There are conceivably issues with xml parsing in the compiler, but this seems to be an implementation issue.

@SethTisue
Copy link
Member

jinx

@som-snytt
Copy link

oh, I just had a @SethTisue jinx.

Ach, jinx, jinx! double jinx!

@joescii
Copy link
Author

joescii commented Aug 2, 2017

Thank you for pointing me to the correct repo. I knew XML was published separately, but after searches failed to find it for me I concluded wrongly that maybe they weren't separate source repos. :)

scala/scala-xml#154

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

3 participants