Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hessian2序列化bug #146

Closed
xiegengcai opened this issue Jul 24, 2015 · 6 comments
Closed

hessian2序列化bug #146

xiegengcai opened this issue Jul 24, 2015 · 6 comments

Comments

@xiegengcai
Copy link

直接RPC上传递Hibernate POJO时的bug,POJO有ORM注解。应该说是hessian本身的bug,
https://groups.google.com/forum/#!msg/dubbo/qO8wddrVAZc/1GB86AmB4LoJ

错误堆栈

com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findAll in the service com.skyroam.bsp.order.facade.OrderFacade. Tried 1 times of the providers [192.168.10.13:20883] (1/1) from the registry 192.168.10.86:2181 on the consumer 192.168.10.13 using the dubbo version 2.5.4-SNAPSHOT. Last error is: Failed to invoke remote method: findAll, provider: dubbo://192.168.10.13:20883/com.skyroam.bsp.order.facade.OrderFacade?anyhost=true&application=bsp-order-comsumer&check=false&dubbo=2.5.4-SNAPSHOT&findAll.retries=0&generic=false&group=order&interface=com.skyroam.bsp.order.facade.OrderFacade&logger=slf4j&methods=createOrder,adminAudit,financeAudit,queryByOrderNumber,getOrderById,cancal,queryOrderFlowByOrderId,findAll,queryOrderFlowByOrderNumAndStatus,returnedPurchase,payOrder&pid=12884&retries=2&revision=0.0.9&serialization=hessian2&side=consumer&timeout=2000&timestamp=1437736684510&version=0.0.9, cause: com.alibaba.com.caucho.hessian.io.HessianFieldException: com.skyroam.bsp.order.domain.Order.orderFlows: java.util.Set cannot be assigned from null
com.alibaba.com.caucho.hessian.io.HessianFieldException: com.skyroam.bsp.order.domain.Order.orderFlows: java.util.Set cannot be assigned from null
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.logDeserializeError(JavaDeserializer.java:677)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:400)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:233)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:157)
at com.alibaba.com.caucho.hessian.io.SerializerFactory.readObject(SerializerFactory.java:397)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2070)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2005)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1990)
at com.alibaba.com.caucho.hessian.io.CollectionDeserializer.readLengthList(CollectionDeserializer.java:93)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1643)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:396)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:233)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:157)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2067)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1592)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1576)
at com.alibaba.dubbo.common.serialize.support.hessian.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:94)
at com.alibaba.dubbo.common.serialize.support.hessian.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:99)
at com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:83)
at com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:109)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:97)
at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:126)
at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:87)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:46)
at com.alibaba.dubbo.remoting.transport.netty.NettyCodecAdapter$InternalDecoder.messageReceived(NettyCodecAdapter.java:134)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:575)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:214)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
at org.hibernate.collection.internal.PersistentSet.add(PersistentSet.java:202)
at com.alibaba.com.caucho.hessian.io.CollectionDeserializer.readLengthList(CollectionDeserializer.java:93)
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1628)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:396)
... 38 more

at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:101)
at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:227)
at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72)
at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
at com.alibaba.dubbo.common.bytecode.proxy0.findAll(proxy0.java)
at com.skyroam.bsp.facade.OrderFacadeTest.findAllTest(OrderFacadeTest.java:276)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
@xiegengcai
Copy link
Author

已解决

原来是hessian丢弃了ArrayList之外的集合。

参见 :com.alibaba.com.caucho.hessian.io.CollectionSerializer#writeObject(Object, AbstractHessianOutput)

if (cl.equals(ArrayList.class)
|| ! _sendJavaType
|| ! Serializable.class.isAssignableFrom(cl))
  hasEnd = out.writeListBegin(list.size(), null);
else
  hasEnd = out.writeListBegin(list.size(), obj.getClass().getName());

修改为:

 if (obj instanceof Set
|| ! _sendJavaType
|| ! Serializable.class.isAssignableFrom(cl))
  hasEnd = out.writeListBegin(list.size(), null);
else
  hasEnd = out.writeListBegin(list.size(), obj.getClass().getName());

另外com.alibaba.com.caucho.hessian.io.MapSerializer#writeObject(Object, AbstractHessianOutput)也一样

@zouchunhui
Copy link

备注一下。

@teemoer
Copy link

teemoer commented Nov 17, 2017

@xiegengcai
你好 首先感谢你提供的这个解决方案 因为我现在也遇到了这个问题

请问一下
com.alibaba.com.caucho.hessian.io.MapSerializer#writeObject(Object, AbstractHessianOutput)

 if (cl.equals(HashMap.class)
	|| ! _isSendJavaType
	|| ! (obj instanceof java.io.Serializable))
      out.writeMapBegin(null);
    else
      out.writeMapBegin(obj.getClass().getName());

是要改成 :

 if (obj instanceof Set
|| ! _sendJavaType
|| ! Serializable.class.isAssignableFrom(cl))
  hasEnd = out.writeListBegin(list.size(), null);
else
  hasEnd = out.writeListBegin(list.size(), obj.getClass().getName());

还是修改为 :

    if (obj instanceof Map
	|| ! _isSendJavaType
	|| ! (obj instanceof java.io.Serializable))
      out.writeMapBegin(null);
    else
      out.writeMapBegin(obj.getClass().getName());

我目前是把他修改成了 :


      if (obj instanceof HashMap
                || !_isSendJavaType
                || !(obj instanceof java.io.Serializable)) {
            out.writeMapBegin(null);
        } else {
            out.writeMapBegin(obj.getClass().getName());
        }

期待你的回复, 再次感谢你提供的解决方案

@xiegengcai
Copy link
Author

@teemoer
CollectionSerializer 把ArrayList改成Set或Collection
MapSerializer把HashMap改成Map

@lovepoem
Copy link
Member

lovepoem commented Jan 3, 2018

@xiegengcai please submit a PR

lovepoem added a commit to lovepoem/hessian-lite that referenced this issue Jul 12, 2018
diecui1202 pushed a commit to apache/dubbo-hessian-lite that referenced this issue Jul 13, 2018
* fix Set Vector Serialize data lost apache/dubbo#2069 apache/dubbo#146

* update .travis.yml

* update

* update test

* update test

* update test

* change travis jdk version
@lovepoem
Copy link
Member

close this via apache/dubbo-hessian-lite#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants