简单举几个CodeReview的常见错误
今天给公司某个项目做个codereview,用findbugs默认配置规则跑了下,发现了几个问题,都是平时coding时稍微注意下,就能避免这样的不适。
1、空指针引用
Load of known null value
Priority:
Medium Confidence Dodgy code
Problem classification:
Dodgy code (Null pointer dereference)
NP_LOAD_OF_KNOWN_NULL_VALUE (Load of known null value)
Notes:
Value loaded from partyId
LoadOfKnownNullValue (NP)
if (null == partyId && partyId == 0){
**
return PartyResultBuilder.error(CustomerConstants.partyId_error).toCamelString();
}
又或如:
if (null == partyIds && partyIds.size() == 0){
return JsonMapper.getCommonJson("error", "W10007", "partyIds不能为空", "0", null);
}
2、程序没有及时return,导致后续流程空指针异常
PartyTrailerList partyTrailerListCheck=partyTrailerListService.selectByPrimaryKey(partyTrailerList.getPartyTrailerListId(