Fix synchronization issue in ArrayAdapter
External bug #19235
Change-Id: I57d28a48ee1e4216e042e7f9d4b198b713f05b93
diff --git a/core/java/android/widget/ArrayAdapter.java b/core/java/android/widget/ArrayAdapter.java
index 593cb59..44f04db 100644
--- a/core/java/android/widget/ArrayAdapter.java
+++ b/core/java/android/widget/ArrayAdapter.java
@@ -206,13 +206,9 @@
public void addAll(T ... items) {
synchronized (mLock) {
if (mOriginalValues != null) {
- for (T item : items) {
- mOriginalValues.add(item);
- }
+ Collections.addAll(mOriginalValues, items);
} else {
- for (T item : items) {
- mObjects.add(item);
- }
+ Collections.addAll(mObjects, items);
}
}
if (mNotifyOnChange) notifyDataSetChanged();
@@ -462,18 +458,22 @@
}
if (prefix == null || prefix.length() == 0) {
+ ArrayList<T> list;
synchronized (mLock) {
- ArrayList<T> list = new ArrayList<T>(mOriginalValues);
- results.values = list;
- results.count = list.size();
+ list = new ArrayList<T>(mOriginalValues);
}
+ results.values = list;
+ results.count = list.size();
} else {
String prefixString = prefix.toString().toLowerCase();
- final ArrayList<T> values = mOriginalValues;
- final int count = values.size();
+ ArrayList<T> values;
+ synchronized (mLock) {
+ values = new ArrayList<T>(mOriginalValues);
+ }
- final ArrayList<T> newValues = new ArrayList<T>(count);
+ final int count = values.size();
+ final ArrayList<T> newValues = new ArrayList<T>();
for (int i = 0; i < count; i++) {
final T value = values.get(i);