ICU-6361 Fix the MessageFormat behavior problem with null arguments.

X-SVN-Rev: 24731
This commit is contained in:
Yoshito Umaoka 2008-10-07 04:19:35 +00:00
parent 6e33806beb
commit 82807260fe
2 changed files with 22 additions and 1 deletions

View file

@ -1312,6 +1312,27 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk {
}
}
// Test case for null arguments.
// Ticket#6361
public void TestNullArgs() {
MessageFormat msgfmt = new MessageFormat("{0} - {1}");
Object[][] TEST_CASES = {
{null, "{0} - {1}"},
{new Object[] {null}, "null - {1}"},
{new Object[] {null, null}, "null - null"},
{new Object[] {"one"}, "one - {1}"},
{new Object[] {"one", null}, "one - null"},
{new Object[] {null, "two"}, "null - two"},
};
for (int i = 0; i < TEST_CASES.length; i++) {
String text = msgfmt.format(TEST_CASES[i][0]);
if (!text.equals(TEST_CASES[i][1])) {
errln("FAIL: Returned[" + text + "] Expected[" + TEST_CASES[i][1] + "]");
}
}
}
//#if defined(FOUNDATION10) || defined(J2SE13)
//#else
// Test case for formatToCharacterIterator

View file

@ -1664,7 +1664,7 @@ public class MessageFormat extends UFormat {
result.append(pattern.substring(lastOffset, offsets[i]));
lastOffset = offsets[i];
String argumentName = argumentNames[i];
if (arguments == null || arguments.get(argumentName) == null) {
if (arguments == null || !arguments.containsKey(argumentName)) {
result.append("{" + argumentName + "}");
continue;
}