Index: src/main/java/java/text/ChoiceFormat.java =================================================================== --- src/main/java/java/text/ChoiceFormat.java (revision 650052) +++ src/main/java/java/text/ChoiceFormat.java (working copy) @@ -132,7 +132,7 @@ } buffer.setLength(0); position.setIndex(index); - upTo(template, position, buffer, '|'); + parseFormat(template, position, buffer, '|'); index = position.getIndex(); limits[limitCount++] = next; formats.add(buffer.toString()); @@ -139,6 +139,32 @@ } } + private boolean parseFormat(String string, ParsePosition position, + StringBuffer buffer, char stop) { + int index = position.getIndex(), length = string.length(); + boolean lastQuote = false, quote = false; + while (index < length) { + char ch = string.charAt(index++); + if (ch == '\'') { + if (lastQuote) { + buffer.append('\''); + } + quote = !quote; + lastQuote = true; + } else if (ch == stop && !quote) { + position.setIndex(index); + return true; + } else { + lastQuote = false; + if ((ch == '#' || ch == '\u2264' || ch == '<') && !quote) + throw new IllegalArgumentException(); + buffer.append(ch); + } + } + position.setIndex(index); + return false; + } + /** * Answers a new instance of ChoiceFormat with the same ranges and strings * as this ChoiceFormat. @@ -397,7 +423,10 @@ buffer.append(limit); buffer.append('#'); } - boolean quote = (choiceFormats[i].indexOf('|') != -1); + boolean quote = (choiceFormats[i].indexOf('|') != -1) || + (choiceFormats[i].indexOf('#') != -1) || + (choiceFormats[i].indexOf('\u2264') != -1) || + (choiceFormats[i].indexOf('<') != -1); if (quote) { buffer.append('\''); } Index: src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java =================================================================== --- src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java (revision 650052) +++ src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java (working copy) @@ -432,6 +432,31 @@ ptrn = cf.toPattern(); assertEquals("Return value should be empty string for invalid pattern", 0, ptrn.length()); + // Regression for HARMONY-1110 + try { + cf = new ChoiceFormat("2#ok a#ab"); + fail("Should throw IllegalArgumentException"); + } catch(IllegalArgumentException e) { + // expected + } + try { + cf = new ChoiceFormat("2#ok a