From 5eba1f238e37e3fef73b492badb950225150cdcf Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Fri, 16 Jan 2015 12:04:24 +0000 Subject: Revert "Introduce user.locale." This reverts commit 7f6e083f86b711bf905edbf1932f6b35877f9d92. Breaks an art test, not sure why. Change-Id: Idbdb03b6e038b73ac07cf3343ff7ddd123d06d01 --- luni/src/main/java/java/lang/System.java | 1 - luni/src/main/java/java/util/Locale.java | 26 +++++---------- .../test/java/libcore/java/util/LocaleTest.java | 38 ---------------------- 3 files changed, 8 insertions(+), 57 deletions(-) (limited to 'luni') 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); - } - } } -- cgit v1.1