Details
-
Bug
-
Resolution: Fixed
-
P3
-
6-pool, 7u25
-
b113
-
generic
-
Verified
Description
FULL PRODUCT VERSION :
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
A DESCRIPTION OF THE PROBLEM :
The implementation of 'remove' in PrivateEntryIterator in TreeMap.java does not work correctly when it is a descending iterator.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Put at least 3 elements into a TreeMap.
2. Get a descending iterator for a TreeMap's KeySet.
3. Iterate through the elements, and remove the second one.
The iterator position is now wrong. (See the test case below for source code.)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableMap;
import java.util.TreeMap;
public class TreeMapIteratorBug {
public static void main(String [] argv) throws Exception {
NavigableMap<String, Object> map = new TreeMap<String, Object>();
map.put("a", 1);
map.put("b", 1);
map.put("c", 1);
List<String> keys = new ArrayList<String>();
keys.addAll(map.descendingMap().keySet());
Iterator<String> iterator = map.navigableKeySet().descendingIterator();
for (int i = 0; i < 3; i++) {
String key = iterator.next();
if (!key.equals(keys.get(i))) {
throw new Exception("bug");
}
if (i == 1) {
iterator.remove();
}
}
}
}
---------- END SOURCE ----------
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
A DESCRIPTION OF THE PROBLEM :
The implementation of 'remove' in PrivateEntryIterator in TreeMap.java does not work correctly when it is a descending iterator.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Put at least 3 elements into a TreeMap.
2. Get a descending iterator for a TreeMap's KeySet.
3. Iterate through the elements, and remove the second one.
The iterator position is now wrong. (See the test case below for source code.)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableMap;
import java.util.TreeMap;
public class TreeMapIteratorBug {
public static void main(String [] argv) throws Exception {
NavigableMap<String, Object> map = new TreeMap<String, Object>();
map.put("a", 1);
map.put("b", 1);
map.put("c", 1);
List<String> keys = new ArrayList<String>();
keys.addAll(map.descendingMap().keySet());
Iterator<String> iterator = map.navigableKeySet().descendingIterator();
for (int i = 0; i < 3; i++) {
String key = iterator.next();
if (!key.equals(keys.get(i))) {
throw new Exception("bug");
}
if (i == 1) {
iterator.remove();
}
}
}
}
---------- END SOURCE ----------