Suppress index-out-of-bounds warning from LGTM about loop unrolling (#8380)

* Suppress index-out-of-bounds warning from LGTM about loop unrolling

* Remove space

* Patch comments
This commit is contained in:
Benedict Jin 2019-09-07 05:46:33 +08:00 committed by Himanshu
parent ec836ae8f8
commit 9fa3407596
2 changed files with 18 additions and 14 deletions

View File

@ -107,13 +107,15 @@ public class TopNLexicographicResultBuilder implements TopNResultBuilder
}
for (int i = extra; i < metricVals.length; i += LOOP_UNROLL_COUNT) {
metricValues.put(aggFactoryNames[i + 0], metricVals[i + 0]);
metricValues.put(aggFactoryNames[i + 1], metricVals[i + 1]);
metricValues.put(aggFactoryNames[i + 2], metricVals[i + 2]);
metricValues.put(aggFactoryNames[i + 3], metricVals[i + 3]);
metricValues.put(aggFactoryNames[i + 4], metricVals[i + 4]);
metricValues.put(aggFactoryNames[i + 5], metricVals[i + 5]);
metricValues.put(aggFactoryNames[i + 6], metricVals[i + 6]);
metricValues.put(aggFactoryNames[i + 7], metricVals[i + 7]);
// LGTM.com flags this, but it's safe
// because we know "metricVals.length - extra" is a multiple of LOOP_UNROLL_COUNT.
metricValues.put(aggFactoryNames[i + 1], metricVals[i + 1]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 2], metricVals[i + 2]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 3], metricVals[i + 3]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 4], metricVals[i + 4]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 5], metricVals[i + 5]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 6], metricVals[i + 6]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 7], metricVals[i + 7]); // lgtm [java/index-out-of-bounds]
}
pQueue.add(new DimValHolder.Builder().withDimValue(dimValue, ValueType.STRING).withMetricValues(metricValues).build());

View File

@ -150,13 +150,15 @@ public class TopNNumericResultBuilder implements TopNResultBuilder
}
for (int i = extra; i < metricVals.length; i += LOOP_UNROLL_COUNT) {
metricValues.put(aggFactoryNames[i + 0], metricVals[i + 0]);
metricValues.put(aggFactoryNames[i + 1], metricVals[i + 1]);
metricValues.put(aggFactoryNames[i + 2], metricVals[i + 2]);
metricValues.put(aggFactoryNames[i + 3], metricVals[i + 3]);
metricValues.put(aggFactoryNames[i + 4], metricVals[i + 4]);
metricValues.put(aggFactoryNames[i + 5], metricVals[i + 5]);
metricValues.put(aggFactoryNames[i + 6], metricVals[i + 6]);
metricValues.put(aggFactoryNames[i + 7], metricVals[i + 7]);
// LGTM.com flags this, but it's safe
// because we know "metricVals.length - extra" is a multiple of LOOP_UNROLL_COUNT.
metricValues.put(aggFactoryNames[i + 1], metricVals[i + 1]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 2], metricVals[i + 2]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 3], metricVals[i + 3]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 4], metricVals[i + 4]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 5], metricVals[i + 5]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 6], metricVals[i + 6]); // lgtm [java/index-out-of-bounds]
metricValues.put(aggFactoryNames[i + 7], metricVals[i + 7]); // lgtm [java/index-out-of-bounds]
}
// Order matters here, do not unroll