Address static cache access issues.

ArrayMap and ArraySet are not thread safe, so callers are expected to
lock around their instances before calling any methods. However, if a
caller fails to lock, there can be races that end up corrupting the
cache pool (despite having the class level lock held). A corrupted pool
causes issues for other ArrayMap/Set instances, even if those instances
are properly used under locks. There's no way to guard against cache
pool corruption without making ArrayMap/Set fully thread-safe, changing
the pool structure, or appropriately locking around each ArrayMap/Set
instance.

For now, we make ArraySet throw ConcurrentModificationException on a best
effort basis to provide better awareness when an ArraySet is accessed
concurrently without any locks and try to detect when the cache is
corrupted.

Bug: 62282384
Bug: 73549921
Bug: 122969275
Bug: 139015193
Bug: 139401479
Test: atest CtsUtilTestCases:ArrayMapTest
Test: atest CtsUtilTestCases:ArraySetTest
Test: atest FrameworksCoreTests:ArrayMapTest
Test: atest FrameworksCoreTests:ArraySetTest
Change-Id: Icd76630b25afd9f3627239301ffa5c37da25ea18
3 files changed