Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4252490

TreeMap will return non-null firstKey for an empty submap

    XMLWordPrintable

Details

    • kestrel
    • generic, sparc
    • generic, solaris_2.5.1

    Description



      Name: clC74495 Date: 07/08/99


      Create an empty submap of a TreeMap, whose interval is specified in
      such a way as to be of size 0. Send firstKey() to it. Instead of
      throwing NoSuchElementException, it will return the first key, as
      illustrated by the following test case.

            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));
            m.put(new Integer(4), new Integer(4));
            SortedMap m2 = m.subMap(new Integer(4), new Integer(4));
            System.out.println("m2's size is " + m2.size());
            Object k = m2.firstKey();
            System.out.println("k = " + k);
      (Review ID: 85300)
      ======================================================================

      Attachments

        Activity

          People

            jjb Josh Bloch
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: