diff options
author | Bryce McKinlay <bryce@albatross.co.nz> | 2001-02-16 01:49:40 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2001-02-16 01:49:40 +0000 |
commit | 07add946aac1a64e5e94c2282eb3b3c033ce3867 (patch) | |
tree | a7928a2955317cb20bc8a9990d3f02b818efb59f /libjava | |
parent | 01a49191c183d87f0282c9f61c14bfbbe27c5adf (diff) | |
download | gcc-07add946aac1a64e5e94c2282eb3b3c033ce3867.zip gcc-07add946aac1a64e5e94c2282eb3b3c033ce3867.tar.gz gcc-07add946aac1a64e5e94c2282eb3b3c033ce3867.tar.bz2 |
TreeSet.java (clone): Made subclass safe, use super.clone(), not new.
* java/util/TreeSet.java (clone): Made subclass safe, use
super.clone(), not new.
* java/util/TreeMap.java (clone): Likewise.
From-SVN: r39734
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/java/util/TreeMap.java | 15 | ||||
-rw-r--r-- | libjava/java/util/TreeSet.java | 13 |
3 files changed, 28 insertions, 6 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 51557e0..63b9840 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,9 @@ +2001-02-16 Bryce McKinlay <bryce@albatross.co.nz> + + * java/util/TreeSet.java (clone): Made subclass safe, use + super.clone(), not new. + * java/util/TreeMap.java (clone): Likewise. + 2001-02-14 Andrew Haley <aph@redhat.com> * include/i386-signal.h (INIT_SEGV): Use a direct system call to diff --git a/libjava/java/util/TreeMap.java b/libjava/java/util/TreeMap.java index 5057d16..67ecebd 100644 --- a/libjava/java/util/TreeMap.java +++ b/libjava/java/util/TreeMap.java @@ -56,7 +56,7 @@ import java.io.IOException; * * @author Jon Zeppieri * @author Bryce McKinlay - * @modified $Id: TreeMap.java,v 1.1 2001/02/14 04:44:21 bryce Exp $ + * @modified $Id: TreeMap.java,v 1.2 2001/02/14 05:32:31 bryce Exp $ */ public class TreeMap extends AbstractMap implements SortedMap, Cloneable, Serializable @@ -178,8 +178,14 @@ public class TreeMap extends AbstractMap public Object clone() { - TreeMap copy = new TreeMap(); - copy.comparator = comparator; + TreeMap copy = null; + try + { + copy = (TreeMap) super.clone(); + } + catch (CloneNotSupportedException x) + { + } copy.fabricateTree(size); Node node = firstNode(); @@ -991,6 +997,9 @@ public class TreeMap extends AbstractMap parent.right = node; parent = nextparent; } + + // We use the "right" link to maintain a chain of nodes in + // each row until the parent->child links are established. if (last != null) last.right = node; last = node; diff --git a/libjava/java/util/TreeSet.java b/libjava/java/util/TreeSet.java index 070ca26..c6875b8 100644 --- a/libjava/java/util/TreeSet.java +++ b/libjava/java/util/TreeSet.java @@ -44,8 +44,8 @@ import java.io.ObjectOutputStream; * TreeSet is a part of the JDK1.2 Collections API. * * @author Jon Zeppieri - * @version $Revision: 1.1 $ - * @modified $Id: TreeSet.java,v 1.1 2001/02/14 04:44:21 bryce Exp $ + * @version $Revision: 1.2 $ + * @modified $Id: TreeSet.java,v 1.2 2001/02/15 03:59:57 bryce Exp $ */ public class TreeSet extends AbstractSet @@ -157,7 +157,14 @@ public class TreeSet extends AbstractSet /** Returns a shallow copy of this Set. */ public Object clone() { - TreeSet copy = new TreeSet(); + TreeSet copy = null; + try + { + copy = (TreeSet) super.clone(); + } + catch (CloneNotSupportedException x) + { + } copy.map = (SortedMap) ((TreeMap) map).clone(); return copy; } |