Initial load
diff --git a/test/java/util/TreeMap/ContainsValue.java b/test/java/util/TreeMap/ContainsValue.java
new file mode 100644
index 0000000..888ffc3
--- /dev/null
+++ b/test/java/util/TreeMap/ContainsValue.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4212425
+ * @summary TreeMap.containsValue throws NullPointerExc for empty TreeMap
+ */
+
+import java.util.*;
+
+public class ContainsValue {
+    static public void main (String[] args) {
+        Map map = new TreeMap();
+
+        if (map.containsValue ("gemutlichkeit"))
+            throw new RuntimeException("containsValue optimistic (non-null)");
+
+        if (map.containsValue (null))
+            throw new RuntimeException("containsValue optimistic (null)");
+
+        map.put("a", null);
+        map.put("b", "gemutlichkeit");
+
+        if (!map.containsValue ("gemutlichkeit"))
+            throw new RuntimeException("containsValue pessimistic (non-null)");
+
+        if (!map.containsValue (null))
+            throw new RuntimeException("containsValue pessimistic (null)");
+    }
+}
diff --git a/test/java/util/TreeMap/HeadTailTypeError.java b/test/java/util/TreeMap/HeadTailTypeError.java
new file mode 100644
index 0000000..7d67e48
--- /dev/null
+++ b/test/java/util/TreeMap/HeadTailTypeError.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+   @test
+   @bug 4251519 4251520
+   @summary indexOf and lastIndex of used to let you look outside the
+            valid range in the backing array
+ */
+
+import java.util.*;
+
+public class HeadTailTypeError {
+    public static void main(String argv[]) throws Exception {
+        try{
+            SortedMap m = new TreeMap();
+            m.headMap(new Object());
+            throw new Exception("headMap, natural ordering");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedMap m = new TreeMap();
+            m.tailMap(new Object());
+            throw new Exception("tailMap, natural ordering");
+        } catch (ClassCastException e) {
+        }
+
+
+        try{
+            SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+            m.headMap(new Integer(0));
+            throw new Exception("headMap, explicit comparator");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+            m.tailMap(new Integer(0));
+            throw new Exception("tailMap, explicit comparator");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet();
+            m.headSet(new Object());
+            throw new Exception("headSet, natural ordering");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet();
+            m.tailSet(new Object());
+            throw new Exception("tailSet, natural ordering");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+            m.headSet(new Integer(0));
+            throw new Exception("headSet, explicit comparator");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+            m.tailSet(new Integer(0));
+            throw new Exception("tailSet, explicit comparator");
+        } catch (ClassCastException e) {
+        }
+
+        try{
+            SortedMap m = new TreeMap();
+            m.headMap(null);
+            throw new Exception("(null endpoint)headMap, natural ordering");
+        } catch (NullPointerException e) {
+        }
+
+        try{
+            SortedMap m = new TreeMap();
+            m.tailMap(null);
+            throw new Exception("(null endpoint)tailMap, natural ordering");
+        } catch (NullPointerException e) {
+        }
+
+
+        try{
+            SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+            m.headMap(null);
+            throw new Exception("(null endpoint)headMap, explicit comparator");
+        } catch (NullPointerException e) {
+        }
+
+        try{
+            SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+            m.tailMap(null);
+            throw new Exception("(null endpoint)tailMap, explicit comparator");
+        } catch (NullPointerException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet();
+            m.headSet(null);
+            throw new Exception("(null endpoint)headSet, natural ordering");
+        } catch (NullPointerException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet();
+            m.tailSet(null);
+            throw new Exception("(null endpoint)tailSet, natural ordering");
+        } catch (NullPointerException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+            m.headSet(null);
+            throw new Exception("(null endpoint)headSet, explicit comparator");
+        } catch (NullPointerException e) {
+        }
+
+        try{
+            SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+            m.tailSet(null);
+            throw new Exception("(null endpoint)tailSet, explicit comparator");
+        } catch (NullPointerException e) {
+        }
+
+        // These should not fail
+        SortedMap m = new TreeMap();
+        m.headMap(new Integer(0));
+        m.tailMap(new Integer(0));
+        m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+        m.headMap("llama");
+        m.tailMap("llama");
+
+        SortedSet s = new TreeSet();
+        s.headSet(new Integer(0));
+        s.tailSet(new Integer(0));
+        s = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+        s.headSet("drama");
+        s.tailSet("drama");
+    }
+}
diff --git a/test/java/util/TreeMap/NullAtEnd.java b/test/java/util/TreeMap/NullAtEnd.java
new file mode 100644
index 0000000..83c4d5a
--- /dev/null
+++ b/test/java/util/TreeMap/NullAtEnd.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     5018254
+ * @summary Test null-allowing Comparators
+ * @author  Martin Buchholz
+ */
+
+import java.util.*;
+import java.util.concurrent.*;
+
+public class NullAtEnd {
+    static volatile int passed = 0, failed = 0;
+
+    static void fail(String msg) {
+        failed++;
+        new AssertionError(msg).printStackTrace();
+    }
+
+    static void pass() {
+        passed++;
+    }
+
+    static void unexpected(Throwable t) {
+        failed++;
+        t.printStackTrace();
+    }
+
+    static void check(boolean condition, String msg) {
+        if (condition)
+            passed++;
+        else
+            fail(msg);
+    }
+
+    static void check(boolean condition) {
+        check(condition, "Assertion failure");
+    }
+
+    private static boolean eq(Object x, Object y) {
+        return x == null ? y == null : x.equals(y);
+    }
+
+    private static final Comparator<String> NULL_AT_END
+        = new Comparator<String>() {
+            /**
+             * Allows for nulls.  Null is greater than anything non-null.
+             */
+            public int compare(String x, String y) {
+                if (x == null && y == null) return 0;
+                if (x == null && y != null) return 1;
+                if (x != null && y == null) return -1;
+                return x.compareTo(y);
+            }
+        };
+
+    public static void main(String[] args) {
+        try {
+            SortedMap<String,String> m1
+                = new TreeMap<String,String>(NULL_AT_END);
+            check(eq(m1.put("a", "a"), null));
+            check(eq(m1.put("b", "b"), null));
+            check(eq(m1.put("c", "c"), null));
+            check(eq(m1.put(null, "d"), null));
+
+            SortedMap<String,String> m2 = new TreeMap<String,String>(m1);
+
+            check(eq(m1.lastKey(), null));
+            check(eq(m1.get(m1.lastKey()), "d"));
+            check(eq(m1.remove(m1.lastKey()), "d"));
+            check(eq(m1.lastKey(), "c"));
+
+            check(eq(m2.entrySet().toString(), "[a=a, b=b, c=c, null=d]"));
+
+            SortedMap<String,String> m3 = m2.tailMap("b");
+
+            check(eq(m3.lastKey(), null));
+            check(eq(m3.get(m3.lastKey()), "d"));
+            check(eq(m3.remove(m3.lastKey()), "d"));
+            check(eq(m3.lastKey(), "c"));
+
+        } catch (Throwable t) { unexpected(t); }
+
+        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+        if (failed > 0) throw new Error("Some tests failed");
+    }
+}
diff --git a/test/java/util/TreeMap/NullPermissiveComparator.java b/test/java/util/TreeMap/NullPermissiveComparator.java
new file mode 100644
index 0000000..2338499
--- /dev/null
+++ b/test/java/util/TreeMap/NullPermissiveComparator.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6467933
+ * @summary Test proper handling of comparators permitting nulls
+ * @author Martin Buchholz
+ */
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+import java.lang.reflect.*;
+
+@SuppressWarnings("unchecked")
+public class NullPermissiveComparator {
+
+    static void equal(Map m, String s) {
+        equal(m.toString(), s);
+    }
+
+    static void realMain(String[] args) throws Throwable {
+        final Comparator nullLow = new Comparator() {
+                public int compare(Object x, Object y) {
+                    return x == y ?  0 :
+                        x == null ? -1 :
+                        y == null ?  1 :
+                        ((Comparable)x).compareTo(y); }};
+
+        final Comparator nullHigh = new Comparator() {
+                public int compare(Object x, Object y) {
+                    return x == y ?  0 :
+                        x == null ?  1 :
+                        y == null ? -1 :
+                        ((Comparable)x).compareTo(y); }};
+
+        TreeMap m = new TreeMap(nullLow);
+
+        m.put("a", "A");
+        m.put("b", "B");
+        m.put("c", "C");
+
+        equal(m, "{a=A, b=B, c=C}");
+        equal(m.headMap("b"), "{a=A}");
+        equal(m.tailMap("b"), "{b=B, c=C}");
+        equal(m.headMap(null), "{}");
+        equal(m.tailMap(null), "{a=A, b=B, c=C}");
+
+        m.put(null, "NULL");
+
+        equal(m, "{null=NULL, a=A, b=B, c=C}");
+        equal(m.headMap("b"), "{null=NULL, a=A}");
+        equal(m.tailMap("b"), "{b=B, c=C}");
+        equal(m.headMap(null), "{}");
+        equal(m.tailMap(null), "{null=NULL, a=A, b=B, c=C}");
+
+        m = new TreeMap(nullHigh);
+
+        m.put("a", "A");
+        m.put("b", "B");
+        m.put("c", "C");
+
+        equal(m, "{a=A, b=B, c=C}");
+        equal(m.headMap("b"), "{a=A}");
+        equal(m.tailMap("b"), "{b=B, c=C}");
+        equal(m.headMap(null), "{a=A, b=B, c=C}");
+        equal(m.tailMap(null), "{}");
+
+        m.put(null, "NULL");
+
+        equal(m, "{a=A, b=B, c=C, null=NULL}");
+        equal(m.headMap("b"), "{a=A}");
+        equal(m.tailMap("b"), "{b=B, c=C, null=NULL}");
+        equal(m.headMap(null), "{a=A, b=B, c=C}");
+        equal(m.tailMap(null), "{null=NULL}");
+    }
+
+    //--------------------- Infrastructure ---------------------------
+    static volatile int passed = 0, failed = 0;
+    static void pass() {passed++;}
+    static void fail() {failed++; Thread.dumpStack();}
+    static void fail(String msg) {System.out.println(msg); fail();}
+    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
+    static void check(boolean cond) {if (cond) pass(); else fail();}
+    static void equal(Object x, Object y) {
+        if (x == null ? y == null : x.equals(y)) pass();
+        else fail(x + " not equal to " + y);}
+    public static void main(String[] args) throws Throwable {
+        try {realMain(args);} catch (Throwable t) {unexpected(t);}
+        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+        if (failed > 0) throw new AssertionError("Some tests failed");}
+}
diff --git a/test/java/util/TreeMap/SubMap.java b/test/java/util/TreeMap/SubMap.java
new file mode 100644
index 0000000..79c4b60
--- /dev/null
+++ b/test/java/util/TreeMap/SubMap.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4252490
+ * @summary The firstKey and lastKey
+ */
+
+import java.util.*;
+
+public class SubMap {
+    public static void main(String args[]) throws Exception {
+        SortedMap m = new TreeMap();
+        m.put(new Integer(1), new Integer(1));
+        m.put(new Integer(2), new Integer(2));
+        m.put(new Integer(3), new Integer(3));
+        SortedMap m2 = m.subMap(new Integer(2), new Integer(2));
+
+        boolean exc = false;
+        try {
+            m2.firstKey();
+        } catch(NoSuchElementException e) {
+            exc = true;
+        }
+        if (!exc)
+            throw new Exception("first key");
+
+        exc = false;
+        try {
+            m2.lastKey();
+        } catch(NoSuchElementException e) {
+            exc = true;
+        }
+        if (!exc)
+            throw new Exception("last key");
+
+        SortedMap m3 = m.subMap(new Integer(2), new Integer(3));
+        if (!m3.firstKey().equals(new Integer(2)))
+            throw new Exception("first key wrong");
+        if (!m3.lastKey().equals(new Integer(2)))
+            throw new Exception("last key wrong");
+
+        SortedSet s = new TreeSet();
+        s.add(new Integer(1));
+        s.add(new Integer(2));
+        s.add(new Integer(3));
+        SortedSet s2 = s.subSet(new Integer(2), new Integer(2));
+
+        exc = false;
+        try {
+            s2.first();
+        } catch(NoSuchElementException e) {
+            exc = true;
+        }
+        if (!exc)
+            throw new Exception("first element");
+
+        exc = false;
+        try {
+            s2.last();
+        } catch(NoSuchElementException e) {
+            exc = true;
+        }
+        if (!exc)
+            throw new Exception("last element");
+
+        SortedSet s3 = s.subSet(new Integer(2), new Integer(3));
+        if (!s3.first().equals(new Integer(2)))
+            throw new Exception("first element wrong");
+        if (!s3.last().equals(new Integer(2)))
+            throw new Exception("last element wrong");
+    }
+}
diff --git a/test/java/util/TreeMap/SubMapClear.java b/test/java/util/TreeMap/SubMapClear.java
new file mode 100644
index 0000000..4daf1a2
--- /dev/null
+++ b/test/java/util/TreeMap/SubMapClear.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     4468802
+ * @summary Submap clear tickled a bug in an optimization suggested by
+ *          Prof. William Collins (Lafayette College)
+ * @author  Josh Bloch
+ */
+
+import java.util.*;
+
+public class SubMapClear {
+    public static void main(String[] args) {
+        SortedSet treeSet = new TreeSet();
+        for (int i = 1; i <=10; i++)
+            treeSet.add(new Integer(i));
+        Set subSet = treeSet.subSet(new Integer(4),new Integer(10));
+        subSet.clear();  // Used to throw exception
+
+        int a[] = new int[] {1, 2, 3, 10};
+        Set s = new TreeSet();
+        for (int i = 0; i < a.length; i++)
+            s.add(new Integer(a[i]));
+        if (!treeSet.equals(s))
+            throw new RuntimeException(treeSet.toString());
+    }
+}