Question

In this code

Vertex page            = graph.getVertex(pageId);

If pageId doesn't exist it should throw IllegalArgumentException but instead it throws NullPointerException. Here page is null.

I am catching IllegalArgumentException exception but its never catched. Why?

Was it helpful?

Solution

If pageId is null then standard Blueprints behavior is to throw an IllegalArgumentException which is enforced by this test:

https://github.com/tinkerpop/blueprints/blob/2.5.0/blueprints-test/src/main/java/com/tinkerpop/blueprints/VertexTestSuite.java#L82

That said, I think you are talking about vertex existence (as you wrote "if pageId doesn't exist). In the case of existence, standard Blueprints behavior is to return null if the identifier does not find a vertex with it. This behavior is enforced by this test:

https://github.com/tinkerpop/blueprints/blob/2.5.0/blueprints-test/src/main/java/com/tinkerpop/blueprints/VertexTestSuite.java#L157

As you can see in my REPL session, Titan works as expected given the tests:

gremlin> g = TitanFactory.open('conf/titan-cassandra.properties')
==>titangraph[cassandrathrift:127.0.0.1]
gremlin> g.getVertex(4)
==>v[4]
gremlin> g.getVertex(8)
==>null
gremlin> g.getVertex(null)
Vertex id can not be null
Display stack trace? [yN] y
java.lang.IllegalArgumentException: Vertex id can not be null

This is all expected behavior given the Blueprints API. As far as "why" it works this way....I think that IllegalArgumentException wouldn't be appropriate for a "not found" situation. At the end of the day, this was largely just a design decision and we thought that returning null was better than tossing an exception to provide feedback on "existence".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top