从 FingBugs的错误来看JAVA代码质量(四)

[b]错误码:RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE[/b]


[img]http://dl.iteye.com/upload/attachment/511818/d309c0e6-d1d2-35d1-9e01-093748dc45fe.jpg[/img]

Bug: Redundant nullcheck of bean1, which is known to be non-null
Pattern id: RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE, type: RCN, category: STYLE
This method contains a redundant check of a known non-null value against the constant null.
解释:这种方法包含了一个称为非空对空值的不断重复检查。
修改为:


[img]http://dl.iteye.com/upload/attachment/511820/8644fd8c-1e2d-3f90-99b6-4aef922af903.jpg[/img]


[b]错误码:SS_SHOULD_BE_STATIC[/b]


[img]http://dl.iteye.com/upload/attachment/511822/d62f4cf0-bed3-3181-865f-95c8e652cf68.jpg[/img]

Bug: Unread field: ADDRESS_KEY; should this field be static?
Pattern id: SS_SHOULD_BE_STATIC, type: SS, category: PERFORMANCE
This class contains an instance final field that is initialized to a compile-time static value. Consider making the field static.
解释:
final成员变量表示常量,只能被赋值一次,赋值后值不再改变。
这个类包含的一个final变量初始化为编译时静态值。考虑变成静态常量
解决方法:
增加static关键字


[b]错误码:NM_METHOD_NAMING_CONVENTION[/b]

[img]http://dl.iteye.com/upload/attachment/511825/69b8122f-e464-35b9-a5fd-c3e59320d3ae.jpg[/img]

Bug: The method name MsmPlanDAOTest.TestViewMsmPlanList() doesn't start with a lower case letter
Pattern id: NM_METHOD_NAMING_CONVENTION, type: Nm, category: BAD_PRACTICE
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
解释:
方法应该是动词,与第一个字母小写混合的情况下,与每个单词的首字母大写的内部。
解决方法:
方法名称小写就通过了。我们写代码还是要规范啊,虽然是单元测试的代码!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值