sonar:默认的扫描规则

本文详细介绍了SonarQube针对Java项目的默认扫描规则,包括代码质量、复杂度、潜在错误等多个方面,旨在提升Java代码的可读性和维护性。
摘要由CSDN通过智能技术生成

https://blog.csdn.net/liumiaocn/article/details/83550309

https://note.youdao.com/ynoteshare1/index.html?id=3c1e6a08a21ada4dfe0123281637e299&type=note

 https://blog.csdn.net/liumiaocn/article/details/83550309

 

 

 

文本版:

soanr规则java版            
启禁用状态    规则    规则内容    禁用原因
启用    ".equals()" should not be used to test the values of "Atomic" classes    equals()方法不应该用在原子类型的数据上(如:AtomicInteger, AtomicLong, AtomicBoolean).    
启用    "=+" should not be used instead of "+="    "=+"不可以替代 “+=”.    
启用    "==" and "!=" should not be used when "equals" is overridden    如果继承自对象的 equals method没有被重写,则使用等号"==操作符和equals方法来比较两个对象是等价的,否则不能用等号操作符.    
启用    "@CheckForNull" or "@Nullable" should not be used on primitive types    "@CheckForNull" 或者 "@Nullable" 注解不应该用于基本类型(byte, short, int, long, float, double, boolean, char).    
启用    "@Controller" classes that use "@SessionAttributes" must call "setComplete" on their "SessionStatus" objects    使用了“@SessionAttributes”注解的“@Controller”类必须在其“SessionStatus”对象上调用“setComplete”.    
启用    "@Deprecated" code should not be used    被@Deprecated 注解标注的代码不应该被使用.    
启用    "@EnableAutoConfiguration" should be fine-uned    @EnableAutoConfiguration”缺点是它可能加载和配置应用程序永远不会使用的bean,因此会消耗比实际需要更多的CPU和RAM。@EnableAutoConfiguration应该配置为排除应用程序不需要的所有bean.    
启用    "@Import"s should be preferred to "@ComponentScan"s    由于@ComponentScan会减慢项目启动的速度,应该选择显式引入jar包的“@Import”注解,而不是“@ComponentScan”注解.    
启用    "@NonNull" values should not be set to null    @NonNull注解修饰的字段不能被赋为null, 标记为@NotNull、@NonNull或@NonNull的字段、参数和返回值通常在使用前不检查空值。将这些值中的一个设置为null,或者在构造函数中没有设置这样的类fieldin,可能会在运行时导致nullpointerexception.    
启用    "@Override" should be used on overriding and implementing methods    在重写和实现方法时,需要添加"@Override"注解.    
启用    "@RequestMapping" methods should be "public"    "@RequestMapping"注解应该用来修饰public方法/类.    
启用    "@RequestMapping" methods should specify HTTP method    @RequestMapping应该显式的指定HTTP请求的类型.    
启用    "@SpringBootApplication" and "@ComponentScan" should not be used in the default package    "@SpringBootApplication" 和 "@ComponentScan" 注解不应该在默认包中使用.    
启用    "action" mappings should not have too many "forward" entries    action映射不应该有太多的“forward”实体.    
启用    "Arrays.stream" should be used for primitive arrays    流应该被用在基本类型数组上.    
启用    "Bean Validation" (JSR 380) should be properly configured    "Bean Validation" (JSR 380)应该被正确的配置,未添加@Valid 注解时,Bean Validation 校验将不会生效.    
启用    "BigDecimal(double)" should not be used    由于精度的原因,BigDecimal(double) 类型不应该被使用,往往会使用valueof()方法将double类型数据进行转化.    
启用    "catch" clauses should do more than rethrow    catch 捕获到异常之后,不应该仅仅只是抛出异常    
启用    "Class.forName()" should not load JDBC 4.0+ drivers    “Class.forName()”不应该加载JDBC 4.0+驱动程序    
启用    "clone" should not be overridden    clone()方法不应该被重写,重写可能导致浅克隆的问题    
启用    "Cloneables" should implement "clone"    Cloneables 接口需要实现 clone()方法    
启用    "close()" calls should not be redundant    不应该有多余的close()方法的调用    
启用    "collect" should be used with "Streams" instead of "list::add"    使用 Streams 时,应该用 collect,因为collect 的进程是并行且安全的    
启用    "Collections.EMPTY_LIST", "EMPTY_MAP", and "EMPTY_SET" should not be used    因为"Collections.EMPTY_LIST", "EMPTY_MAP", and "EMPTY_SET"会返回默认的集合,会导致对于返回值判null的步骤缺失的问题,不推荐使用    
启用    "compareTo" results should not be checked for specific values    “compareTo”结果不应检查特定值,通常检查>0或者<0    
启用    "compareTo" should not be overloaded    compareTo 参数个数不应该超出声明的个数    
启用    "compareTo" should not return "Integer.MIN_VALUE"    compareTo 的返回值不能是Integer.MIN_VALUE    
启用    "DateUtils.truncate" from Apache Commons Lang library should not be used    Apache Commons Lang 的日期截取方法 DateUtils.truncate() 不会四舍五入,不应该被使用    
启用    "default" clauses should be last    switch中 default应该被放在最后    
启用    "DefaultMessageListenerContainer" instances should not drop messages during restarts    DefaultMessageListenerContainer实例不应该在重启期间删除消息    
启用    "deleteOnExit" should not be used    java程序执行结束后,有自己的回收机制,不需要用deleteOnExit回收临时文件    
启用    "Double.longBitsToDouble" should not be used for "int"    int类型的数据转换为lone double 会存在精度问题,不应该这样使用    
启用    "entrySet()" should be iterated when both the key and value are needed    在需要获取map中的键值对key和value时,应该用entryset()方法    
启用    "enum" fields should not be publicly mutable    集合类型的值不应该是可变的    
启用    "equals" method overrides should accept "Object" parameters    重载的equals方法,应该能接受object类型的参数    
启用    "equals" method parameters should not be marked "@Nonnull"    equals方法的参数不应该被@Nonnull注解修饰,equals()方法可以接受为null的数据    
启用    "equals" methods should be symmetric and work for subclasses    equals方法可以应用于子类,因为"=="操作符需要保证两端数据的对称性,但父类不是子类的实例    
启用    "equals(Object obj)" and "hashCode()" should be overridden in pairs    equals(Object obj)和hashCode()应该成对出现    
启用    "equals(Object obj)" should be overridden along with the "compareTo(T obj)" method    equals(Object obj)和compareTo(T obj)应该一起重写    
启用    "equals(Object obj)" should test argument type    因为equals方法能接受泛型参数,所以需要对于传递的参数类型进行验证    
是    "Exception" should not be caught when not required by called methods    当调用的方法不需要捕获异常时,不应该捕获到异常(主要针对于运行时异常和检查异常)    运行时如果异常应该能正常捕获到,并提醒开发人员调整
启用    "Externalizable" classes should have no-arguments constructors    Externalizable 类需要有无参构造函数    
启用    "File.createTempFile" should not be used to create a directory    File.createTempFile 不够安全,不应该用于创建新的目录    
启用    "final" classes should not have "protected" members    final 类是不可被继承的,不应该有protected 类型的元素    
启用    "finalize" should not set fields to "null"    finalize 修饰的空间不应该被置为null    
启用    "for" loop increment clauses should modify the loops' counters    循环增量子句应该修改计数器    
启用    "for" loop stop conditions should be invariant    循环停止的条件应该是不可变的    
启用    "getClass" should not be used for synchronization    getClass方法不应该被用在synchronization 修饰的方法中    
启用    "hashCode" and "toString" should not be called on array instances    array 实例中不应该使用 hashCode 和 toString 方法    
启用    "HostnameVerifier.verify" should not always return true    HostnameVerifier.verify 不应该一直返回 true    
启用    "HttpOnly" should be set on cookies    应该在 cookies 中设置 HttpOnly 属性,可以有效地防止XSS攻击    
启用    "HttpSecurity" URL patterns should be correctly ordered    用HttpSecurity 方法配置url 应该按照一定的声明顺序    
启用    "HttpServletRequest.getRequestedSessionId()" should not be used    不应该使用 HttpServletRequest.getRequestedSessionId() 方法获取 sessionId    
启用    "if ... else if" constructs should end with "else" clauses    if ... else if 结构应该以 else 语句结束    
启用    "indexOf" checks should not be for positive numbers    indexOf()方法结果判断不应该仅针对于正数    
启用    "indexOf" checks should use a start position    indexOfF方法应该传入起始地址参数    
启用    "instanceof" operators that always return "true" or "false" should be removed    如果 instanceof 操作符的结果一直返回true或者false,那么相关的调用语句应该被删除    
启用    "Integer.toHexString" should not be used to build hexadecimal strings    Integer.toHexString方法不应该用于构建16进制字符串    
启用    "InterruptedException" should not be ignored    不应该忽略InterruptedException(方法阻塞)报错    
启用    "iterator" should not return "this"    iterator()方法不应该返回this    
启用    "Iterator.hasNext()" should not call "Iterator.next()"    Iterator.hasNext()是判断是否有下一个元素,但并不会改变指针指向,而next()会改变指针指向,如果没有下一个元素,会直接报空指针异常    
启用    "Iterator.next()" methods should throw "NoSuchEl
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值