4
我有一個代碼分析工具,萎靡不振的LinkedHashSet<String> widgetsToCreate = new LinkedHashSet<String>();
線在下面的方法,在方法來解決,將滿足分析工具的邏輯什麼想法?代碼分析失敗:死存儲到本地變量
死存儲到局部變量:
該指令將一個值分配給本地變量,但該值不被讀取或以任何後續指令使用。通常,這表示出現錯誤,因爲計算的值從不使用。請注意,Sun的javac編譯器通常爲最終的局部變量生成死鎖存儲。由於FindBugs是一個基於字節碼的工具,因此沒有簡單的方法來消除這些誤報。
public void add(Map<String, String> input) {
TreeSet<String> widgetsToAdd = new TreeSet<String>();
TreeSet<String> widgetsToUpdate = new TreeSet<String>();
LinkedHashSet<String> widgetsToCreate = new LinkedHashSet<String>();
for (Map.Entry<String, String> entry : input.entrySet()) {
//logic to add to widgetsToAdd based on content of the input Map
}
widgetsToCreate = processInput(widgetsToAdd);
for (Iterator<String> wIterator = widgetsToCreate.iterator(); wIterator.hasNext();) {
//process each widgetsToCreate
}
}