From 1acd0739fafe07d21dd5c11446c72179775ee7dc Mon Sep 17 00:00:00 2001 From: Adam He Date: Mon, 26 Apr 2021 13:52:01 -0700 Subject: [PATCH] Change clearEvents() to clear existing events rather than setting mEvents to null to remove possible NPE. * clearEvents() needs to be called by destroy() which could cause race condition on whether mEvents is null for other func calls. Fixes: 185162720 Test: atest CtsContentCaptureServiceTestCases Change-Id: I7330e651bc890c8a86822158efcf17a61e927112 --- .../view/contentcapture/MainContentCaptureSession.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index f196f75861ec9..ad4ba76a17cb1 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -583,9 +583,9 @@ public final class MainContentCaptureSession extends ContentCaptureSession { // NOTE: we must save a reference to the current mEvents and then set it to to null, // otherwise clearing it would clear it in the receiving side if the service is also local. final List events = mEvents == null - ? Collections.emptyList() - : mEvents; - mEvents = null; + ? Collections.EMPTY_LIST + : new ArrayList<>(mEvents); + mEvents.clear(); mLastComposingSpan.clear(); return new ParceledListSlice<>(events); }