Topic
No replies
C340_Vasily_Nalivayko
1 Post
ACCEPTED ANSWER

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

‏2013-06-07T16:02:44Z |

When using Guava (http://code.google.com/p/guava-libraries/) 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 (http://docs.oracle.com/javase/6/docs/api/java/util/Collection.html#iterator%28%29).

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