classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] Patch: FYI: bug 9949


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: bug 9949
Date: 16 Aug 2004 20:50:38 -0600
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

I'm checking this in.

This fixes bug 9949.  In that bug we used a field before initializing
it.  This changes the code to use an ArrayList and only convert to an
array at the end of the constructor.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>
        Bug 9949.
        * java/text/AttributedString.java (AttributedString): Use
        ArrayList to build array of attribute ranges.  Don't use
        `attribs' before it is set.

Index: java/text/AttributedString.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/AttributedString.java,v
retrieving revision 1.8
diff -u -r1.8 AttributedString.java
--- java/text/AttributedString.java 29 Apr 2004 15:47:26 -0000 1.8
+++ java/text/AttributedString.java 17 Aug 2004 03:06:29 -0000
@@ -39,6 +39,7 @@
 package java.text;
 
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -224,6 +225,7 @@
   // Loop through and extract the attributes
   char c = aci.setIndex(begin_index);
 
+  ArrayList accum = new ArrayList();
   do
     { 
       sb.append(c);
@@ -272,17 +274,17 @@
           Map new_map = new Hashtable();
           new_map.put(attrib, attrib_obj);
 
-          // Add it to the attribute list.  Yes this is a bad way to do things.
-          AttributeRange[] new_list = new AttributeRange[attribs.length + 1];
-          System.arraycopy(attribs, 0, new_list, 0, attribs.length);
-          attribs = new_list;
-          attribs[attribs.length - 1] = new AttributeRange(new_map, rs, rl);
+          // Add it to the attribute list.
+         accum.add(new AttributeRange(new_map, rs, rl));
         }
 
       c = aci.next();
     }
   while(c != CharacterIterator.DONE);
 
+  attribs = new AttributeRange[accum.size()];
+  attribs = (AttributeRange[]) accum.toArray(attribs);
+
   sci = new StringCharacterIterator(sb.toString());
 }
 




reply via email to

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