[armedbear-devel] bug in RandomAccessCharacterFile.java

David Kirkman dkirkman at ucsd.edu
Sun Dec 5 05:25:24 UTC 2010


The problem is that in the while loop (line 549), if only part of the byte
array is written to the buffer, the position is updated but the length
is not.  I'm attaching a patch.

Here is some code that fails in r13087, and works with the patch.  I ran into
this while serializing mixed lisp/java objects, which is pretty well reflected
in this snippet.

Cheers,

-david k.

(let* ((len 5000)
       (big-object (jnew-array "double" len)))
  (dotimes (i len)
    (setf (jarray-ref big-object i) (+ i 0.1)))


  (with-open-file (stream "foo.dat"
                          :direction :output
                          :element-type 'unsigned-byte)
    (let ((p (jnew
              (jconstructor "java.io.ObjectOutputStream" "java.io.OutputStream")
              (jcall (jmethod "org.armedbear.lisp.Stream"
                              "getWrappedOutputStream")
                     stream))))

      (jcall (jmethod "java.io.ObjectOutputStream" "writeObject"
                      "java.lang.Object")
             p
             big-object)

      (jcall (jmethod "java.io.ObjectOutputStream" "flush") p)))


  (let ((big-object2
         (with-open-file (stream "foo.dat"
                                 :direction :input
                                 :element-type 'unsigned-byte)
           (let ((p (jnew
                     (jconstructor "java.io.ObjectInputStream"
                                   "java.io.InputStream")
                     (jcall (jmethod "org.armedbear.lisp.Stream"
                                     "getWrappedInputStream")
                            stream))))
             (jcall (jmethod "java.io.ObjectInputStream" "readObject") p)))))

    (dotimes (i len)
      (format t "~A ~A~%"
              (jarray-ref big-object i)
              (jarray-ref big-object2 i)))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: want.diff
Type: application/octet-stream
Size: 606 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20101204/50c5caa0/attachment.obj>


More information about the armedbear-devel mailing list