Sonar代码规则

Sonar代码规则

blocker级别

序号分类规则解读
1BugLoops should not be infinite循环必须有一个终止条件
2BugOverride both equals and hashcodeequals和hashcode必须同时覆盖或则都不覆盖
3BugResources should be closed使用资源必须关闭
4BugDouble-checked locking should not be useddublecheck可能出现线程安全问题
5Bug“wait” should not be called when multiple locks are held持有多个锁时,不应该调用wait方法,因为wait只会释放一个锁
6Bug“@Controller” classes that use “@SessionAttributes” must call “setComplete” on their “SessionStatus” objects使用SessionAttributes时,需要调用setComplete来销毁attributes信息
7Bug“@SpringBootApplication” and “@ComponentScan” should not be used in the default package这2个注解最好不要分开放在不同包不同类中
8BugPrintf-style format strings should not lead to unexpected behavior at runtime格式化打印时,切勿写错格式与入参
9Bug“wait(…)” should be used instead of “Thread.sleep(…)” when a lock is held在锁机制下,应该使用wait,而不是Thread.sleep;因为sleep不释放资源
10Bug“PreparedStatement” and “ResultSet” methods should be called with valid indicesstatement和resultset下标索引都是1开头
11BugFiles opened in append mode should not be used with ObjectOutputStream追加模式写文档切勿使用ObjectOutputStream,会导致StreamCorruptedException
12BugMethods “wait(…)”, “notify()” and “notifyAll()” should not be called on Thread instanceswait、notify、notifyAll方法不应该被Thread调用,这样会破坏JVM本身改变线程的状态
13BugMethods should not call same-class methods with incompatible “@Transactional” values在同一个类中一个没有Transactional注解调用另外一个有Transactional注解的方法,这个Transactional会不生效
14VulnerabilityStruts validation forms should have unique namesStruts的表单验证,不要使用相同名称
15VulnerabilityDefault EJB interceptors should be declared in “ejb-jar.xml”ejb的拦截器一定要申明到ejb-jar.xml的配置文件中,不能更改配置文件名,否则拦截器会变成非默认
16Vulnerability“”@RequestMapping"" methods should be ““public””@RequestMapping不要使用在private方法中,因为controller的方法通过反射机制调用,private不起到私有的作用。另外加上@sercurity也不起作用,因为AOP代码对非静态方法不起作用
17Vulnerability“HostnameVerifier.verify” should not always return truessl链接必须验证hostname
18VulnerabilityXML parsers should not be vulnerable to XXE attacksXML使用规范,防止被XXE或者SSRF漏洞
19VulnerabilityLDAP deserialization should be disabledLDAP协议不应该启用发序列话,有导致远程攻击的风险
20Vulnerability“javax.crypto.NullCipher” should not be used for anything other than testingCipher加密应该使用比较强大的算法
21VulnerabilityCipher algorithms should be robust加密算法需要健壮,加密说法要指定安全模式和padding规则
22VulnerabilityEncryption algorithms should be used with secure mode and padding scheme加密说法要指定安全模式和padding规则
23VulnerabilityNeither DES (Data Encryption Standard) nor DESede (3DES) should be used不应该使用不安全的加密算法
24VulnerabilitySecurity constraints should be definedweb服务器中web.xml必须设置,增强安全
25VulnerabilityDatabases should be password-protected不应该使用没有密码的数据库
26VulnerabilityOctal values should not be used不建议使用八进制
27code smell[p3c]Braces are used with if, else, for, do and while statements, even if the body contains only a single statement.if、while等建议使用大括号,哪怕主体只有一句代码
28code smellMethods and field names should not be the same or differ only by capitalization方法名和字段名不能相同或仅大小写不同,容易造成困惑
29code smell[p3c]Manually create thread pool is better.手动创建线程池,而非使用Excutor创建,可能考虑排队队列是无限长导致资源耗尽
30code smellMethods returns should not be invariant返回结果不应该只有一种结果
31code smell[p3c]Use System.currentTimeMillis() to get the current millisecond. Do not use new Date().getTime().使用System.currentTimeMillis()代替new Date().getTime(),new Date()其实也是调用currentTimeMillis,所以可以少创建一个对象
32code smell[p3c]The wrapper classes should be compared by equals method rather than by symbol of ‘==’ directly.包装类应该使用equal方法
33code smellSwitch cases should end with an unconditional “break” statement每个case应该以一个无条件的break结束
34code smell“clone” should not be overridden不建议重写clone方法,会造成浅拷贝以及跳过构造函数限制问题
35code smell“main” should not “throw” anythingmain不应该抛异常,因为没有再外层可以catch这个exception
36code smell[p3c]When using regex, precompile needs to be done in order to increase the matching performance.使用正则表达式,最好使用预编译号的pattern以提高性能
37code smellShort-circuit logic should be used in boolean contextsboolean类型使用非与或操作以为的操作,可能导致错误
38code smellFuture keywords should not be used as names部分高版本已经被java定为关键字,最好也不要使用
39code smell“ThreadGroup” should not be usedThreadGroup不要再使用了,有些方法不推荐,有些方法不安全。使用ThreadFactory和ThreadPoolExecutor代替
40code smellEJB interceptor exclusions should be declared as annotations不推荐使用EJB的xml配置拦截器,推荐使用注解方式,这样更能显示看到
41code smellJUnit test cases should call super methodsJUnit测试用例,在初始化和结束方法中,如果是继承类最好调用super方法
42code smellTestCases should contain testsTestCase中最好包含测试用例的方法,以避免命名TestCase但不是做测试用例而忽略某个类的测试
43code smellSilly bit operations should not be performed某些确定的位移操作是可确定的,比如&-1、^0、
44code smell““switch”” statements should not contain non-case labelsswitch语句的case分支不能省略case关键字;case分支的逻辑处理代码要封装为一个方法,不要在case分支里写复杂的逻辑处理
45code smellAssertions should be complete断言方法要写全
46code smellJUnit framework methods should be declared properly测试用例的方法命名必须按照JUnit规范
47code smellChild class fields should not shadow parent class fields子类不推荐修改父类的属性的更封闭的修饰词,容易造成混乱
48code smellThreads should not be started in constructors不应该在构造方法调用线程启动方法,如果该类被继承,那么线程可以在子类初始化完成之前启动,可能造成混乱
49code smellTests should include assertions测试用例中应该使用断言来测试,而非抛异常
50code smellExit methods should not be called不应该在代码中调用System.exit方法,避免被恶意攻击关闭整个JVM
51code smell[p3c]Do not remove or add elements to a collection in a foreach loop.不要在for循环中添加或删除集合的元素
52code smell[p3c]Avoid using Apache Beanutils to copy attributes.不建议使用apache的beanutils拷贝对象,因为性能上比较低
53code smell[p3c]Use ScheduledExecutorService instead.推荐使用ScheduledExecutorService来做定时任务,相对于Timer来说对时间上更严格
54security hotspotHard-coded credentials are security-sensitive硬编码秘钥文件有风险,最好把秘钥文件存储到数据库或者其他专门的服务中和业务代码分开。放在代码中很容易反编译看到秘钥
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值