2012-01-17 85 views
2

有人在JRockit VM上運行hessian時遇到此異常嗎?粗體與JRockit兼容性

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 

我花了一個星期只上解決此問題,找出麻袋正常工作與HotSpot虛擬機,但始終未能序列化使用的JRockit VM特定對象。我實際上想出了一個簡單的修復方法,但它需要修改IdentityIntMap.java代碼並更新hessian jar文件。

+0

如果您有修復,請把它張貼在這裏(作爲答案),以便人們可以找到它。 – nfechner 2012-01-17 15:17:08

回答

1

這是我想出的修復。我無法弄清楚如何通知Hessian代碼的維護者,所以我在這裏發佈它。修改文件:

com.caucho.hessian.util.IdentityIntMap.java起始於線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; 
    ... 

而且改變在下一方法的代碼起始於線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; 
    ...