From b21e7cee30993f32efc0b30043d5461963623965 Mon Sep 17 00:00:00 2001 From: Jeremy Meyer Date: Mon, 28 Feb 2022 22:35:37 +0000 Subject: [PATCH] Fix a ConcurrentModificationException when dumping resources Since the sResourcesHistory set is synchronized, an attemp to modify the set will block while the forEach() method is running in the rare case resources are being dumped. With a normal for loop, modifying the set while in the loop results in a ConcurrentModificationException. Fixes: 219609463 Test: Manual Change-Id: I9b7bb965aa390e5dec696be07599f777c807c1e3 --- core/java/android/content/res/Resources.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index ebef0535f0779..a03286d3ec6f6 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -2674,9 +2674,8 @@ public class Resources { // Putting into a map keyed on the apk assets to deduplicate resources that are different // objects but ultimately represent the same assets Map, Resources> history = new ArrayMap<>(); - for (Resources r : sResourcesHistory) { - history.put(Arrays.asList(r.mResourcesImpl.mAssets.getApkAssets()), r); - } + sResourcesHistory.forEach( + r -> history.put(Arrays.asList(r.mResourcesImpl.mAssets.getApkAssets()), r)); int i = 0; for (Resources r : history.values()) { if (r != null) {