0
我正在測試CodePro Anlaytix(Eclipse插件)以檢查項目中的代碼樣式。 CPA告訴我,變量「titleParam」和「descParam」中的變量具有空值。CodePro Analytix - 我沒有得到審計規則「Variable has Null Value」
下面是類:
/**
* fdas fsda fsda fsa
* @version 1.0
*/
public class CodeProItem {
/**
* Field title.
*/
private String title;
/**
* Field desc.
*/
private String desc;
/**
* Method getTitle.
* @return String
*/
public String getTitle() {
return title;
}
/**
* Method setTitle.
* @param titleParam String
*/
public void setTitle(String titleParam) {
this.title = titleParam;
}
/**
* Method getDesc.
* @return String
*/
public String getDesc() {
return desc;
}
/**
* Method setDesc.
* @param descParam String
*/
public void setDesc(String descParam) {
this.desc = descParam;
}
}
這裏是規則的摘要(從CPA DOC):
被保證有一個空值,並在 表達式中使用的變量可能表示程序員忘記用其實際值初始化變量 。
規則「變量具有空值」被激活,這是代碼的例子,將通過這條規則被捕獲(註冊會計師DOC):
public boolean myMethod(String param)
{
String tmp = null;
if (tmp.equals(param)) {
return true;
} else {
return false;
}
}
我得到的例子,但爲什麼它是否說我在setters中的參數是null?
那麼我禁用了這個規則。設置者沒有被調用,我的項目中只有1個類(用於測試CodePro)。 CodePro仍然非常有趣,它是findbugs,codestyle和指標之間的混搭:) – mrmuggles 2012-01-17 21:39:26