Mantis - Resin
Viewing Issue Advanced Details
69 minor always 03-01-05 00:00 05-11-05 00:00
user102  
 
normal  
closed  
fixed  
none    
none 3.0.13  
0000069: hessian references break when there are more than 256 refs in one call
RSN-60
When you create a Large hessian Object that has more than 256 references in it,
using HessianOutput.writeObject() can produce unpredictable results.
The reason for this is the implementation of HessianOutput.writeRef() as following:

public void writeRef(int value)
    throws IOException
  {
    os.write('R');
    os.write(value << 24);
    os.write(value << 16);
    os.write(value << 8);
    os.write(value);
  }

the above code does bitshifting to the left and write out the value. This will work as long as
the reference value is smaller than 256 because the shifting will not affect the higher bytes, as
they are zero anyway. but anything bigger than 256 will give strange results, resulting in difficult to debug error messages, because the references will not point to the correct objects.
This can cause ClassCastExceptions and other Exceptions.

The solution i found to this problem is the following code:

 /*corrected this function so that reference bigger than 256 can work!! i
    * in hessian, the bits were being shifted to the left instead of right
    * @see com.caucho.hessian.io.AbstractHessianOutput#writeRef(int)
    */
    public void writeRef(int value)
      throws IOException
    {
      os.write('R');
      os.write((value >> 24) & 0xFF);
      os.write((value >> 16) & 0xFF);
      os.write((value >> 8) & 0xFF);
      os.write((value) & 0xFF);
    }

this code correctly shifts the bits to the right and everything works fine.

linux

There are no notes attached to this issue.