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


    问题与解决方法

    有时候我们的系统会报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.

    参考链接

  • 相关阅读:
    idea 代码提交到gitee
    flink+nacos实现参数化配置
    循环依赖的学习
    protobuf学习
    idea重置试用期插件
    Idea git 指定回滚版本
    Tomcat8下的Redis会话共享
    建造者设计模式
    Servlet中跨域问题详解
    gRPC
  • 原文地址:https://www.cnblogs.com/yulinlewis/p/10061800.html
Copyright © 2020-2023  润新知