• No replies
1 Post

Pinned topic java.util.TreeMap Bug. (NoSuchElementException in iterator()).

‏2013-06-07T16:02:44Z | descendingmap headmap iterator java.util.treemap nosuchelementexception

When using Guava ( encountered a problem with RangeSet class.

Using RangeSet's methods complement() and subRangeSet sometimes resulted in an error NoSuchElementException. And this exception is thrown out of an iterator() method, which should not throw any exceptions (

After some digging I managed to find root problem of these errors. When using TreeMap's methods headMap (or tailMap) with descendingMap (in any order) and after using values().iterator() NoSuchElementException was thrown. Simple code to reproduce this problem:

new TreeMap<Integer, Integer>().headMap(0, false).descendingMap().values().iterator();

This error is not repeated in other JDK's.

My JDK version:

java version "1.6.0"
Java(TM) SE Runtime Environment (build pxa6460sr12-20121025_01(SR12))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux amd64-64 jvmxa6460sr12-20121024_126067 (JIT enabled, AOT enabled)
J9VM - 20121024_126067
JIT  - r9_20120914_26057
GC   - 20120928_AA)
JCL  - 20121014_01