Search code examples
amazon-neptune

How to programmatically create a vertex in aws neptune using java


I am running the following java code (a very small modification on the example posted here https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-java.html) and getting a null pointer exception. I see the vertex is created in Neptune, but the driver seems to bomb on the response.

Am I doing something wrong here? Has anyone been successful in programmatically creating a vertex in Neptune using Java.

public class NeptuneMain {
  public static void main(String[] args) {
  Cluster.Builder builder = Cluster.build();
  builder.addContactPoint("<enter cluster url here>");
  builder.port(8182);

  Cluster cluster = builder.create();
  GraphTraversalSource g = EmptyGraph.instance().traversal().withRemote(DriverRemoteConnection.using(cluster));
  GraphTraversal t = g.addV("Aspect");
  t.forEachRemaining(
        e ->  System.out.println(e)
  );
  cluster.close();
}
}

Stack trace is :

Exception in thread "main" java.util.concurrent.CompletionException: java.lang.NullPointerException
    at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
    at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
    at org.apache.tinkerpop.gremlin.driver.ResultSet.one(ResultSet.java:107)
    at org.apache.tinkerpop.gremlin.driver.ResultSet$1.hasNext(ResultSet.java:159)
    at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:166)
    at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:153)
    at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:142)
    at 

Solution

  • You might be using an older version (3.2.x) of the gremlin-driver package. Try upgrading to >= 3.3.2 and let us know if you still observe this problem.