[
https://issues.apache.org/jira/browse/TINKERPOP-1923?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16409345#comment-16409345
]
ASF GitHub Bot commented on TINKERPOP-1923:
-------------------------------------------
Github user rcaunt commented on the issue:
https://github.com/apache/tinkerpop/pull/818
@spmallette I've been working with @jbaker-nca to understand this issue a
bit more.
Our use case for discovering this bug was essentially merging two separate
graphs into a single graph.
When two vertices are to be merged we copy the edges from the original
vertex to a new one and then proceed to remove the edges on that vertex using
the following:
``` java
Object[] edgeIdsArr = edgeIds.toArray();
if(edgeIdsArr.length > 0)
graph.traversal().E(edgeIdsArr).drop().iterate();
```
Once the vertices are merged we then remove the original vertices from the
graph:
``` java
Object[] ids =
mergeGroup.stream().map(Element::id).filter(Objects::nonNull).toArray();
if(ids != null && ids.length > 0)
graph.traversal().V(ids).drop().iterate();
```
This second traversal on vertex removal is where the error would occur
yielding the following exception:
```
Exception in thread "main" java.lang.NegativeArraySizeException
at java.util.AbstractCollection.toArray(Unknown Source)
at java.util.ArrayList.addAll(Unknown Source)
at java.lang.Iterable.forEach(Unknown Source)
at
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerHelper.getEdges(TinkerHelper.java:173)
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.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:198)
at
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.iterate(GraphTraversal.java:2677)
at
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal$Admin.iterate(GraphTraversal.java:176)
at
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.iterate(DefaultGraphTraversal.java:48)
```
I noticed the following Google Groups post -
https://groups.google.com/forum/#!topic/gremlin-users/CGkuoBkNMGI - which
indicates that when removing a vertex the edges should be removed at the same
time. Therefore I modified our code to no longer remove the edges and only
remove the vertices.
This appears to have fixed our issue and we have reverted back to Tinkerpop
3.3.1 without any further issues. However, I suspect that one should be able
to remove edges and then vertices without encountering the issue.
> Intermittent NegativeArraySizeException on drop
> -----------------------------------------------
>
> Key: TINKERPOP-1923
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1923
> Project: TinkerPop
> Issue Type: Bug
> Components: tinkergraph
> Affects Versions: 3.3.1
> Reporter: James Baker
> Priority: Major
>
> I am intermittently getting the following exception when dropping vertices on
> a TinkerGraph:
> {noformat}
> 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)
> {noformat}
> My code is as follows (the last line is Line 172, which is where the
> exception is thrown):
> {code:java}
> LOGGER.info("Removing original vertices");
> Object[] ids = mergeGroup.stream().map(Element::id).toArray();
> LOGGER.debug("IDs to remove {}", ids);
> if(ids != null && ids.length > 0)
> graph.traversal().V(ids).drop().iterate();
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)