NPE on nextEntry() for Int2ObjectOpenHashSet.values().iterator()

67 views
Skip to first unread message

Alex Fiennes

unread,
Jul 2, 2017, 6:49:24 PM7/2/17
to fastutil
Hi,

I am getting an odd exception when iterating across values with fastutil 7.0.13 on an Int2ObjectOpenHashSet which appears to be a problem in the fastutil implementation.

I have a nice simple loop of:

Iterator<Object> i = map.values.iterator();
while (i.hasNext()) { System.out.println(i.next()) }

but I am getting a:

     [java] Caused by: java.lang.NullPointerException
     [java] at it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap$MapIterator.nextEntry(Int2ObjectOpenHashMap.java:730)
     [java] at it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap$ValueIterator.next(Int2ObjectOpenHashMap.java:1033)

which appears to be from:

final int k = wrapped.getInt(-pos - 1);

but wrapper is documented as:
/**
* A lazily allocated list containing keys of entries that have wrapped
* around the table because of removals.
*/

and I have not been invoking remove and therefore wrapper has not been allocated hence the NPE.
so there is some situation where...
if (--pos < 0) {
...is true despite not having invoked remove() on the iterator().  

after this point I am getting other weird errors on the rehash functionality like:

java.lang.ArrayIndexOutOfBoundsException: -1
at it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap.rehash(Int2ObjectOpenHashMap.java:1167)
at it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap.insert(Int2ObjectOpenHashMap.java:346)
at it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap.put(Int2ObjectOpenHashMap.java:353)

so obviously something has got really confused.  I have the map in question protected by a ReadWriteLock so there are no concurrent writes.  Can you think of anything that I might be doing to provoke this behaviour, and what further information would be useful to help diagnose the problem?

many thanks

Alex

Sebastiano Vigna

unread,
Jul 3, 2017, 1:16:01 AM7/3/17
to fast...@googlegroups.com
I would look for map modifications happening during the iteration. That's usually the case.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Reply all
Reply to author
Forward
0 new messages