gpt4 book ai didi

java - 具有 JRockit 兼容性的 Hessian

转载 作者:行者123 更新时间:2023-11-30 11:48:18 27 4
gpt4 key购买 nike

有人在 JRockit VM 上运行 hessian 时遇到过这个异常吗?

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

我花了一个多星期的时间解决这个问题,结果发现 hessian 在 HotSpot VM 上运行良好,但在使用 JRockit VM 序列化某些对象时始终失败。我实际上想出了一个简单的修复方法,但它需要修改 IdentityIntMap.java 代码并更新 hessian jar 文件。

最佳答案

这是我想出的解决方法。我不知道如何通知 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;
...

关于java - 具有 JRockit 兼容性的 Hessian,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8897037/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com