gpt4 book ai didi

sonarqube5.1 - 发现 'UR' - 变量异常

转载 作者:行者123 更新时间:2023-12-04 05:09:48 29 4
gpt4 key购买 nike

我有这个声纳错误主要:

Found 'UR'-anomaly for variable 'language' (lines '83'-'85')



在这个函数中:
public void saveAll(List<Language> languages){
//Found 'UR'-anomaly for variable 'country' (lines '83'-'85').
//Code Smell Major Open Not assigned 20min effort Comment
for (Language language: languages) {
save(language);
}
}

请如何解决这个重大错误,谢谢提前

最佳答案

编辑 :
在其他 SO 帖子中找到了更多信息。虽然这更以 PMD 为中心,但您可能会对背景信息感兴趣。
Java for each loop being flagged as UR anomaly by PMD .

这似乎是 PMD 的规则。定义:

The dataflow analysis tracks local definitions, undefinitions and references to variables on different paths on the data flow. From those informations there can be found various problems. 1. UR - Anomaly: There is a reference to a variable that was not defined before. This is a bug and leads to an error. 2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text. 3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.



有一个开放的错误报告:
https://sourceforge.net/p/pmd/bugs/1190/

在示例中,他们为数组报告了它,但有人评论说,这也发生在他们身上,也发生在集合中。

例子:
public static void main(final String[] args) {
for (final String string : args) {
string.getBytes(); //UR Anomaly
}
for (int i = 0; i < args.length; i++) {
args[i].getBytes();
}
}

在我们的声纳设置中,我们不使用此规则。根据可用信息,您可能不希望在您的信息中使用它。

关于sonarqube5.1 - 发现 'UR' - 变量异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40104296/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com