Uploaded image for project: 'JBoss Marshalling'
  1. JBoss Marshalling
  2. JBMAR-126

Unexpected behavior of the method readFully(byte[]) in case the byte array is empty

XMLWordPrintable

      According to the Javadoc of the interface java.io.DataInput, I quote If b.length is zero, then no bytes are read which is not what classes like org.jboss.marshalling.river.BlockUnmarshaller do as we can face java.io.EOFException if we try to read an empty byte array at the end of the stream. See below a typical use case:

      ...
      protected byte[] data;
      ...
         public void readExternal(ObjectInput in) throws IOException
         {
            ..
            
            data = new byte[in.readInt()];
            in.readFully(data);
         }
      
         public void writeExternal(ObjectOutput out) throws IOException
         {
            ...
            out.writeInt(data.length);
            out.write(data);
         }
      ...
      

      In this use case if data.length == 0, the object will be serialized properly but if you try to de-serialize it, it will fail at in.readFully(data) with an java.io.EOFException instead of reading nothing as expected.

              dlloyd@redhat.com David Lloyd
              nfilotto Nicolas Filotto (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: