Uploaded image for project: 'Pig'
  1. Pig
  2. PIG-4795

Flushing ObjectOutputStream before calling toByteArray on the underlying ByteArrayOutputStream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.16.0
    • None
    • Patch Available
    • Reviewed
    • Patch

    Description

      In PigSplit.java

          private void writeObject(Serializable obj, DataOutput os)
                  throws IOException {
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(baos);
              oos.writeObject(obj);
              byte[] bytes = baos.toByteArray();
              os.writeInt(bytes.length);
              os.write(bytes);
          }
      

      When an ObjectOutputStream instance wraps an underlying ByteArrayOutputStream instance,
      it is recommended to flush or close the ObjectOutputStream before invoking the underlying instances's toByteArray(). Also, it is a good practice to call flush/close explicitly as mentioned for example at http://stackoverflow.com/questions/2984538/how-to-use-bytearrayoutputstream-and-dataoutputstream-simultaneously-java.
      The patch adds a flush method before calling toByteArray().

      Attachments

        1. PIG-4795-0.patch
          0.7 kB
          emopers

        Activity

          People

            emopers emopers
            emopers emopers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: