IndexOutOfBoundsException in MeasureMapInternal
Please answer these questions before submitting a bug report.
What version of OpenCensus are you using?
0.23.0 (latest)
What JVM are you using (java -version)?
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode)
What did you do?
If possible, provide a recipe for reproducing the error.
// recorder is from Stats.getStatsRecorder()
// measure is a MeasureLong, but I'm pretty sure this will repro with any Measure subclass
recorder.newMeasureMap().put(measure, 25L)
.put(measure, 15L)
.put(measure, 35L)
.put(measure, 33L)
.put(measure, 37L)
.record();
What did you expect to see?
One of the measurements in the map.
What did you see instead?
IndexOutOfBoundsException
Additional context
Add any other context about the problem here. The problem is a classic mutated iterated list in MeasureMapInternal:
for (int i = measurements.size() - 1; i >= 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (measurements.get(i).getMeasure() == measurements.get(j).getMeasure()) {
measurements.remove(j);
j--;
}
}
}
This needs i--; in the inner-most block. Because i is strictly greater than j, and the item at index j is removed, the item that was at index i is now at i-1.
I would fix this myself but I need to check with my employer about signing the CLA.
Thanks @jeffalder for reporting this issue. It would be nice if you can send a fix on it.
@songy23 I have a fix here: https://github.com/census-instrumentation/opencensus-java/compare/master...jeffalder:mmi-array-mutation . I'm working internally to get permissions to sign the CLA and open the PR.
@songy23 Should I even bother contributing here? Or should I be looking at Open Telemetry-java?
It still makes sense to contribute here because
- We'll continue maintaining this repo for a long time, and want to continue getting this kind of bug fixed.
- Metrics implementation of OpenTelemetry-Java is not yet complete and will likely port a lot of the implementation from this repo.