PATCH: java.lang.StringBuffer

Warren Levy warrenl@cygnus.com
Fri Dec 8 05:07:00 GMT 2000


Here's another minor fix from the Mauve testsuite.  It gets rid of a
NullPointerException that's thrown in the case that offset is invalid AND
data is null (StringIndexOutOfBoundsException should be thrown).
--warrenl


2000-12-08  Warren Levy  <warrenl@redhat.com>

        * java/lang/StringBuffer.java (insert(int,char[])): Avoid
        NullPointerException so proper check of offset can be done.



Index: java/lang/StringBuffer.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/StringBuffer.java,v
retrieving revision 1.8
diff -u -p -r1.8 StringBuffer.java
--- StringBuffer.java   2000/05/19 17:55:32     1.8
+++ StringBuffer.java   2000/12/08 13:02:18
@@ -454,7 +454,9 @@ public final class StringBuffer implemen
    */
   public StringBuffer insert (int offset, char[] data)
   {
-    return insert (offset, data, 0, data.length);
+    // One could check if offset is invalid here instead of making sure that
+    // data isn't null before dereferencing, but this works just as well.
+    return insert (offset, data, 0, data == null ? 0 : data.length);
   }
 
   /** Insert the <code>char[]</code> argument into this






More information about the Java-patches mailing list