开发者社区> 问答> 正文

fastjson 2 writeInstant StackOverflowError 堆栈溢出

问题描述

序列化 Instant 时 抛 StackOverflowError

环境信息

OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB] JDK信息: [e.g.:Openjdk 1.8.0_312] 版本信息:[e.g.:Fastjson2 2.0.7]

重现步骤

如何操作可以重现该问题:

at com.alibaba.fastjson2.JSONWriter.writeInstant(JSONWriter.java:1186)

06-15 14:54:19.439 ERROR [http-nio-32184-exec-128] s.b.e.handler.ExceptionAdvice [ 72][]: 系统异常: url=/api/v1/abc; Handler dispatch failed; nested exception is java.lang.StackOverflowError org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:665) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.StackOverflowError: null at java.time.temporal.ValueRange.isValidIntValue(ValueRange.java:295) at java.time.temporal.ValueRange.checkValidIntValue(ValueRange.java:329) at java.time.temporal.ChronoField.checkValidIntValue(ChronoField.java:722) at java.time.LocalDate.ofEpochDay(LocalDate.java:341) at java.time.LocalDateTime.ofEpochSecond(LocalDateTime.java:422) at java.time.format.DateTimeFormatterBuilder$InstantPrinterParser.format(DateTimeFormatterBuilder.java:3205) at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2190) at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1746) at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1720) at com.alibaba.fastjson2.JSONWriter.writeInstant(JSONWriter.java:1186) at com.alibaba.fastjson2.writer.ObjectWriterImplInstant.write(ObjectWriterImplInstant.java:37) at com.alibaba.fastjson2.writer.ObjectWriter_9.write(Unknown Source) at com.alibaba.fastjson2.writer.ObjectWriter_9.write(Unknown Source) at com.alibaba.fastjson2.writer.ObjectWriter_9.write(Unknown Source) .... 无限长 at com.alibaba.fastjson2.writer.ObjectWriter_9.write(Unknown Source) at com.alibaba.fastjson2.writer.ObjectWriter_9.write(Unknown Source)

原提问者GitHub用户lyhu

展开
收起
飘飘斯嘉丽 2023-04-21 12:02:13 439 0
1 条回答
写回答
取消 提交回答
  • 序列化的时候指定Feature.ReferenceDetection

    https://github.com/alibaba/fastjson2/blob/main/docs/features_cn.md

    原回答者GitHub用户wenshao

    2023-04-21 14:41:09
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载