havenwang
havenwang

Reputation: 153

JanusGraph: NullPointerException when traversing vertices

I'm using JanusGraph to store and retrieve pairs of vertices connected by an edge.

After inserting over 100k pairs of vertices, I have found that when I try to traverse and retrieve the vertices from, for around 5% of the pairs, I get a NullPointerException error. I've included a stack trace of the error below.

For affected vertex pairs, the NullPointerException occurs every time I try and traverse it.

My question is: what may be causing these NullPointerExceptions?

Other info:

edit: I also want to add that both vertices of each pair exist in the graph, and I can even read properties from each.

Here is the relevant portion of the error stack trace:

Caused by: java.lang.NullPointerException
    at org.janusgraph.graphdb.database.serialize.AttributeUtil.hasGenericDataType(AttributeUtil.java:99)
    at org.janusgraph.graphdb.database.EdgeSerializer.readPropertyValue(EdgeSerializer.java:197)
    at org.janusgraph.graphdb.database.EdgeSerializer.readInline(EdgeSerializer.java:189)
    at org.janusgraph.graphdb.database.EdgeSerializer.parseRelation(EdgeSerializer.java:161)
    at org.janusgraph.graphdb.database.EdgeSerializer.readRelation(EdgeSerializer.java:73)
    at org.janusgraph.graphdb.transaction.RelationConstructor.readRelationCache(RelationConstructor.java:41)
    at org.janusgraph.graphdb.relations.CacheEdge.getPropertyMap(CacheEdge.java:107)
    at org.janusgraph.graphdb.relations.CacheEdge.getValueDirect(CacheEdge.java:114)
    at org.janusgraph.graphdb.relations.AbstractTypedRelation.lambda$properties$1(AbstractTypedRelation.java:157)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:294)
    at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206)
    at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
    at java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)   

The following is the relevant piece of code I have implemented for the graph traversal:

g.V()
        .has(indexProperty, vertexId)
        .coalesce(
                __.repeat(__
                        .bothE()
                        .or(
                                __.has(GraphElementProperties.WEIGHT, P.gte
                                        (STRONG_CONNECTION_WEIGHT_THRESHOLD)),
                                __.hasNot(GraphElementProperties.WEIGHT)
                        )
                        .bothV()
                        .dedup())
                        .emit(),
                __.identity()
        )
        .toList()

Upvotes: 1

Views: 533

Answers (1)

Kfir Dadosh
Kfir Dadosh

Reputation: 1419

Try to swap the traversals in your or traversal: First check if the property doesn't exist, and get the value only if it does. I would also consider changing bothV() to otherV().

Upvotes: 1

Related Questions