Menu

#221 StackOverflowError when de/serializing

closed-wont-fix
nobody
None
5
2007-11-08
2007-03-20
No

Serializing a long list produces a StackOverFlowError. Serializing and deserializing a shorter list fails if done twice in a row.

--8<----8<----8<----8<----8<----8<--
;; a utility module
(module ser-deser
(ser deser ser-deser)

(import s2j)

(define-java-classes
(<object-output-stream> |java.io.ObjectOutputStream|)
(<file-output-stream> |java.io.FileOutputStream|)
(<object-input-stream> |java.io.ObjectInputStream|)
(<file-input-stream> |java.io.FileInputStream|))

(define-generic-java-methods
read-object write-object)

(define (ser-deser value)
(ser value)
(deser))

(define (ser value)
(write-object (java-new <object-output-stream>
(java-new <file-output-stream>
(->jstring "value.ser")))
(java-wrap value)))

(define (deser)
(java-unwrap (read-object (java-new <object-input-stream>
(java-new <file-input-stream>
(->jstring "value.ser"))))))
)

(import ser-deser)

(require-library 'sisc/libs/srfi/srfi-1)
(import srfi-1)

;; TEST CASE 1
(ser (iota 10000))
; => java.lang.StackOverflowError

;; TEST CASE 2
(ser (iota 10000)) ; => ok
(ser-deser (iota 10000)) ; => ok
(ser-deser (iota 10000)) ; => java.lang.StackOverflowError

;; TEST CASE 3

(ser-deser (fold (lambda (n acc)
(make-child-environment acc)) (null-environment 0) (iota 1000)))
--8<----8<----8<----8<----8<----8<--

Discussion

  • Alessandro Colomba

    Logged In: YES
    user_id=544263
    Originator: YES

    Reposting the second test case. The parameter to iota should be 1E3, not 1E4.

    ;; TEST CASE 2
    (ser (iota 1000)) ; => ok
    (ser-deser (iota 1000)) ; => ok
    (ser-deser (iota 1000)) ; => java.lang.StackOverflowError

     
  • Scott G. Miller

    Scott G. Miller - 2007-11-08

    Logged In: YES
    user_id=25869
    Originator: NO

    Unfortunately this is a side effect of ObjectOutputStream not being able to serialize long chains of objects. Since OOS handles the serialization in the case of an ObjectOutputStream, rather than SISC's serialization, you're limited to stack size for them. The workaround is to increase the stack size, or use SISC's serialization which uses the heap to trace through deeply nested values.

     
  • Scott G. Miller

    Scott G. Miller - 2007-11-08
    • status: open --> open-wont-fix
     
  • Scott G. Miller

    Scott G. Miller - 2007-11-08
    • status: open-wont-fix --> closed-wont-fix
     

Log in to post a comment.