Background
Follow-up to #14469 (SpotBugs check enforcement). This addresses the NS_DANGEROUS_NON_SHORT_CIRCUIT pattern — using the non-short-circuit operator & instead of && in a boolean expression. When used in a for-loop condition, & always evaluates both operands even when the first is already false, which is unnecessary and potentially dangerous.
Affected locations (1 occurrence)
| File |
Line |
Current code |
core/.../NacosServerLoaderService.java |
L137 |
for (int i = 0; i < overLimitServer.size() & i < lowLimitServer.size(); i++) |
The & operator evaluates both i < overLimitServer.size() and i < lowLimitServer.size() unconditionally. With &&, the second condition would be skipped when the first is already false, which is the correct short-circuit behavior for a loop guard.
Fix
Replace & with && in the for-loop condition (single character change):
- for (int i = 0; i < overLimitServer.size() & i < lowLimitServer.size(); i++) {
+ for (int i = 0; i < overLimitServer.size() && i < lowLimitServer.size(); i++) {
After fixing, the NS_DANGEROUS_NON_SHORT_CIRCUIT exclusion in style/spotbugs-exclude.xml should be removed so that future occurrences are caught by CI.
Background
Follow-up to #14469 (SpotBugs check enforcement). This addresses the
NS_DANGEROUS_NON_SHORT_CIRCUITpattern — using the non-short-circuit operator&instead of&&in a boolean expression. When used in a for-loop condition,&always evaluates both operands even when the first is alreadyfalse, which is unnecessary and potentially dangerous.Affected locations (1 occurrence)
core/.../NacosServerLoaderService.javafor (int i = 0; i < overLimitServer.size() & i < lowLimitServer.size(); i++)The
&operator evaluates bothi < overLimitServer.size()andi < lowLimitServer.size()unconditionally. With&&, the second condition would be skipped when the first is alreadyfalse, which is the correct short-circuit behavior for a loop guard.Fix
Replace
&with&&in the for-loop condition (single character change):After fixing, the
NS_DANGEROUS_NON_SHORT_CIRCUITexclusion instyle/spotbugs-exclude.xmlshould be removed so that future occurrences are caught by CI.