美文网首页
Sonar相关规则解读2

Sonar相关规则解读2

作者: 岩岩和欣欣 | 来源:发表于2017-07-20 14:20 被阅读0次

今天继续来看Sonar规则


3、Throwable.printStackTrace(...) should not be called

处理异常时不要用e.printStackTrace(),最好记录log

Throwable.printStackTrace(...) prints a Throwable and its stack trace to some stream. By default that stream System.Err, which could inadvertently expose sensitive information.

Loggers should be used instead to printThrowables, as they have many advantages:

1、Users are able to easily retrieve the logs.

2、The format of log messages is uniform and allow users to browse the logs easily.

This rule raises an issue when printStackTrace is used without arguments, i.e. when the stack trace is printed to the default stream.


4、"public static" fields should be constant

There is no good reason to declare a field "public" and "static" without also declaring it "final". Most of the time this is a kludge to share a state among several objects. But with this approach, any object can do whatever it wants with the shared state, such as setting it to null.

从代码安全性上考虑,public static 一定要加 final。


Sonar相关规则解读1

相关文章

  • Sonar相关规则解读2

    今天继续来看Sonar规则 3、Throwable.printStackTrace(...) should not...

  • Sonar相关规则解读1

    这几天在处理sonar扫出来的代码问题,有一些觉得还是有必要写下来的,所以做一些记录。每次记录2个。 1、loop...

  • sonar规则

    high ncss method 方法有效代码行太高 某个代码块中代码行数过多(只统计有效的语句),查看代码块中代...

  • sonar规则-次要

    次要规则 Redundant conditional operator (冗余的条件判断会造成一些错误,应该让它变...

  • sonar自定义规则笔记

    对于sonar的安装,笔记并未做相关记录,原因很简单,百度一下你就知道;笔记着重自定义规则开发,个人也是慢慢摸索,...

  • webhook Response: Server Unreach

    定位到问题,应该是域名相关。 sonar服务:测试云环境上的sonar服务sonarqube:测试环境虚机上搭建的...

  • SonarQube结合FindBugs Security Aud

    背景 近期公司做的一个项目,客户对代码安全这块要求特别严格,不满足于sonar默认的sonar way规则集,因为...

  • 持续集成2-SonarQube

    sonar是一个代码质量管理平台,根据规则对代码进行静态检查,对保证工程的代码质量很有帮助 sonar5.5是最后...

  • Sonar---漏洞规则

    Sonar---bug规则:https://www.jianshu.com/p/22329a177e5f[http...

  • Sonar---bug规则

    Sonar---漏洞规则:https://www.jianshu.com/p/d471b483652c[https...

网友评论

      本文标题:Sonar相关规则解读2

      本文链接:https://www.haomeiwen.com/subject/gvgdkxtx.html