ArrayList has no equivalent of Vector.setSize() which pads
a collection to a specified size.  MessageFormat was relying on this
behaviour to produce a sparsely-populated results array (filling
only the specified slots using set rather than appending to the end).
We emulate it by simply looping until the specified size is achieved
by adding null values to the end.

ChangeLog:

2008-12-31  Andrew John Hughes  <gnu_and...@member.fsf.org>

        * java/text/MessageFormat.java:
        (parse(String,ParsePosition)): Emulate behaviour
        of Vector's setSize() which was being implicitly relied on.
-- 
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8
Index: java/text/MessageFormat.java
===================================================================
RCS file: /sources/classpath/classpath/java/text/MessageFormat.java,v
retrieving revision 1.28
diff -u -u -r1.28 MessageFormat.java
--- java/text/MessageFormat.java        31 Dec 2008 08:27:25 -0000      1.28
+++ java/text/MessageFormat.java        31 Dec 2008 11:14:47 -0000
@@ -686,7 +686,12 @@
          }
 
        if (elements[i].argNumber >= results.size())
-         results.ensureCapacity(elements[i].argNumber + 1);
+         {
+           // Emulate padding behaviour of Vector.setSize() with ArrayList
+           results.ensureCapacity(elements[i].argNumber + 1);
+           for (int a = results.size(); a <= elements[i].argNumber; ++a)
+             results.add(a, null);
+         }
        results.set(elements[i].argNumber, value);
 
        index += elements[i].trailer.length();

Reply via email to