Reviewers: rchandia,

Description:
Fix a possible null pointer dereference

Review by: rchan...@google.com

Please review this at http://gwt-code-reviews.appspot.com/330802/show

Affected files:
  M bikeshed/src/com/google/gwt/collections/MutableArray.java


Index: bikeshed/src/com/google/gwt/collections/MutableArray.java
===================================================================
--- bikeshed/src/com/google/gwt/collections/MutableArray.java (revision 7903)
+++ bikeshed/src/com/google/gwt/collections/MutableArray.java   (working copy)
@@ -1,12 +1,12 @@
 /*
  * Copyright 2009 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,7 +17,7 @@

 /**
  * An array whose content and length can change over time.
- *
+ *
  * @param <E> The type stored in the array elements
  */
 public class MutableArray<E> extends Array<E> {
@@ -44,11 +44,11 @@
     Assertions.assertNotFrozen(this);
     elems = null;
   }
-
+
   /**
- * Creates an immutable array based on this one. Also marks this object as read-only. - * After calling {...@code freeze()}, only use methods from {...@link Array} or the returned
-   * {...@link ImmutableArray} should be to access the elements
+ * Creates an immutable array based on this one. Also marks this object as read-only. + * After calling {...@code freeze()}, only use methods from {...@link Array} or the returned
+   * {...@link ImmutableArray} should be to access the elements
    * of the array is preferred.
    */
   public ImmutableArray<E> freeze() {
@@ -60,7 +60,7 @@
     } else {
       r = ImmutableArray.getEmptyInstance();
     }
-
+
     return r;
   }

@@ -77,7 +77,7 @@

   /**
    * Inserts {...@code element} before the element residing at {...@code 
index}.
-   *
+   *
* @param index in the range [0, this.size()], inclusive; if index is equal * to the array's current size, the result is equivalent to calling
    *          {...@link #add(Object)}
@@ -118,7 +118,7 @@
       System.arraycopy(elems, 0, newElems, 0, index);
System.arraycopy(elems, index + 1, newElems, index, oldLen - index - 1);
       elems = newElems;
-    } else if (elems.length == 1) {
+    } else if (elems != null && elems.length == 1) {
       elems = null;
     } else {
assert false : "index " + index + " in range [0, " + size() + "), but remove(int) failed";
@@ -127,7 +127,7 @@

   /**
    * Replaces the element at the specified index.
-   *
+   *
    * @param index in the range [0, this.size()), exclusive
    * @param elem the element to insert or {...@code null}
    */


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

To unsubscribe, reply using "remove me" as the subject.

Reply via email to