You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Yang Wang (Created) (JIRA)" <ji...@apache.org> on 2011/10/11 12:27:12 UTC
[jira] [Created] (HARMONY-6688) TreeMap returns wrong key in
lastKey function through interface SortedMap
TreeMap returns wrong key in lastKey function through interface SortedMap
-------------------------------------------------------------------------
Key: HARMONY-6688
URL: https://issues.apache.org/jira/browse/HARMONY-6688
Project: Harmony
Issue Type: Bug
Components: Classlib
Affects Versions: 5.0M15, 6.0M4
Environment: Platform independent
Reporter: Yang Wang
Fix For: 6.0M4, 5.0M16
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".
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (HARMONY-6688) TreeMap returns wrong key in
lastKey function through interface SortedMap
Posted by "Jesse Wilson (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6688?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13125538#comment-13125538 ]
Jesse Wilson commented on HARMONY-6688:
---------------------------------------
For what it's worth, this doesn't impact Android's rewritten TreeMap.
http://www.google.com/codesearch#cZwlSNS7aEw/libcore/luni/src/main/java/java/util/TreeMap.java
> TreeMap returns wrong key in lastKey function through interface SortedMap
> -------------------------------------------------------------------------
>
> Key: HARMONY-6688
> URL: https://issues.apache.org/jira/browse/HARMONY-6688
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Affects Versions: 6.0M4, 5.0M15
> Environment: Platform independent
> Reporter: Yang Wang
> Labels: TreeMap, lastKey
> Fix For: 6.0M4, 5.0M16
>
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> 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".
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira