diff options
author | Victor Chang <vichang@google.com> | 2020-07-14 21:45:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-14 21:45:32 +0000 |
commit | 7e776c3e3834c06ad946e34c3dbd29168367e16c (patch) | |
tree | f1e2fd205c2fb5df0ef2957b5ea2b7977986d7a7 | |
parent | 10a967ca07ebabffba1a97bf97f6ac2abf914158 (diff) | |
parent | 8982b713d5a154722d63ea85423b223093d139b1 (diff) |
Merge "Fix stack overflow in libcore.java.lang.StringTest#testFormat_invalidLocale" into rvc-dev am: 8982b713d5
Original change: https://googleplex-android-review.googlesource.com/c/platform/libcore/+/12128015
Change-Id: Ia8c3f0c295fce7c66207b8b57ebf0782d1ea9619
-rw-r--r-- | luni/src/main/java/libcore/icu/LocaleData.java | 17 | ||||
-rw-r--r-- | luni/src/test/java/libcore/libcore/icu/LocaleDataTest.java | 8 |
2 files changed, 17 insertions, 8 deletions
diff --git a/luni/src/main/java/libcore/icu/LocaleData.java b/luni/src/main/java/libcore/icu/LocaleData.java index 3e4e1d7b38..12b978de15 100644 --- a/luni/src/main/java/libcore/icu/LocaleData.java +++ b/luni/src/main/java/libcore/icu/LocaleData.java @@ -25,6 +25,8 @@ import android.icu.impl.ICUResourceBundle; import android.icu.text.NumberingSystem; import android.icu.util.UResourceBundle; +import dalvik.system.VMRuntime; + import java.text.DateFormat; import java.util.HashMap; import java.util.Locale; @@ -71,6 +73,9 @@ public final class LocaleData { * * Note that Locale.ROOT is used as language/country neutral locale or fallback locale, * and does not guarantee to represent English locale. + * + * This flag is only for documentation and can't be overridden by app. Please use + * {@code targetSdkVersion} to enable the new behavior. */ @ChangeId @EnabledAfter(targetSdkVersion=29 /* Android Q */) @@ -215,10 +220,14 @@ public final class LocaleData { * @return a compatible locale for the bug b/159514442 */ public static Locale getCompatibleLocaleForBug159514442(Locale locale) { - if (Locale.ROOT.equals(locale) && - // isChangeEnabled() always returns true in non-app process - !Compatibility.isChangeEnabled(USE_REAL_ROOT_LOCALE)) { - locale = LOCALE_EN_US_POSIX; + if (Locale.ROOT.equals(locale)) { + int targetSdkVersion = VMRuntime.getRuntime().getTargetSdkVersion(); + // Don't use Compatibility.isChangeEnabled(USE_REAL_ROOT_LOCALE) because the app compat + // framework lives in libcore and can depend on this class via various format methods, + // e.g. String.format(). See b/160912695. + if (targetSdkVersion <= 29 /* Android Q */) { + locale = LOCALE_EN_US_POSIX; + } } return locale; } diff --git a/luni/src/test/java/libcore/libcore/icu/LocaleDataTest.java b/luni/src/test/java/libcore/libcore/icu/LocaleDataTest.java index 60572a0bc9..eace2333c9 100644 --- a/luni/src/test/java/libcore/libcore/icu/LocaleDataTest.java +++ b/luni/src/test/java/libcore/libcore/icu/LocaleDataTest.java @@ -32,7 +32,7 @@ import java.util.Locale; import java.util.TimeZone; import libcore.icu.LocaleData; -import libcore.junit.util.compat.CoreCompatChangeRule; +import libcore.junit.util.SwitchTargetSdkVersionRule; import org.junit.Rule; import org.junit.Test; @@ -44,7 +44,7 @@ import org.junit.runners.JUnit4; public class LocaleDataTest { @Rule - public TestRule compatChangeRule = new CoreCompatChangeRule(); + public TestRule switchTargetSdkVersionRule = SwitchTargetSdkVersionRule.getInstance(); @Test public void testAll() throws Exception { @@ -191,7 +191,7 @@ public class LocaleDataTest { // Test for b/159514442 @Test - @CoreCompatChangeRule.EnableCompatChanges({LocaleData.USE_REAL_ROOT_LOCALE}) + @SwitchTargetSdkVersionRule.TargetSdkVersion(30) public void test_rootLocale_useRealRootLocaleData() { assertRootDataEqualsToTargetLocaleData(Locale.ROOT); @@ -203,7 +203,7 @@ public class LocaleDataTest { // Test for b/159514442 @Test - @CoreCompatChangeRule.DisableCompatChanges({LocaleData.USE_REAL_ROOT_LOCALE}) + @SwitchTargetSdkVersionRule.TargetSdkVersion(29) public void test_rootLocale_notUseRealRootLocaleData() { Locale LOCALE_EN_US_POSIX = new Locale("en", "US", "POSIX"); assertRootDataEqualsToTargetLocaleData(LOCALE_EN_US_POSIX); |