• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtpythonrubywindowsphpgamebathyscapheguic翻訳omegatframework計画中(planning stage)twitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

frameworks/base


Commit MetaInfo

Revisiond51d737fcd46593f32d02a30abbb59d14af8f05e (tree)
Time2020-11-06 08:32:38
AuthorSeigo Nonaka <nona@goog...>
Commitersyphyr

Log Message

Accept repeated locale as an input of LocaleList construction.

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 142ce41bfadbbe984cb42484b98b1dddf4483c91)

Change Summary

Incremental Difference

--- a/core/java/android/os/LocaleList.java
+++ b/core/java/android/os/LocaleList.java
@@ -24,6 +24,7 @@ import android.icu.util.ULocale;
2424
2525 import com.android.internal.annotations.GuardedBy;
2626
27+import java.util.ArrayList;
2728 import java.util.Arrays;
2829 import java.util.Collection;
2930 import java.util.HashSet;
@@ -150,18 +151,18 @@ public final class LocaleList implements Parcelable {
150151 /**
151152 * Creates a new {@link LocaleList}.
152153 *
154+ * If two or more same locales are passed, the repeated locales will be dropped.
153155 * <p>For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()},
154156 * which returns a pre-constructed empty list.</p>
155157 *
156158 * @throws NullPointerException if any of the input locales is <code>null</code>.
157- * @throws IllegalArgumentException if any of the input locales repeat.
158159 */
159160 public LocaleList(@NonNull Locale... list) {
160161 if (list.length == 0) {
161162 mList = sEmptyList;
162163 mStringRepresentation = "";
163164 } else {
164- final Locale[] localeList = new Locale[list.length];
165+ final ArrayList<Locale> localeList = new ArrayList<>();
165166 final HashSet<Locale> seenLocales = new HashSet<Locale>();
166167 final StringBuilder sb = new StringBuilder();
167168 for (int i = 0; i < list.length; i++) {
@@ -169,10 +170,10 @@ public final class LocaleList implements Parcelable {
169170 if (l == null) {
170171 throw new NullPointerException("list[" + i + "] is null");
171172 } else if (seenLocales.contains(l)) {
172- throw new IllegalArgumentException("list[" + i + "] is a repetition");
173+ // Dropping duplicated locale entries.
173174 } else {
174175 final Locale localeClone = (Locale) l.clone();
175- localeList[i] = localeClone;
176+ localeList.add(localeClone);
176177 sb.append(localeClone.toLanguageTag());
177178 if (i < list.length - 1) {
178179 sb.append(',');
@@ -180,7 +181,7 @@ public final class LocaleList implements Parcelable {
180181 seenLocales.add(localeClone);
181182 }
182183 }
183- mList = localeList;
184+ mList = localeList.toArray(new Locale[localeList.size()]);
184185 mStringRepresentation = sb.toString();
185186 }
186187 }