--- old/src/java.base/share/classes/java/util/Hashtable.java 2015-05-01 10:10:39.000000000 -0700 +++ new/src/java.base/share/classes/java/util/Hashtable.java 2015-05-01 10:10:38.000000000 -0700 @@ -230,6 +230,14 @@ } /** + * A constructor chained from {@link Properties} keeps Hashtable fields + * uninitialized since they are not used. + * + * @param dummy a dummy parameter + */ + Hashtable(Void dummy) {} + + /** * Returns the number of keys in this hashtable. * * @return the number of keys in this hashtable. @@ -549,18 +557,23 @@ * @return a clone of the hashtable */ public synchronized Object clone() { + Hashtable t = cloneHashtable(); + t.table = new Entry[table.length]; + for (int i = table.length ; i-- > 0 ; ) { + t.table[i] = (table[i] != null) + ? (Entry) table[i].clone() : null; + } + t.keySet = null; + t.entrySet = null; + t.values = null; + t.modCount = 0; + return t; + } + + /** Calls super.clone() */ + final Hashtable cloneHashtable() { try { - Hashtable t = (Hashtable)super.clone(); - t.table = new Entry[table.length]; - for (int i = table.length ; i-- > 0 ; ) { - t.table[i] = (table[i] != null) - ? (Entry) table[i].clone() : null; - } - t.keySet = null; - t.entrySet = null; - t.values = null; - t.modCount = 0; - return t; + return (Hashtable)super.clone(); } catch (CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw new InternalError(e); @@ -1189,6 +1202,11 @@ */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { + writeHashtable(s); + } + + void writeHashtable(java.io.ObjectOutputStream s) + throws IOException { Entry entryStack = null; synchronized (this) { @@ -1219,11 +1237,26 @@ } /** + * Write out the simulated threshold, loadfactor + * Called by Properties + */ + final void defaultWriteHashtable(java.io.ObjectOutputStream s, int length, + float loadFactor) throws IOException { + this.threshold = (int)Math.min(length * loadFactor, MAX_ARRAY_SIZE + 1); + this.loadFactor = loadFactor; + s.defaultWriteObject(); + } + + /** * Reconstitute the Hashtable from a stream (i.e., deserialize it). */ private void readObject(java.io.ObjectInputStream s) - throws IOException, ClassNotFoundException - { + throws IOException, ClassNotFoundException { + readHashtable(s); + } + + void readHashtable(java.io.ObjectInputStream s) + throws IOException, ClassNotFoundException { // Read in the threshold and loadFactor s.defaultReadObject();