1、
if(attributes!=null && !attributes.isEmpty()){
for(String key : attributes.keySet() ) {
sb.append(" ").append(entry).append("=").append("'").append(attributes.get(entry)).append("'").append(" ");
}
}
用上面的代码会有这样的隐患:
Performance - Inefficient use of keySet iterator instead of entrySet iterator
This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.
findbugs:WMI_WRONG_MAP_ITERATOR Efficiency > Processor use
if(attributes!=null && !attributes.isEmpty()){
for(Entry<String, Object> entry : attributes.entrySet() ) {
sb.append(" ").append(entry).append("=").append("'").append(attributes.get(entry)).append("'").append(" ");
}
}
2、
3、
AccountApp accountApp = accountAppService.getByPubId(pubAccount.getAccountId());
上面的代码可能有null的隐患,改为下面的代码。
AccountApp accountApp = null;
if( pubAccount!=null ){
accountApp = accountAppService.getByPubId(pubAccount.getAccountId());
}
相关链接:https://ci.openmrs.org/sonar/rules_configuration/index/4