[kaffe] Bug: java/text/MessageFormat.java
Ito Kazumitsu
ito.kazumitsu at mail.hidec.co.jp
Tue Jun 15 01:01:02 PDT 2004
In message "[kaffe] Bug: java/text/MessageFormat.java"
on 04/06/15, Ito Kazumitsu <ito.kazumitsu at mail.hidec.co.jp> writes:
> And here is my patch. I am afraid this patch is not strictly correct
> but I think it is better than nothing.
This must be better:
--- java/text/MessageFormat.java.orig Tue Mar 23 06:34:32 2004
+++ java/text/MessageFormat.java Tue Jun 15 16:44:23 2004
@@ -157,7 +157,7 @@
* This is the attribute set for all characters produced
* by MessageFormat during a formatting.
*/
- public static final MessageFormat.Field ARGUMENT = new Field("argument");
+ public static final MessageFormat.Field ARGUMENT = new MessageFormat.Field("argument");
// For deserialization
private Field()
@@ -414,10 +414,12 @@
for (int i = 0; i < elements.length; ++i)
{
+ Object thisArg = null;
+ boolean unavailable = false;
if (elements[i].argNumber >= arguments.length)
- throw new IllegalArgumentException("Not enough arguments given");
-
- Object thisArg = arguments[elements[i].argNumber];
+ unavailable = true;
+ else
+ thisArg = arguments[elements[i].argNumber];
AttributedCharacterIterator iterator = null;
Format formatter = null;
@@ -425,22 +427,27 @@
if (fp != null && i == fp.getField() && fp.getFieldAttribute() == Field.ARGUMENT)
fp.setBeginIndex(appendBuf.length());
- if (elements[i].setFormat != null)
- formatter = elements[i].setFormat;
- else if (elements[i].format != null)
+ if (unavailable)
+ appendBuf.append("{" + elements[i].argNumber + "}");
+ else
{
- if (elements[i].formatClass != null
- && ! elements[i].formatClass.isInstance(thisArg))
- throw new IllegalArgumentException("Wrong format class");
+ if (elements[i].setFormat != null)
+ formatter = elements[i].setFormat;
+ else if (elements[i].format != null)
+ {
+ if (elements[i].formatClass != null
+ && ! elements[i].formatClass.isInstance(thisArg))
+ throw new IllegalArgumentException("Wrong format class");
- formatter = elements[i].format;
+ formatter = elements[i].format;
+ }
+ else if (thisArg instanceof Number)
+ formatter = NumberFormat.getInstance(locale);
+ else if (thisArg instanceof Date)
+ formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
+ else
+ appendBuf.append(thisArg);
}
- else if (thisArg instanceof Number)
- formatter = NumberFormat.getInstance(locale);
- else if (thisArg instanceof Date)
- formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
- else
- appendBuf.append(thisArg);
if (fp != null && fp.getField() == i && fp.getFieldAttribute() == Field.ARGUMENT)
fp.setEndIndex(appendBuf.length());
More information about the kaffe
mailing list