[kaffe] Bug: java/text/MessageFormat.java

Ito Kazumitsu ito.kazumitsu at mail.hidec.co.jp
Mon Jun 14 23:59:02 PDT 2004


Hi,

While testing an example that comes with VelocityStruts
(http://jakarta.apache.org/velocity/tools/index.html),
I found the following bug.

What the API document says:

  An argument is unavailable if arguments is null or has
  fewer than argumentIndex+1 elements.


    Subformat   Argument      Formatted Text

    any         unavailable   "{" + argumentIndex + "}"

What java/text/MessageFormat.java does:

    if (elements[i].argNumber >= arguments.length)
      throw new IllegalArgumentException("Not enough arguments given");

And here is my patch.  I am afraid this patch is not strictly correct
but I think it is better than nothing.

--- java/text/MessageFormat.java.orig	Tue Mar 23 06:34:32 2004
+++ java/text/MessageFormat.java	Tue Jun 15 15:31:11 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,11 @@
 
     for (int i = 0; i < elements.length; ++i)
       {
+	Object thisArg = null;
 	if (elements[i].argNumber >= arguments.length)
-	  throw new IllegalArgumentException("Not enough arguments given");
-
-	Object thisArg = arguments[elements[i].argNumber];
+	  thisArg = "{" + elements[i].argNumber + "}";
+	else
+	  thisArg = arguments[elements[i].argNumber];
 	AttributedCharacterIterator iterator = null;
 
 	Format formatter = null;




More information about the kaffe mailing list