[英]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.