Revision: 6609 Author: r...@google.com Date: Tue Nov 3 10:42:54 2009 Log: Avoid calling overridable methods from constructors to avoid subclassing glitches (see external issue 4177).
Review by: scottb http://code.google.com/p/google-web-toolkit/source/detail?r=6609 Modified: /trunk/user/super/com/google/gwt/emul/java/util/ArrayList.java ======================================= --- /trunk/user/super/com/google/gwt/emul/java/util/ArrayList.java Fri Oct 9 15:22:16 2009 +++ /trunk/user/super/com/google/gwt/emul/java/util/ArrayList.java Tue Nov 3 10:42:54 2009 @@ -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; - } -} +} --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---