记一次dubbo 反序列化问题-Fail to decode request due to: RpcInvocation

记一次dubbo 反序列化问题 Fail to decode request due to: RpcInvocation

接口&类先行

Api定义层

/**
 * 抽象类 注意这是抽象类 
 */
public abstract class AbstractModel implements Serializable {
    private String name;
    // getter setter toString
}

/**
 * rpc 接口定义
 */
public interface HelloService {
    String sayHello(AbstractModel model);
}

provider 层

/**
 * rpc 接口实现
 */
@Service // dubbo的service
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello(AbstractModel model) {
        return "hello " + model.getName();
    }
}

consumer 层

/**
 * person 实现类 旨在consumer 里面 
 */
public class Model extends AbstractModel {
    private String factory;
    // getter setter
}

/**
 *
 */
@Service // spring service
public Consumer {
    @Reference
    private HelloService helloService;
    
    public void say() {
        Model model = new Model();
        model.setName("哈哈哈哈");
        model.setFactory("笑话工厂");
        hellpService.sayHello(model);
    }

出现问题

低版本dubbo 这里以alibaba版本为例

image-20210521214643563

com.alibaba.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=hello0, parameterTypes=[class com.lijun.example.dubbo.api.AbstractModel], arguments=null, attachments={path=com.lijun.example.dubbo.api.HelloService, input=293, dubbo=2.0.2, version=0.0.0}]
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:245) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:162) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:135) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:95) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]
at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:155) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]
at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:77) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]
at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75) ~[dubbo-2.6.10-ZP.jar:2.6.10-ZP]

高版本dubbo

consumer上异常

2021-05-21 21:54:05.155 ERROR 57390 — [nio-8082-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.dubbo.rpc.RpcException: Failed to invoke the method hello0 in the service com.example.dubbo.api.HelloService. Tried 3 times of the providers [172.16.26.222:20880] (1/1) from the registry 127.0.0.1:8848 on the consumer 172.16.26.222 using the dubbo version 2.7.3. Last error is: Failed to invoke remote method: hello0, provider: dubbo://172.16.26.222:20880/com.example.dubbo.api.HelloService?anyhost=true&application=dubbo-consumer-demo&bean.name=ServiceBean:com.example.dubbo.api.HelloService&category=providers&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com.example.dubbo.api.HelloService&lazy=false&methods=hello0,hello1,hello2,hello3&path=com.example.dubbo.api.HelloService&pid=57390&protocol=dubbo&qos.enable=false&register=true&register.ip=172.16.26.222&release=2.7.3&remote.application=dubbo-provider-demo&side=consumer&sticky=false&timestamp=1621604961685, cause: org.apache.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=hello0, parameterTypes=[class com.example.dubbo.api.AbstractModel], arguments=null, attachments={path=com.example.dubbo.api.HelloService, input=263, dubbo=2.0.2, version=0.0.0}]] with root cause

org.apache.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=hello0, parameterTypes=[class com.example.dubbo.api.AbstractModel], arguments=null, attachments={path=com.example.dubbo.api.HelloService, input=263, dubbo=2.0.2, version=0.0.0}]
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:191) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:153) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:141) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleResponse(HeaderExchangeHandler.java:62) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:199) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57) ~[dubbo-2.7.3.jar:2.7.3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_281]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_281]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_281]

provider上异常

2021-05-21 21:54:05.106 WARN 57369 — [erverWorker-3-1] o.a.d.r.p.dubbo.DecodeableRpcInvocation : [DUBBO] Decode argument failed: ‘com.example.dubbo.api.AbstractModel’ could not be instantiated, dubbo version: 2.7.3, current host: 172.16.26.222

