* @param where A locale specifying the language of the text to be
* analyzed.
* @return An instance of BreakIterator that locates word boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 2.0
*/
public static BreakIterator getWordInstance(Locale where)
* @param where A locale specifying the language of the text to be
* analyzed.
* @return An instance of BreakIterator that locates word boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 3.2
*/
public static BreakIterator getWordInstance(ULocale where)
* @param where A Locale specifying the language of the text being broken.
* @return A new instance of BreakIterator that locates legal
* line-wrapping positions.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 2.0
*/
public static BreakIterator getLineInstance(Locale where)
* @param where A Locale specifying the language of the text being broken.
* @return A new instance of BreakIterator that locates legal
* line-wrapping positions.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 3.2
*/
public static BreakIterator getLineInstance(ULocale where)
* @param where A Locale specifying the language of the text being analyzed.
* @return A new instance of BreakIterator that locates logical-character
* boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 2.0
*/
public static BreakIterator getCharacterInstance(Locale where)
* @param where A Locale specifying the language of the text being analyzed.
* @return A new instance of BreakIterator that locates logical-character
* boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 3.2
*/
public static BreakIterator getCharacterInstance(ULocale where)
* Returns a new instance of BreakIterator that locates sentence boundaries.
* @param where A Locale specifying the language of the text being analyzed.
* @return A new instance of BreakIterator that locates sentence boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 2.0
*/
public static BreakIterator getSentenceInstance(Locale where)
* {@icu} Returns a new instance of BreakIterator that locates sentence boundaries.
* @param where A Locale specifying the language of the text being analyzed.
* @return A new instance of BreakIterator that locates sentence boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 3.2
*/
public static BreakIterator getSentenceInstance(ULocale where)
* please use Word Boundary iterator.{@link #getWordInstance}
* @param where A Locale specifying the language of the text being analyzed.
* @return A new instance of BreakIterator that locates title boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 2.0
*/
public static BreakIterator getTitleInstance(Locale where)
* please use Word Boundary iterator.{@link #getWordInstance}
* @param where A Locale specifying the language of the text being analyzed.
* @return A new instance of BreakIterator that locates title boundaries.
+ * @throws NullPointerException if <code>where</code> is null.
* @stable ICU 3.2
s */
public static BreakIterator getTitleInstance(ULocale where)
*/
@Deprecated
public static BreakIterator getBreakInstance(ULocale where, int kind) {
-
+ if (where == null) {
+ throw new NullPointerException("Specified locale is null");
+ }
if (iterCache[kind] != null) {
BreakIteratorCache cache = (BreakIteratorCache)iterCache[kind].get();
if (cache != null) {
/*
*******************************************************************************
- * Copyright (C) 1996-2012, International Business Machines Corporation and *
+ * Copyright (C) 1996-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.text.BreakIterator;
+import com.ibm.icu.util.ULocale;
public class BreakIteratorTest extends TestFmwk
{
errln("ERR: Failed to create an instance type: " + type + " / locale: " + loc + " / exception: " + e.getMessage());
}
}
+
+ /*
+ * Test case for Ticket#10721. BreakIterator factory method should throw NPE
+ * when specified locale is null.
+ */
+ public void TestNullLocale() {
+ Locale loc = null;
+ ULocale uloc = null;
+
+ @SuppressWarnings("unused")
+ BreakIterator brk;
+
+ // Character
+ try {
+ brk = BreakIterator.getCharacterInstance(loc);
+ errln("getCharacterInstance((Locale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+ try {
+ brk = BreakIterator.getCharacterInstance(uloc);
+ errln("getCharacterInstance((ULocale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+
+ // Line
+ try {
+ brk = BreakIterator.getLineInstance(loc);
+ errln("getLineInstance((Locale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+ try {
+ brk = BreakIterator.getLineInstance(uloc);
+ errln("getLineInstance((ULocale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+
+ // Sentence
+ try {
+ brk = BreakIterator.getSentenceInstance(loc);
+ errln("getSentenceInstance((Locale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+ try {
+ brk = BreakIterator.getSentenceInstance(uloc);
+ errln("getSentenceInstance((ULocale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+
+ // Title
+ try {
+ brk = BreakIterator.getTitleInstance(loc);
+ errln("getTitleInstance((Locale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+ try {
+ brk = BreakIterator.getTitleInstance(uloc);
+ errln("getTitleInstance((ULocale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+
+ // Word
+ try {
+ brk = BreakIterator.getWordInstance(loc);
+ errln("getWordInstance((Locale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+ try {
+ brk = BreakIterator.getWordInstance(uloc);
+ errln("getWordInstance((ULocale)null) did not throw NPE.");
+ } catch (NullPointerException e) { /* OK */ }
+ }
}