今天繼續(xù)來看Sonar規(guī)則
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相關(guān)規(guī)則解讀1