FindBugs是编码期间,检测代码质量的工具。eclispe插件地址:http://findbugs.cs.umd.edu/eclipse-daily
刚刚使用,是我的一个数据库引擎项目,叫ojadb。初步分析下问题:
1.Comparison of String objects using == or !=
if (methodNames[i]==fields[j].getName()) {
=>if (methodNames[i].equals(fields[j].getName())) {
2.The field name doesn't start with a lower case letter
protected static HashMap<Long, OdbClassInfo> OdbClassAddressMap;
=>protected static HashMap<Long, OdbClassInfo> odbClassAddressMap;
3.Method makes inefficient use of keySet iterator instead of entrySet iterator
Set keys = map.keySet();
for (Object key : keys) {
Object value = map.get(key);
……
=>
Set<Map.Entry> entrys=map.entrySet();
for(Map.Entry entry: entrys){
Object key=entry.getKey();
Object value = entry.getValue();
4.Possible null pointer dereference of classInfo
OdbCache.setClass(classInfo.getClassName(), classInfo);
=>
if(classInfo!=null)
OdbCache.setClass(classInfo.getClassName(), classInfo);
5.Class defines non-transient non-serializable instance field positionInfo
private OdbClassPositionInfo positionInfo;
=>public class OdbClassPositionInfo implements Serializable{
6.Method invokes inefficient new Integer(int) constructor; use Integer.valueOf(int) instead
this.finderValue = new Integer(value);
=>this.finderValue = Integer.valueOf(value);