![](/img/trans.png)
[英]while loop in seperate thread continues running after condition has been changed via seperate method in main thread
[英]How to resolve the sonar issue “Correctness - This method continues a loop after finding an equality condition ”
我有以下代码。 我想从代码中得到的只是
String LOCALE = "locale";
List<Map<String, Object>> labelList = // coming for other class
...
public Object resolveData(String locale) {
Map<String, Object> enUSLabel = null;
locale = locale!= null && !locale.isEmpty() ? locale: EN_US;
for (Map<String, Object> picklistLabel : labelList) {
if (picklistLabel.get(LOCALE).equals(locale)) {
return picklistLabel;
} else if (EN_US.equals(picklistLabel.get(LOCALE))) {
enUSLabel = picklistLabel;
}
}
return enUSLabel;
}
我遇到声纳问题(在 enUSLabel = picklistLabel;)
正确性 - 此方法在找到相等条件后继续循环 此方法在基于相等的 if 条件中找到并设置变量后继续循环,并且不会跳出循环。 由于继续循环似乎不太可能再次找到该项目,因此在这一点上中断似乎是正确的操作。
如何纠正它? 是否可以在一个 for 循环中使用?
将enUSLabel = picklistLabel
替换为return picklistLabel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.