summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2020-08-26 14:42:08 -0700
committerAnis Assi <anisassi@google.com>2020-09-10 13:51:58 -0700
commit9d69c14f68c1d8296e15a225ec5798a14e568d0c (patch)
tree8bf4c010d825482021ecaaba48e059f041d1d91c
parent8879790a7bf87ffe808803364b927fa1182271b8 (diff)
downloadbase-android-security-10.0.0_r48.tar.gz
Accept repeated locale as an input of LocaleList construction.android-security-10.0.0_r48
Repeated locale has not been accepted and IllegalArgumentException is thrown. Instead of throwing exception, dropping repeated locale instead. Bug: 152410253 Test: atest LocaleListTest Change-Id: I80f243678ac3024eaeb0349f770cff897df7f332 (cherry picked from commit 3d25b3b9b4913e5bdc25dcbe51179276e4359ba8)
-rw-r--r--core/java/android/os/LocaleList.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/core/java/android/os/LocaleList.java b/core/java/android/os/LocaleList.java
index 7782753e4abc..22e6689461a3 100644
--- a/core/java/android/os/LocaleList.java
+++ b/core/java/android/os/LocaleList.java
@@ -27,6 +27,7 @@ import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.GuardedBy;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -173,18 +174,18 @@ public final class LocaleList implements Parcelable {
/**
* Creates a new {@link LocaleList}.
*
+ * If two or more same locales are passed, the repeated locales will be dropped.
* <p>For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()},
* which returns a pre-constructed empty list.</p>
*
* @throws NullPointerException if any of the input locales is <code>null</code>.
- * @throws IllegalArgumentException if any of the input locales repeat.
*/
public LocaleList(@NonNull Locale... list) {
if (list.length == 0) {
mList = sEmptyList;
mStringRepresentation = "";
} else {
- final Locale[] localeList = new Locale[list.length];
+ final ArrayList<Locale> localeList = new ArrayList<>();
final HashSet<Locale> seenLocales = new HashSet<Locale>();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.length; i++) {
@@ -192,10 +193,10 @@ public final class LocaleList implements Parcelable {
if (l == null) {
throw new NullPointerException("list[" + i + "] is null");
} else if (seenLocales.contains(l)) {
- throw new IllegalArgumentException("list[" + i + "] is a repetition");
+ // Dropping duplicated locale entries.
} else {
final Locale localeClone = (Locale) l.clone();
- localeList[i] = localeClone;
+ localeList.add(localeClone);
sb.append(localeClone.toLanguageTag());
if (i < list.length - 1) {
sb.append(',');
@@ -203,7 +204,7 @@ public final class LocaleList implements Parcelable {
seenLocales.add(localeClone);
}
}
- mList = localeList;
+ mList = localeList.toArray(new Locale[localeList.size()]);
mStringRepresentation = sb.toString();
}
}