ICU-10721 Changed BreakIterator factory method to throw NPE always when specified locale is null. The API docs are also updated to clarify this. The spec is equivalent to JDK.
X-SVN-Rev: 35317
This commit is contained in:
parent
21e8bbce00
commit
e9bdf144db
@ -581,6 +581,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @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)
|
||||
@ -593,6 +594,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @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)
|
||||
@ -619,6 +621,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @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)
|
||||
@ -632,6 +635,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @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)
|
||||
@ -658,6 +662,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @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)
|
||||
@ -671,6 +676,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @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)
|
||||
@ -694,6 +700,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* 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)
|
||||
@ -705,6 +712,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* {@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)
|
||||
@ -733,6 +741,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* 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)
|
||||
@ -747,6 +756,7 @@ public abstract class BreakIterator implements Cloneable
|
||||
* 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)
|
||||
@ -837,7 +847,9 @@ s */
|
||||
*/
|
||||
@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) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2012, International Business Machines Corporation and *
|
||||
* Copyright (C) 1996-2014, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -13,6 +13,7 @@ import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.BreakIterator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class BreakIteratorTest extends TestFmwk
|
||||
{
|
||||
@ -843,4 +844,66 @@ 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 */ }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user