问题描述
序列化 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
序列化的时候指定Feature.ReferenceDetection
https://github.com/alibaba/fastjson2/blob/main/docs/features_cn.md
原回答者GitHub用户wenshao
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。