我有一个代码分析工具正在用下面的方法标记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
}
}
我不确定,但我认为您会收到错误消息,因为您从未使用分配的new LinkedHashSet<String>();
您收到错误消息,因为您从未使用分配的widgetsToUpdate。