alibaba / alibaba/fastjson2

[QUESTION] java.lang.OutOfMemoryError: try enabling LargeObject feature instead

Open
#2,628 7 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

请问下,什么情况下会报这个错误:
Caused by: java.lang.OutOfMemoryError: try enabling LargeObject feature instead
at com.alibaba.fastjson2.JSONWriterUTF8.ensureCapacity(JSONWriterUTF8.java:2122) ~[fastjson2-2.0.50.jar:?]
at com.alibaba.fastjson2.JSONWriterUTF8.writeStringUTF16(JSONWriterUTF8.java:570) ~[fastjson2-2.0.50.jar:?]
at com.alibaba.fastjson2.writer.OWG_14_27_BaseCar.write(Unknown Source) ~[?:?]
at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:364) ~[fastjson2-2.0.50.jar:?]
at com.alibaba.fastjson2.writer.ObjectWriterArray.write(ObjectWriterArray.java:103) ~[fastjson2-2.0.50.jar:?]
at com.alibaba.fastjson2.writer.OWG_3_3_Result.write(Unknown Source) ~[?:?]
at com.alibaba.fastjson2.JSON.writeTo(JSON.java:3481) ~[fastjson2-2.0.50.jar:?]
at com.alibaba.fastjson2.support.spring.http.converter.FastJsonHttpMessageConverter.writeInternal(FastJsonHttpMessageConverter.java:138) ~[fastjson2-extension-spring5-2.0.50.jar:?]
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227) ~[spring-web-5.3.19.jar:5.3.19]
at com.alibaba.fastjson2.support.spring.http.converter.FastJsonHttpMessageConverter.write(FastJsonHttpMessageConverter.java:86) ~[fastjson2-extension-spring5-2.0.50.jar:?]

在fastjson1时,不报错的,谢谢!

Contributor guide

Open the contributing guide

Research direction

Start by inspecting JSONWriterUTF8.ensureCapacity at line 2122 and the writeStringUTF16 path shown in the stack trace. Trace how the result list reaches JSON.writeTo and FastJsonHttpMessageConverter.writeInternal, then compare the behavior with fastjson1. Done would require identifying the conditions that trigger this error and documenting or fixing the difference.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.