Hessian with JRockit Compatibility

443 views Asked by At

Has anyone run into this exception when running hessian on a JRockit VM?

Caused by: java.lang.ArrayIndexOutOfBoundsException: -418
        at com.caucho.hessian.util.IdentityIntMap.put(IdentityIntMap.java:141)
        at com.caucho.hessian.io.Hessian2Output.addRef(Hessian2Output.java:1285)
        at com.caucho.hessian.io.UnsafeSerializer.writeObject(UnsafeSerializer.java:157)
        at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:421)
        at com.caucho.hessian.io.CollectionSerializer.writeObject(CollectionSerializer.java:102)
        at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:421)
        at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:293)
        ... 34 more

I spent over a week troubleshooting this problem only to find out that hessian works fine with the HotSpot VM but consistently fails serializing certain objects using the JRockit VM. I actually came up with a simple fix but it required modifying the IdentityIntMap.java code and update the hessian jar file.

1

There are 1 answers

0
Tom H. On

Here is the fix that I came up with. I couldn't figure out how to notify the maintainers of the Hessian code so I'm posting it here. Modify the file:

com.caucho.hessian.util.IdentityIntMap.java starting at line 112:

public final int get(Object key)
{
  int prime = _prime;
  // int hash = System.identityHashCode(key) % prime;
  int hash = System.identityHashCode(key);
  // JRockit VMs can return a negative number which will cause this method to throw an exception
  if (hash < 0)
    hash = -hash;
  hash = hash % prime;
  ...

Also change the code in the next method starting at line 135:

public final int put(Object key, int value, boolean isReplace)
{
  int prime = _prime;
  // int hash = System.identityHashCode(key) % prime;
  int hash = System.identityHashCode(key);
  // JRockit VMs can return a negative number which will cause this method to throw an exception
  if (hash < 0)
    hash = -hash;
  hash = hash % prime;
  ...