apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.48k stars 26.43k forks source link

java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader 'bootstrap') #9037

Closed childe-dragon closed 3 years ago

childe-dragon commented 3 years ago

以下情况会有一定几率出现,不知道是不是我使用不对

Environment

Steps to reproduce this issue

  1. CcxdAbsCalculateHandler.java:139调用了CcxdOdsDataSourceServiceApi.saveRecordBatchForSelect 接口
  2. 接口参数结构 ParamsBean{ private String a; private String[] b; private Object params; }
  3. 接口调用参数 a=“xxx”,b="zzz",params为List<Map<String,Object>> Map值大部分为String,部分为Date和Long
  4. 持续调用会有不小的概率出现以下异常

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

What do you expected from the above steps?

Actual Result

What actually happens?

If there is an exception, please attach the exception trace: org.apache.dubbo.rpc.RpcException: Failed to invoke the method saveRecordBatchForSelect in the service com.ccxd.idp.ods.service.api.CcxdOdsDataSourceServiceApi. Tried 3 times of the providers [172.30.76.92:20880, 172.30.76.94:20880, 172.30.190.144:20880] (3/4) from the registry nacos-headless:8848 on the consumer 172.30.190.145 using the dubbo version 3.0.3. Last error is: Failed to invoke remote method: saveRecordBatchForSelect, provider: dubbo://172.30.76.92:20880/com.ccxd.idp.ods.service.api.CcxdOdsDataSourceServiceApi?application=idp-ods-service&category=providers&deprecated=false&dubbo=2.0.2&loadbalance=roundrobin&path=com.ccxd.idp.ods.service.api.CcxdOdsDataSourceServiceApi&protocol=dubbo&release=3.0.3&serialization=kryo&version=1.0.0, cause: org.apache.dubbo.remoting.RemotingException: Fail to decode request due to: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader 'bootstrap') java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader 'bootstrap') at org.apache.dubbo.common.serialize.ObjectInput.readAttachments(ObjectInput.java:87) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:224) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:93) at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:57) at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:44) at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41) at java.base/java.lang.Thread.run(Thread.java:834)

at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:110)
at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:268)
at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:89)
at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$FilterChainNode.invoke(FilterChainBuilder.java:84)
at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:51)
at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$FilterChainNode.invoke(FilterChainBuilder.java:84)
at org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter.invoke(ConsumerContextFilter.java:108)
at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$FilterChainNode.invoke(FilterChainBuilder.java:84)
at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$ClusterFilterInvoker.invoke(AbstractCluster.java:92)
at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:94)
at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:276)
at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:92)
at org.apache.dubbo.common.bytecode.proxy0.saveRecordBatchForSelect(proxy0.java)
at jdk.internal.reflect.GeneratedMethodAccessor201.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy52.saveRecordBatchForSelect(Unknown Source)
at com.ccxd.idp.calculate.service.handlers.CcxdAbsCalculateHandler.lambda$transferData$1(CcxdAbsCalculateHandler.java:139)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Just put your stack trace here!
childe-dragon commented 3 years ago

经过测试发现序列化换成hessian2正常 目前用的dubbo-serialization-kryo 2.7.9版本就会偶发性异常,想换高一点的版本但是貌似与3.0.3无法集成,会报如下错误 java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk

childe-dragon commented 3 years ago

Caused by: org.apache.dubbo.remoting.RemotingException: io.netty.handler.codec.EncoderException: java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk(Ljava/lang/Class;)Z io.netty.handler.codec.EncoderException: java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk(Ljava/lang/Class;)Z at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:125) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702) at io.netty.handler.timeout.IdleStateHandler.write(IdleStateHandler.java:304) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702) at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:115) at org.apache.dubbo.remoting.transport.netty4.NettyClientHandler.write(NettyClientHandler.java:88) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) at io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1071) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk(Ljava/lang/Class;)Z at org.apache.dubbo.common.serialize.kryo.CompatibleKryo.getDefaultSerializer(CompatibleKryo.java:46) at com.esotericsoftware.kryo.Kryo.register(Kryo.java:410) at org.apache.dubbo.common.serialize.kryo.utils.AbstractKryoFactory.create(AbstractKryoFactory.java:112) at org.apache.dubbo.common.serialize.kryo.utils.ThreadLocalKryoFactory$1.initialValue(ThreadLocalKryoFactory.java:26) at org.apache.dubbo.common.serialize.kryo.utils.ThreadLocalKryoFactory$1.initialValue(ThreadLocalKryoFactory.java:23) at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195) at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172) at org.apache.dubbo.common.serialize.kryo.utils.ThreadLocalKryoFactory.getKryo(ThreadLocalKryoFactory.java:37) at org.apache.dubbo.common.serialize.kryo.utils.KryoUtils.get(KryoUtils.java:30) at org.apache.dubbo.common.serialize.kryo.KryoObjectOutput.(KryoObjectOutput.java:39) at org.apache.dubbo.common.serialize.kryo.KryoSerialization.serialize(KryoSerialization.java:51) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeRequest(ExchangeCodec.java:255) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:71) at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:40) at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:69) at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ... 22 more

at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:207)
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:170)
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:158)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleResponse(HeaderExchangeHandler.java:60)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:181)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)
at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:196)
at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:99)
at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:179)
... 33 more

与dubbo其他分支对比了下, 3.0版本确实有isJdk方法,可能后续被移除了

zhuangjinjin commented 3 years ago

Caused by: org.apache.dubbo.remoting.RemotingException: io.netty.handler.codec.EncoderException: java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk(Ljava/lang/Class;)Z io.netty.handler.codec.EncoderException: java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk(Ljava/lang/Class;)Z at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:125) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702) at io.netty.handler.timeout.IdleStateHandler.write(IdleStateHandler.java:304) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702) at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:115) at org.apache.dubbo.remoting.transport.netty4.NettyClientHandler.write(NettyClientHandler.java:88) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) at io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1071) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.NoSuchMethodError: org.apache.dubbo.common.utils.ReflectUtils.isJdk(Ljava/lang/Class;)Z at org.apache.dubbo.common.serialize.kryo.CompatibleKryo.getDefaultSerializer(CompatibleKryo.java:46) at com.esotericsoftware.kryo.Kryo.register(Kryo.java:410) at org.apache.dubbo.common.serialize.kryo.utils.AbstractKryoFactory.create(AbstractKryoFactory.java:112) at org.apache.dubbo.common.serialize.kryo.utils.ThreadLocalKryoFactory$1.initialValue(ThreadLocalKryoFactory.java:26) at org.apache.dubbo.common.serialize.kryo.utils.ThreadLocalKryoFactory$1.initialValue(ThreadLocalKryoFactory.java:23) at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195) at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172) at org.apache.dubbo.common.serialize.kryo.utils.ThreadLocalKryoFactory.getKryo(ThreadLocalKryoFactory.java:37) at org.apache.dubbo.common.serialize.kryo.utils.KryoUtils.get(KryoUtils.java:30) at org.apache.dubbo.common.serialize.kryo.KryoObjectOutput.(KryoObjectOutput.java:39) at org.apache.dubbo.common.serialize.kryo.KryoSerialization.serialize(KryoSerialization.java:51) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeRequest(ExchangeCodec.java:255) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:71) at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:40) at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:69) at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ... 22 more

at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:207)
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:170)
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:158)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleResponse(HeaderExchangeHandler.java:60)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:181)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)
at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:196)
at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:99)
at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:179)
... 33 more

与dubbo其他分支对比了下, 3.0版本确实有isJdk方法,可能后续被移除了

可以查看这个PR,已经恢复isJdk方法,还没发布 #8968