Dan*_*roa 5 java static-analysis sonarlint
我有一段看起来像这样的代码:
public void test() {
Stream.of(aSet.entrySet(), anotherSet.entrySet())
.flatMap(Collection::stream)
.forEach((es) -> {
try {
//Complains on unused variable message.
Value value = es.getValue();
...use value.
} catch (IllegalArgumentException e) {
String key = es.getKey();
//Complains on unused variable message.
String message = " (#" + key + ")";
throw new IllegalArgumentException(message, e);
}
});
}
这段代码仅使用 catch 子句中的关键变量的事实并非如此,因为我在其他地方也遇到了这个错误。
这对于声纳(sonarlint)来说似乎是一件奇怪的事情。因为对我来说它使用了变量,并且不应该被Unused local variable
规则捕获。我错了还是这是一个有效的投诉?