com.alibaba.com.caucho.hessian.io.HessianProtocolException: ‘com.example.dubbo.api.AbstractModel’ could not be instantiated
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.instantiate(JavaDeserializer.java:316) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:201) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2818) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2145) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2118) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:92) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:116) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:73) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:132) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:122) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:82) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:48) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter I n t e r n a l D e c o d e r . d e c o d e ( N e t t y C o d e c A d a p t e r . j a v a : 90 ) [ d u b b o − 2.7.3. j a r : 2.7.3 ] a t i o . n e t t y . h a n d l e r . c o d e c . B y t e T o M e s s a g e D e c o d e r . d e c o d e R e m o v a l R e e n t r y P r o t e c t i o n ( B y t e T o M e s s a g e D e c o d e r . j a v a : 508 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . h a n d l e r . c o d e c . B y t e T o M e s s a g e D e c o d e r . c a l l D e c o d e ( B y t e T o M e s s a g e D e c o d e r . j a v a : 447 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . h a n d l e r . c o d e c . B y t e T o M e s s a g e D e c o d e r . c h a n n e l R e a d ( B y t e T o M e s s a g e D e c o d e r . j a v a : 276 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . i n v o k e C h a n n e l R e a d ( A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . j a v a : 379 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . i n v o k e C h a n n e l R e a d ( A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . j a v a : 365 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . f i r e C h a n n e l R e a d ( A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . j a v a : 357 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . D e f a u l t C h a n n e l P i p e l i n e InternalDecoder.decode(NettyCodecAdapter.java:90) [dubbo-2.7.3.jar:2.7.3] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.DefaultChannelPipeline InternalDecoder.decode(NettyCodecAdapter.java:90)[dubbo2.7.3.jar:2.7.3]atio.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.DefaultChannelPipelineHeadContext.channelRead(DefaultChannelPipeline.java:1410) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_281]
Caused by: java.lang.InstantiationException: null
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[na:1.8.0_281]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_281]
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.instantiate(JavaDeserializer.java:312) ~[dubbo-2.7.3.jar:2.7.3]
… 33 common frames omitted

2021-05-21 21:54:05.106 WARN 57369 — [erverWorker-3-1] o.a.d.r.p.dubbo.DecodeableRpcInvocation : [DUBBO] Decode rpc invocation failed: expected map/object at java.lang.String (11), dubbo version: 2.7.3, current host: 172.16.26.222

com.alibaba.com.caucho.hessian.io.HessianProtocolException: expected map/object at java.lang.String (11)
at com.alibaba.com.caucho.hessian.io.AbstractDeserializer.error(AbstractDeserializer.java:131) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.AbstractMapDeserializer.readObject(AbstractMapDeserializer.java:70) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2267) ~[dubbo-2.7.3.jar:2.7.3]
at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:92) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:126) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:73) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:132) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:122) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:82) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:48) [dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter I n t e r n a l D e c o d e r . d e c o d e ( N e t t y C o d e c A d a p t e r . j a v a : 90 ) [ d u b b o − 2.7.3. j a r : 2.7.3 ] a t i o . n e t t y . h a n d l e r . c o d e c . B y t e T o M e s s a g e D e c o d e r . d e c o d e R e m o v a l R e e n t r y P r o t e c t i o n ( B y t e T o M e s s a g e D e c o d e r . j a v a : 508 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . h a n d l e r . c o d e c . B y t e T o M e s s a g e D e c o d e r . c a l l D e c o d e ( B y t e T o M e s s a g e D e c o d e r . j a v a : 447 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . h a n d l e r . c o d e c . B y t e T o M e s s a g e D e c o d e r . c h a n n e l R e a d ( B y t e T o M e s s a g e D e c o d e r . j a v a : 276 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . i n v o k e C h a n n e l R e a d ( A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . j a v a : 379 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . i n v o k e C h a n n e l R e a d ( A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . j a v a : 365 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . f i r e C h a n n e l R e a d ( A b s t r a c t C h a n n e l H a n d l e r C o n t e x t . j a v a : 357 ) [ n e t t y − a l l − 4.1.59. F i n a l . j a r : 4.1.59. F i n a l ] a t i o . n e t t y . c h a n n e l . D e f a u l t C h a n n e l P i p e l i n e InternalDecoder.decode(NettyCodecAdapter.java:90) [dubbo-2.7.3.jar:2.7.3] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.59.Final.jar:4.1.59.Final] at io.netty.channel.DefaultChannelPipeline InternalDecoder.decode(NettyCodecAdapter.java:90)[dubbo2.7.3.jar:2.7.3]atio.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)[nettyall4.1.59.Final.jar:4.1.59.Final]atio.netty.channel.DefaultChannelPipelineHeadContext.channelRead(DefaultChannelPipeline.java:1410) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-all-4.1.59.Final.jar:4.1.59.Final]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_281]

问题分析

简单来说 就是反序列异常

dubbo源码分析

public class Hessian2Input
        extends AbstractHessianInput
        implements Hessian2Constants {
    private Object readObjectInstance(Class cl, ObjectDefinition def)
            throws IOException {
        String type = def.getType();
        String[] fieldNames = def.getFieldNames();

        if (cl != null) {
            Deserializer reader;
            reader = findSerializerFactory().getObjectDeserializer(type, cl);

            return reader.readObject(this, fieldNames);
        } else {
            return findSerializerFactory().readObject(this, type, fieldNames);
        }
    }
}
  • cl 是我们预期的类。AbstractModel
  • def 中解析出来的type是我们传入的类 model
  • getObjectDeserializer 会尝试获取序列化器
public class SerializerFactory extends AbstractSerializerFactory {
    public Deserializer getObjectDeserializer(String type, Class cl)
            throws HessianProtocolException {
        Deserializer reader = getObjectDeserializer(type);

        if (cl == null
                || cl.equals(reader.getType())
                || cl.isAssignableFrom(reader.getType())
                || HessianHandle.class.isAssignableFrom(reader.getType())) {
            return reader;
        }

        if (log.isLoggable(Level.FINE)) {
            log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
                    + reader.getType().getName() + ")");
        }

        return getDeserializer(cl);
    }
    
    
    public Deserializer getObjectDeserializer(String type)
            throws HessianProtocolException {
        Deserializer deserializer = getDeserializer(type);

        if (deserializer != null)
            return deserializer;
        else if (_hashMapDeserializer != null)
            return _hashMapDeserializer;
        else { // 懒加载
            _hashMapDeserializer = new MapDeserializer(HashMap.class);

            return _hashMapDeserializer;
        }
    }
}

可以看到 model 在我们的provider 中是并不存在的,所以deserializer 为null ,将HashMap的的反序列化器返回

if (cl == null
		|| cl.equals(reader.getType())
	    || cl.isAssignableFrom(reader.getType())
		|| HessianHandle.class.isAssignableFrom(reader.getType())) {
	return reader;
}

明显不符合上面的条件,就会尝试获取我们预期的类AbstractModel 的反序列化器(这个是存在的)

实例化一个对象

具体流程这里就不一一梳理了 最终会 调用到 JavaDeserializer newInstance

public class JavaDeserializer extends AbstractMapDeserializer {
	protected Object instantiate()
            throws Exception {
        try {
            if (_constructor != null)
                return _constructor.newInstance(_constructorArgs);
            else
                return _type.newInstance();
        } catch (Exception e) {
            throw new HessianProtocolException("'" + _type.getName() + "' could not be instantiated", e);
        }
    }
}

由于抽象类无法被实例化,所以在这将抛出异常 反序列化失败

大致流程就是这些了,感兴趣的可以自己研究 跟踪下源码分析下

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值