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

[BUG]反序列化java.util.SubList报错 #3364

Open
qqq412700802 opened this issue Mar 6, 2025 · 3 comments
Open

[BUG]反序列化java.util.SubList报错 #3364

qqq412700802 opened this issue Mar 6, 2025 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@qqq412700802
Copy link

问题描述

问题场景与#2851高度相似。
在Dubbo应用中使用FastJSON2作为序列化,当传递java.util.SubList对象时报错
java.util.SubList对象是调用AbstractList类的subList方法获得的。该对象类没有public构造方法。

public List<E> subList(int fromIndex, int toIndex) {
    return (this instanceof RandomAccess ?
            new RandomAccessSubList<>(this, fromIndex, toIndex) :
            new SubList<>(this, fromIndex, toIndex));
}

环境信息

  • JDK信息: Openjdk 1.8.0_401
  • 版本信息:Fastjson2 2.0.56

重现步骤

//dubbo接口
void testListCall(List<String> listMsg);

//消费者调用场景
List<String> linkedList = new LinkedList<>();

linkedList.add("hello");
linkedList.add("world");

dubboTestService.testListCall(linkedList.subList(0, 1));

相关日志输出

2025-03-06 12:09:27.937 WARN  [NettyServerWorker-5-5] o.a.d.r.p.d.DecodeableRpcInvocation -  [DUBBO] Decode rpc invocation failed: org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: create instance error class java.util.SubList, offset 21, dubbo version: 3.2.12, current host: 192.168.158.33, error code: 4-20. This may be caused by , go to https://dubbo.apache.org/faq/4/20 to find instructions. 
java.io.IOException: org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: create instance error class java.util.SubList, offset 21
	at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper.handleToIOException(DefaultSerializationExceptionWrapper.java:353)
	at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper.access$000(DefaultSerializationExceptionWrapper.java:27)
	at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper$ProxyObjectInput.readObject(DefaultSerializationExceptionWrapper.java:163)
	at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.drawArgs(DecodeableRpcInvocation.java:272)
	at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:173)
	at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:105)
	at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:199)
	at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:137)
	at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:92)
	at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:59)
	at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalDecoder.decode(NettyCodecAdapter.java:103)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.handler.codec.ByteToMessageDecoder.handlerRemoved(ByteToMessageDecoder.java:266)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:536)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:750)
Caused by: org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: create instance error class java.util.SubList, offset 21
	... 37 common frames omitted
Caused by: com.alibaba.fastjson2.JSONException: create instance error class java.util.SubList, offset 21
	at com.alibaba.fastjson2.reader.ObjectReaderImplList.readJSONBObject(ObjectReaderImplList.java:534)
	at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:569)
	at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectInput.readObject(FastJson2ObjectInput.java:122)
	at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper$ProxyObjectInput.readObject(DefaultSerializationExceptionWrapper.java:161)
	... 34 common frames omitted
Caused by: java.lang.InstantiationException: java.util.SubList
	at java.lang.Class.newInstance(Class.java:427)
	at com.alibaba.fastjson2.reader.ObjectReaderImplList.readJSONBObject(ObjectReaderImplList.java:532)
	... 37 common frames omitted
Caused by: java.lang.NoSuchMethodException: java.util.SubList.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 38 common frames omitted
@qqq412700802 qqq412700802 added the bug Something isn't working label Mar 6, 2025
@RedHolger
Copy link

RedHolger commented Mar 6, 2025

Could you elaborate?

@wenshao wenshao added this to the 2.0.57 milestone Mar 7, 2025
@wenshao
Copy link
Member

wenshao commented Mar 7, 2025

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.57-SNAPSHOT/
问题已经修复,请帮忙用2.0.57-SNAPSHOT版本验证,预计2.0.57在3月底前发布。

wenshao added a commit that referenced this issue Mar 7, 2025
@wenshao wenshao added the fixed label Mar 7, 2025
@qqq412700802
Copy link
Author

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.57-SNAPSHOT/ 问题已经修复,请帮忙用2.0.57-SNAPSHOT版本验证,预计2.0.57在3月底前发布。

使用2.0.57-SNAPSHOT版本测试,不会再报错,问题修复了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants