Scala Programming Language
  1. Scala Programming Language
  2. SI-6961

List serialization/deserialization can overflow the stack

    Details

      Description

      Compiling and running this program will result in the issue that it overflows the stack at runtime in 2.10 but not in 2.9. Please fix this - it's a critical bug.

      object ListSer extends App {
      
        val largeList = (1 to 1000000).toList
      
        val oos = new ObjectOutputStream(new FileOutputStream("C:/tmp/largeList.ser"))
        oos.writeObject(largeList)
        oos.flush()
        oos.close()
      
        val ois = new ObjectInputStream(new FileInputStream("C:/tmp/largeList.ser"))
        val read = ois.readObject().asInstanceOf[List[Int]]
        println(read.size)
      
      
      }
      

      Here is the stack trace:

              at scala.collection.immutable.$colon$colon.readObject(List.scala:362)
              at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
              at scala.collection.immutable.$colon$colon.readObject(List.scala:362)
              at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
              at scala.collection.immutable.$colon$colon.readObject(List.scala:362)
              at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
              at scala.collection.immutable.$colon$colon.readObject(List.scala:362)
              at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
      

        Issue Links

          Activity

          Hide
          Jan Vanek added a comment -

          Makes sense. The fast simple non-shared serialization should be available. If there is a big need in the future one could provide something like List.sharedSerialization[T](body: => T): T, which would trigger the shared mode for the duration of body, hypothetically.

          Show
          Jan Vanek added a comment - Makes sense. The fast simple non-shared serialization should be available. If there is a big need in the future one could provide something like List.sharedSerialization [T] (body: => T): T, which would trigger the shared mode for the duration of body, hypothetically.
          Hide
          Jan Vanek added a comment -

          I've updated the gist to handle your last issue, as described above. For your reference:
          https://gist.github.com/4517945

          Show
          Jan Vanek added a comment - I've updated the gist to handle your last issue, as described above. For your reference: https://gist.github.com/4517945
          Hide
          Jason Zaugg added a comment -

          Moving back to 2.10.1, didn't we agree to simply revert the structural sharing change that triggered this bug?

          Show
          Jason Zaugg added a comment - Moving back to 2.10.1, didn't we agree to simply revert the structural sharing change that triggered this bug?
          Show
          Aleksandar Prokopec added a comment - https://github.com/scala/scala/pull/2073
          Hide
          James Iry added a comment -
          Show
          James Iry added a comment - Superseded by https://github.com/scala/scala/pull/2093

            People

            • Assignee:
              Aleksandar Prokopec
              Reporter:
              Chris Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development