diff options
| author | Dianne Hackborn <hackbod@google.com> | 2016-08-25 17:22:42 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2016-08-25 17:22:42 +0000 |
| commit | d43d24884801b31cfe75c095563401bdaf5469c9 (patch) | |
| tree | f104f6e61c101d5e3b4b2e5f736ccf04f77e8d92 /core/java/android/util/ArraySet.java | |
| parent | 9cdaceb0fabd66294252ddd7780f2997f29dfc65 (diff) | |
| parent | 92aa4b2ba3c93cc344c885b50b75726599e6065d (diff) | |
Try to mitigate issue #31016187: system_server crash in ArraySet.
am: 92aa4b2ba3
Change-Id: I0c44548aad0761dc0c87ac5bd129061e69c39795
Diffstat (limited to 'core/java/android/util/ArraySet.java')
| -rw-r--r-- | core/java/android/util/ArraySet.java | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/core/java/android/util/ArraySet.java b/core/java/android/util/ArraySet.java index 1e765b62e131..a02c070d4889 100644 --- a/core/java/android/util/ArraySet.java +++ b/core/java/android/util/ArraySet.java @@ -156,28 +156,46 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { synchronized (ArraySet.class) { if (mTwiceBaseCache != null) { final Object[] array = mTwiceBaseCache; - mArray = array; - mTwiceBaseCache = (Object[])array[0]; - mHashes = (int[])array[1]; - array[0] = array[1] = null; - mTwiceBaseCacheSize--; - if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes - + " now have " + mTwiceBaseCacheSize + " entries"); - return; + try { + mArray = array; + mTwiceBaseCache = (Object[]) array[0]; + mHashes = (int[]) array[1]; + array[0] = array[1] = null; + mTwiceBaseCacheSize--; + if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes + + " now have " + mTwiceBaseCacheSize + " entries"); + return; + } catch (ClassCastException e) { + } + // Whoops! Someone trampled the array (probably due to not protecting + // their access with a lock). Our cache is corrupt; report and give up. + Slog.wtf(TAG, "Found corrupt ArraySet cache: [0]=" + array[0] + + " [1]=" + array[1]); + mTwiceBaseCache = null; + mTwiceBaseCacheSize = 0; } } } else if (size == BASE_SIZE) { synchronized (ArraySet.class) { if (mBaseCache != null) { final Object[] array = mBaseCache; - mArray = array; - mBaseCache = (Object[])array[0]; - mHashes = (int[])array[1]; - array[0] = array[1] = null; - mBaseCacheSize--; - if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes - + " now have " + mBaseCacheSize + " entries"); - return; + try { + mArray = array; + mBaseCache = (Object[]) array[0]; + mHashes = (int[]) array[1]; + array[0] = array[1] = null; + mBaseCacheSize--; + if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes + + " now have " + mBaseCacheSize + " entries"); + return; + } catch (ClassCastException e) { + } + // Whoops! Someone trampled the array (probably due to not protecting + // their access with a lock). Our cache is corrupt; report and give up. + Slog.wtf(TAG, "Found corrupt ArraySet cache: [0]=" + array[0] + + " [1]=" + array[1]); + mBaseCache = null; + mBaseCacheSize = 0; } } } |
