【发布时间】:2013-12-10 07:45:47
【问题描述】:
我有一个代码分析工具,它在下面的方法中标记了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
}
}
【问题讨论】:
标签: java