From 49e3b372ab288992a4705dfe7f37fbd732d06aed Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 16 Jun 2011 02:25:35 -0700 Subject: Fix crash determining direction of invalid locale The layoutlib is used in the SDK which might not have a default Locale, so the language string will be some kind of junk. This causes a crash in the new LocaleUtils Change-Id: I24e5115c56e39d394dcf89ec6cff609525b3c73e --- core/java/android/util/LocaleUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/util/LocaleUtil.java b/core/java/android/util/LocaleUtil.java index 4511d94..e767a85 100644 --- a/core/java/android/util/LocaleUtil.java +++ b/core/java/android/util/LocaleUtil.java @@ -71,8 +71,9 @@ public class LocaleUtil { if (localeWithSubtags == null) return getLayoutDirectionFromFirstChar(locale); // Need to check if we can extract the script subtag. For example, "Latn" in "en_Latn_US" - if (localeWithSubtags.charAt(2) != UNDERSCORE_CHAR || - localeWithSubtags.charAt(7) != UNDERSCORE_CHAR) { + if (localeWithSubtags.length() <= 7 + || localeWithSubtags.charAt(2) != UNDERSCORE_CHAR + || localeWithSubtags.charAt(7) != UNDERSCORE_CHAR) { return getLayoutDirectionFromFirstChar(locale); } // Extract the script subtag -- cgit v1.1