Details
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)
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".