zoukankan      html  css  js  c++  java
  • Sonar规则学习笔记

    1. A catch statement should never catch throwable since it includes errors. 在catch里永远不要抛出throwable。

      Explain: Catching Throwable errors is not recommended since its scope is very broad. It includes runtime issues such as OutOfMemoryError that should be exposed and managed separately.在catch里抛出Throwable里不被推荐的,因为它的范围极其广泛,这个包含了一些远行时异常,例如:OutOfMemoryError,内容溢出,而这些错误应该被单独管理。

      Code: 

    public void bar() {
        try {
         // do something
        } catch (Throwable th) {  // should not catch Throwable
            th.printStackTrace();
        }
      }

    2. 不要使用sysout或者e.printStackTrace(),打印出信息,应该使用统一的logger进行日志、异常输出。

    3. 对于不需要被其他类继承应该定义成final来控制其不被继承性

    4. 工具类不应该有公共的构造器

  • 相关阅读:
    Spark完成wordCount
    Spark介绍
    分库分表介绍
    rpc学习
    xgboost应用
    ElasticSearch 批量增加索引
    乡愁
    java futureTask的使用
    ElasticSearch 例子
    Matlab实现线性回归和逻辑回归: Linear Regression & Logistic Regression
  • 原文地址:https://www.cnblogs.com/garinzhang/p/3425069.html
Copyright © 2011-2022 走看看