Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-6688

TreeMap returns wrong key in lastKey function through interface SortedMap

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 6.0M4, 5.0M15
    • 6.0M4, 5.0M16
    • Classlib
    • Platform independent
    • Moderate

    Description

      Problem
      =======
      TreeMap returns wrong key in lastKey function through interface SortedMap when the map size is 65 and submap size is 64.

      Test to reproduce the error
      ===================
      import java.util.*;

      public class Main {

      static TreeMap<Integer,Integer> map;

      static boolean test_passed = true;

      public static void test_lastKey() {
      SortedMap<Integer,Integer> s_map;

      for(int i=0; i<65; i++)
      map.put(i, i);

      s_map = map.subMap(0, 64);

      int last_key = s_map.lastKey();
      if (last_key != 63)

      { test_passed = false; System.out.println("Error occured for map size: " + 65 + " submap(0, " + 64 + ")"); }

      map.clear();
      }

      public static void main(String args[])

      { map = new TreeMap<Integer,Integer>(); System.out.println("test started!"); test_lastKey(); if (test_passed) System.out.println("test passed!"); }

      }

      Proposed fix
      ==========
      Search the string "foundIndex = foundNode.right_idx - 1" in TreeMap.java,
      and change it to "foundIndex = foundNode.right_idx".

      Attachments

        Activity

          People

            Unassigned Unassigned
            yang.wang Yang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified