summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-01-16 12:04:38 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-01-16 12:04:38 +0000
commit7861c3e60b7769a9cce11015a48842f1b1712360 (patch)
treec20daaf0c6cc2055d84a416d1cb79c7e585d870d /luni
parenta4fe2227d3c7e72b84d0ac6b3e15f811564b24ee (diff)
parent5eba1f238e37e3fef73b492badb950225150cdcf (diff)
downloadlibcore-7861c3e60b7769a9cce11015a48842f1b1712360.zip
libcore-7861c3e60b7769a9cce11015a48842f1b1712360.tar.gz
libcore-7861c3e60b7769a9cce11015a48842f1b1712360.tar.bz2
Merge "Revert "Introduce user.locale.""
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/lang/System.java1
-rw-r--r--luni/src/main/java/java/util/Locale.java26
-rw-r--r--luni/src/test/java/libcore/java/util/LocaleTest.java38
3 files changed, 8 insertions, 57 deletions
diff --git a/luni/src/main/java/java/lang/System.java b/luni/src/main/java/java/lang/System.java
index 7cd9b13..9425894 100644
--- a/luni/src/main/java/java/lang/System.java
+++ b/luni/src/main/java/java/lang/System.java
@@ -753,7 +753,6 @@ public final class System {
p.put("file.encoding", "UTF-8");
p.put("user.language", "en");
p.put("user.region", "US");
- p.put("user.locale", "en-US");
try {
StructPasswd passwd = Libcore.os.getpwuid(Libcore.os.getuid());
diff --git a/luni/src/main/java/java/util/Locale.java b/luni/src/main/java/java/util/Locale.java
index 82acb4a..e509a6e 100644
--- a/luni/src/main/java/java/util/Locale.java
+++ b/luni/src/main/java/java/util/Locale.java
@@ -272,27 +272,17 @@ public final class Locale implements Cloneable, Serializable {
*/
private static final String UNDETERMINED_LANGUAGE = "und";
- private static Locale defaultLocale = getDefaultLocaleFromSystemProperties();
-
/**
- * Returns the default locale from system properties.
- *
- * @hide visible for testing.
+ * The current default locale. It is temporarily assigned to US because we
+ * need a default locale to lookup the real default locale.
*/
- public static Locale getDefaultLocaleFromSystemProperties() {
- final String languageTag = System.getProperty("user.locale", "");
+ private static Locale defaultLocale = US;
- final Locale defaultLocale;
- if (!languageTag.isEmpty()) {
- defaultLocale = Locale.forLanguageTag(languageTag);
- } else {
- String language = System.getProperty("user.language", "en");
- String region = System.getProperty("user.region", "US");
- String variant = System.getProperty("user.variant", "");
- defaultLocale = new Locale(language, region, variant);
- }
-
- return defaultLocale;
+ static {
+ String language = System.getProperty("user.language", "en");
+ String region = System.getProperty("user.region", "US");
+ String variant = System.getProperty("user.variant", "");
+ defaultLocale = new Locale(language, region, variant);
}
/**
diff --git a/luni/src/test/java/libcore/java/util/LocaleTest.java b/luni/src/test/java/libcore/java/util/LocaleTest.java
index c6dd730..15e01a1 100644
--- a/luni/src/test/java/libcore/java/util/LocaleTest.java
+++ b/luni/src/test/java/libcore/java/util/LocaleTest.java
@@ -1165,42 +1165,4 @@ public class LocaleTest extends junit.framework.TestCase {
assertEquals('\u0660', new DecimalFormatSymbols(ar_EG_arab).getZeroDigit());
assertEquals('0', new DecimalFormatSymbols(ar_EG_latn).getZeroDigit());
}
-
- public void testDefaultLocale() throws Exception {
- final String userLanguage = System.getProperty("user.language", "");
- final String userRegion = System.getProperty("user.region", "");
- final String userLocale = System.getProperty("user.locale", "");
- try {
- // Assert that user.locale gets priority.
- System.setProperty("user.locale", "de-DE");
- System.setProperty("user.language", "en");
- System.setProperty("user.region", "US");
-
- Locale l = Locale.getDefaultLocaleFromSystemProperties();
- assertEquals("de", l.getLanguage());
- assertEquals("DE", l.getCountry());
-
- // Assert that it's parsed as a full language tag.
- System.setProperty("user.locale", "de-Latn-DE");
- System.setProperty("user.language", "en");
- System.setProperty("user.region", "US");
-
- l = Locale.getDefaultLocaleFromSystemProperties();
- assertEquals("de", l.getLanguage());
- assertEquals("DE", l.getCountry());
- assertEquals("Latn", l.getScript());
-
- // Assert that we use "und" if we're faced with a bad language tag, and
- // that we don't end up with a null default locale or an exception.
- System.setProperty("user.locale", "dexx-Latn-DE");
-
- l = Locale.getDefaultLocaleFromSystemProperties();
- assertEquals("und", l.getLanguage());
- assertEquals("DE", l.getCountry());
- } finally {
- System.setProperty("user.language", userLanguage);
- System.setProperty("user.region", userRegion);
- System.setProperty("user.locale", userLocale);
- }
- }
}