|
19 | 19 | import com.google.common.annotations.VisibleForTesting; |
20 | 20 | import io.opencensus.common.Duration; |
21 | 21 | import io.opencensus.common.ToLongFunction; |
| 22 | +import io.opencensus.implcore.internal.CheckerFrameworkUtils; |
22 | 23 | import io.opencensus.implcore.internal.DaemonThreadFactory; |
23 | 24 | import io.opencensus.implcore.trace.RecordEventsSpanImpl; |
24 | 25 | import io.opencensus.metrics.DerivedLongCumulative; |
@@ -318,13 +319,17 @@ private long getPushedSpans() { |
318 | 319 | } |
319 | 320 | } |
320 | 321 |
|
321 | | - @SuppressWarnings("argument.type.incompatible") |
322 | | - private void exportBatches(ArrayList<RecordEventsSpanImpl> spanList) { |
| 322 | + private void exportBatches(ArrayList<RecordEventsSpanImpl> spansCopy) { |
323 | 323 | ArrayList<SpanData> spanDataList = new ArrayList<>(bufferSize); |
324 | | - for (int i = 0; i < spanList.size(); i++) { |
325 | | - spanDataList.add(spanList.get(i).toSpanData()); |
| 324 | + for (int i = 0; i < spansCopy.size(); i++) { |
| 325 | + spanDataList.add(spansCopy.get(i).toSpanData()); |
| 326 | + |
326 | 327 | // Remove the reference to the RecordEventsSpanImpl to allow GC to free the memory. |
327 | | - spanList.set(i, null); |
| 328 | + // TODO: Refactor the handling of the spans list to remove this call to castNonNull. Setting |
| 329 | + // the elements to null after they are read is safe because 'exportBatches' is only ever |
| 330 | + // called on a copy of 'spans', and the copy is not reused. |
| 331 | + spansCopy.set(i, (RecordEventsSpanImpl) CheckerFrameworkUtils.castNonNull(null)); |
| 332 | + |
328 | 333 | if (spanDataList.size() == bufferSize) { |
329 | 334 | // One full batch, export it now. Wrap the list with unmodifiableList to ensure exporter |
330 | 335 | // does not change the list. |
|
0 commit comments