Sonarlint评估真正使用的未使用变量

时间:2018-05-08 12:42:02

标签: 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规则捕获。 我错了还是这是一个有效的投诉?

0 个答案:

没有答案
相关问题