classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug: java/text/MessageFormat.java


From: Ito Kazumitsu
Subject: Bug: java/text/MessageFormat.java
Date: Wed, 16 Jun 2004 07:33:16 +0900
User-agent: EMH/1.10.0 SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) Emacs/21.2 (i386-unknown-freebsd4.7) MULE/5.0 (SAKAKI)

Hi,

As reported to the Kaffe mailing list:
http://www.kaffe.org/pipermail/kaffe/2004-June/046657.html
java/text/MessageFormat.java has a bug.

This is my suggested patch.

Changelog entry:
2004-06-15  Ito Kazumitsu  <address@hidden>

        * java/text/MessageFormat.java
        (formatInternal): Append "{n}" if argument n is unavailable.

--- java/text/MessageFormat.java.orig   Mon May 10 00:17:30 2004
+++ java/text/MessageFormat.java        Wed Jun 16 07:16:42 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,13 @@
 
     for (int i = 0; i < elements.length; ++i)
       {
-       if (elements[i].argNumber >= arguments.length)
-         throw new IllegalArgumentException("Not enough arguments given");
+       Object thisArg = null;
+       boolean unavailable = false;
+       if (arguments == null || elements[i].argNumber >= arguments.length)
+         unavailable = true;
+       else
+         thisArg = arguments[elements[i].argNumber];
 
-       Object thisArg = arguments[elements[i].argNumber];
        AttributedCharacterIterator iterator = null;
 
        Format formatter = null;
@@ -425,22 +428,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());




reply via email to

[Prev in Thread] Current Thread [Next in Thread]