Hooli
Hooli

Reputation: 1195

cqengine IndexedCollection add causing nullpointer

I'm currently getting this error when I add elements to an IndexedCollection:

HIGHEST: null
java.lang.NullPointerException
    at java.util.concurrent.ConcurrentSkipListMap.doGet(ConcurrentSkipListMap.java:778)
    at java.util.concurrent.ConcurrentSkipListMap.get(ConcurrentSkipListMap.java:1546)
    at com.googlecode.cqengine.index.support.AbstractMapBasedAttributeIndex.addAll(AbstractMapBasedAttributeIndex.java:81)
    at com.googlecode.cqengine.engine.CollectionQueryEngine$12.perform(CollectionQueryEngine.java:1125)
    at com.googlecode.cqengine.engine.CollectionQueryEngine.forEachIndexDo(CollectionQueryEngine.java:1206)
    at com.googlecode.cqengine.engine.CollectionQueryEngine.addAll(CollectionQueryEngine.java:1122)
    at com.googlecode.cqengine.ConcurrentIndexedCollection.add(ConcurrentIndexedCollection.java:351)

I've tried to debug to see if I'm passing a null value but I'm not. The object I'm trying to add has a null DateTime but the respective index already returns null instead when it is null.

I think the solution to this one ultimately comes down to experience, @npgall have you ever encountered this issue and if so how did you solve it?

Upvotes: 0

Views: 603

Answers (1)

npgall
npgall

Reputation: 3028

I think the documentation on the site in this area was lacking. It mentioned SimpleNullableAttribute and MultiValueNullableAttribute but didn't really explain when to use them.

The TL;DR is: if you get an NPE, it usually means you need to use a nullable attribute.

Or more precisely: if there is any chance your data may contain null values, then you need to use a nullable attribute (e.g. SimpleNullableAttribute) instead of a non-nullable one (e.g. SimpleAttribute).

Anyway I've expanded the documentation on the main Readme.md to discuss "Null values" in more detail. Hope that helps!

Upvotes: 2

Related Questions