diff --git a/icu4c/source/i18n/alphaindex.cpp b/icu4c/source/i18n/alphaindex.cpp index 2f6255c7142..fadc2f42a62 100644 --- a/icu4c/source/i18n/alphaindex.cpp +++ b/icu4c/source/i18n/alphaindex.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 2009-2011, International Business Machines Corporation and * +* Copyright (C) 2009-2012, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -218,6 +218,13 @@ void AlphabeticIndex::buildIndex(UErrorCode &status) { } } + // If we have no labels, hard-code a fallback default set of [A-Z] + // This case can occur with locales that don't have exemplar character data, including root. + // A no-labels situation will cause other problems; it needs to be avoided. + if (labelSet.isEmpty()) { + labelSet.add((UChar32)0x41, (UChar32)0x5A); + } + // Move the set of Labels from the set into a vector, and sort // according to the collator. diff --git a/icu4c/source/test/intltest/alphaindextst.cpp b/icu4c/source/test/intltest/alphaindextst.cpp index eabfa4d6038..bc9286004df 100644 --- a/icu4c/source/test/intltest/alphaindextst.cpp +++ b/icu4c/source/test/intltest/alphaindextst.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2011, International Business Machines Corporation and + * Copyright (c) 2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ // @@ -43,6 +43,10 @@ void AlphabeticIndexTest::runIndexedTest( int32_t index, UBool exec, const char* if (exec) HackPinyinTest(); break; + case 3: name = "TestBug9009"; + if (exec) TestBug9009(); + break; + default: name = ""; break; //needed to end loop } @@ -416,4 +420,16 @@ void AlphabeticIndexTest::HackPinyinTest() { TEST_ASSERT(bucketCount > 25); TEST_ASSERT(filledBucketCount > 15); } + + +void AlphabeticIndexTest::TestBug9009() { + UErrorCode status = U_ZERO_ERROR; + Locale loc("root"); + AlphabeticIndex aindex(loc, status); + TEST_CHECK_STATUS; + aindex.nextBucket(status); // Crash here before bug was fixed. + TEST_CHECK_STATUS; +} + + #endif diff --git a/icu4c/source/test/intltest/alphaindextst.h b/icu4c/source/test/intltest/alphaindextst.h index a9c543641a7..8c8392dd287 100644 --- a/icu4c/source/test/intltest/alphaindextst.h +++ b/icu4c/source/test/intltest/alphaindextst.h @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2011, International Business Machines Corporation and + * Copyright (c) 2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ // @@ -23,6 +23,7 @@ public: virtual void APITest(); virtual void ManyLocalesTest(); virtual void HackPinyinTest(); + virtual void TestBug9009(); }; #endif