1
votes

I am creating a graph in a highly multithreaded environment and I am encountering a strange error. Whilst running I sometimes get an error that the property I am trying to access does not exist.

java.lang.IllegalStateException: The property does not exist as it has no key, value, or associated element

To try and figure this out I put a break point when that error occurred and found some strange behaviour.

When I run :

Vertex vertex = graph.traversal().V(123).next();
vertex.properties();

I see the list of all the properties I am expecting, for example "PROP1", "PROP2", and "PROP3". However when I run the following:

vertex.property("PROP1").value();

I get an error that the property does not exist. Even more strange is that vertex.property(xxx).value(); works for the other properties "PROP2" and "PROP3". What can lead to this strange behaviour ?

1

1 Answers

2
votes

As a good practice, you should always check before you hit next()

For example,

traversal=graph.traversal().V(123);
if (traversal.hasNext()) // avoid fast no property exception here.
    vertex=traversal.next() 

Another thing, vertex.property("PROP1") might be a bit strange to retrieve a value. property() retrieves the property object and that's not what you want I assume, if it doesn't find it, it throws an exception. Instead, a better way to get a value would be through vertex.values("PROP1"). This will return null if property doesn't exist.

Check documentations here