如何获取更多关于序列化异常的堆栈信息

问题与解决方法

有时候我们的系统会报java.io.NotSerializableException,根据堆栈信息又无法得出有用的信息,无法找到具体是因为哪些类或者变量造成的,可以使用一个java参数-Dsun.io.serialization.extendedDebugInfo=true来得到更加具体的序列化信息。

从jdk6开始就可以使用该参数,可以在启动java程序时启用该参数,也可以在项目的一开始通过代码来启用:

System.setProperty("sun.io.serialization.extendedDebugInfo", "true");

下边是stackoverflow上找到的两个回答:

回答其一

From JDK6 you should be able to get extra information by setting the sun.io.serialization.extendedDebugInfo system property:
-Dsun.io.serialization.extendedDebugInfo=true

回答其二

Set the system property sun.io.serialization.extendedDebugInfo to true, either by adding-Dsun.io.serialization.extendedDebugInfo=trueto the command line, or add the line System.setProperty("sun.io.serialization.extendedDebugInfo", "true"); at the start of your program.
If something isn't serializable, this will cause a trace of the path through the data structure that leads from the "root" object (the one passed to ObjectOutputStream.writeObject()) to the object that's not serializable. At least, it'll tell you the class names of the instances and the fields that lead to the non-serializable object.

参考链接

转载于:https://www.cnblogs.com/yulinlewis/p/10061800.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值