【问题标题】:How do i resolve Information Exposure Through an Error Message to remove all the e.printstacktrace and log the error as custom message?如何通过错误消息解决信息暴露问题以删除所有 e.printstacktrace 并将错误记录为自定义消息?
【发布时间】:2018-02-08 10:15:45
【问题描述】:

通过错误消息暴露信息 try{ } catch (PackageManager.NameNotFoundException e) { e.printStackTrace();} 我们如何设计自定义记录器来解决这个问题

【问题讨论】:

    标签: java security coding-style standards


    【解决方案1】:

    您可以将 printStackTrace 替换为以下内容:

    Logger.getLogger(<your-class>.class.getName()).log(Level.SEVERE, null, ex);
    

    【讨论】:

    • Logger 也会暴露信息或者解决上述问题。
    • @VISHALKUMAR 是的,因为您可以配置写入日志的内容。当然,更激进的方法是删除所有日志记录。
    • @Maurice_Perry 是的,最好删除所有 e.printstacktrace 并添加具有标准名称的自定义日志作为标记值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2018-10-21
    • 2011-03-16
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多