Avoid calling overridable methods from constructors to avoid subclassing glitches (see external issue 4177). Review by: scottb git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6609 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/super/com/google/gwt/emul/java/util/ArrayList.java b/user/super/com/google/gwt/emul/java/util/ArrayList.java index 52a57ed..418d953 100644 --- a/user/super/com/google/gwt/emul/java/util/ArrayList.java +++ b/user/super/com/google/gwt/emul/java/util/ArrayList.java
@@ -61,7 +61,7 @@ /** * This field holds a JavaScript array. */ - private transient E[] array; + private transient E[] array = (E[]) new Object[0]; /** * Ensures that RPC will consider type parameter E to be exposed. It will be @@ -73,22 +73,21 @@ /** * The size of the array. */ - private int size; - - { - clearImpl(); - } + private int size = 0; public ArrayList() { } - + public ArrayList(Collection<? extends E> c) { - addAll(c); + // Avoid calling overridable methods from constructors + spliceArray(array, 0, 0, c.toArray()); + size = c.size(); } public ArrayList(int initialCapacity) { + // Avoid calling overridable methods from constructors assert (initialCapacity >= 0); - ensureCapacity(initialCapacity); + setCapacity(array, initialCapacity); } @Override @@ -130,7 +129,8 @@ @Override public void clear() { - clearImpl(); + array = (E[]) new Object[0]; + size = 0; } public Object clone() { @@ -275,10 +275,4 @@ setCapacity(array, newSize); size = newSize; } - - @SuppressWarnings("unchecked") - private void clearImpl() { - array = (E[]) new Object[0]; - size = 0; - } }