2

I'm intermittently getting the following exception whilst removing vertices from a Gremlin (TinkerGraph) graph:

Exception in thread "main" java.lang.NegativeArraySizeException
at java.util.AbstractCollection.toArray(AbstractCollection.java:136)
at java.util.ArrayList.addAll(ArrayList.java:581)
at java.util.HashMap$Values.forEach(HashMap.java:981)
at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerHelper.getEdges(TinkerHelper.java:172)
at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex.edges(TinkerVertex.java:146)
at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex.remove(TinkerVertex.java:131)
at org.apache.tinkerpop.gremlin.process.traversal.step.filter.DropStep.filter(DropStep.java:67)
at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:38)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:37)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:128)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:38)
at org.apache.tinkerpop.gremlin.process.traversal.Traversal.iterate(Traversal.java:203)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.iterate(GraphTraversal.java:2664)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal$Admin.iterate(GraphTraversal.java:177)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.iterate(DefaultGraphTraversal.java:48)
at mycode.merge.GraphMerger.mergeVertices(GraphMerger.java:172)
at mycode.merge.GraphMerger.lambda$mergeGraphs$6(GraphMerger.java:78)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.concurrent.ConcurrentHashMap$ValueSpliterator.forEachRemaining(ConcurrentHashMap.java:3566)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at mycode.merge.GraphMerger.mergeGraphs(GraphMerger.java:79)
at mycode.cli.mapper.MergeGraphFiles.main(MergeGraphFiles.java:117)

The code that is causing the problem is (the last line of the following is 172, where the exception is being thrown):

LOGGER.info("Removing original vertices");
Object[] ids = mergeGroup.stream().map(Element::id).filter(Objects::nonNull).toArray();
LOGGER.debug("IDs to remove {}", ids);
if(ids != null && ids.length > 0)
    graph.traversal().V(ids).drop().iterate();

Am I doing something wrong? I'm struggling to reliably reproduce this error to debug, as it seems to be intermittent (and different data sets work under different versions of Java).

James Baker
  • 1,143
  • 17
  • 39
  • The error clearly states toArray causes the error, maybe what you're converting is null? – Lance Toth Mar 14 '18 at 10:47
  • I'm explicitly checking that the array isn't null or empty, and I've just tried it with a filter to remove any null items in the array (which made no difference). I've updated the code above to include this filter. – James Baker Mar 14 '18 at 12:09
  • The NegativeArraySizeException is sometimes because a value was interpreted as a signed value (ie negative) when meant to be a positive integer. I'm not sure it is your array that has the issue. This seems to be happening inside the TinkerPop code itself as it tries to decide which edges it needs to also delete along with the vertices. So something is causing the underlying code to try and allocate an array with a negative length is my guess. – Kelvin Lawrence Mar 16 '18 at 21:36

0 Answers0