NullPointerException comparing PredicateCondition (in equals method)
Janusgraph (version 0.5.2) can be made to throw a NullPointerException using the following traversals:
g.V().has(label, eq('User')).has(label, eq(null))
g.V().has(label, without('User')).has(label, without('Group'))
in QueryUtil#constraints2QNF we're builidng up a list of conditions from the constaints and in addConstraints we're checking if the list already contains the condition (by calling contains)
if (!conditions.contains(pc)) conditions.add(pc);
It calls the equals method in PredicateCondition. If the list already contains another condition with the same predicate and key, and the condition we're trying to add has a null value, it will throw a null pointer exception
public boolean equals(Object other) {
// ....
PredicateCondition oth = (PredicateCondition) other;
return key.equals(oth.key) && predicate.equals(oth.predicate) && value.equals(oth.value);
The stack trace:
java.lang.NullPointerException
at org.janusgraph.graphdb.query.condition.PredicateCondition.equals(PredicateCondition.java:109)
at java.util.ArrayList.indexOf(ArrayList.java:321)
at java.util.ArrayList.contains(ArrayList.java:304)
at org.janusgraph.graphdb.query.QueryUtil.addConstraint(QueryUtil.java:272)
at org.janusgraph.graphdb.query.QueryUtil.constraints2QNF(QueryUtil.java:215)
at org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder.constructQueryWithoutProfile(GraphCentricQueryBuilder.java:238)
at org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder.constructQuery(GraphCentricQueryBuilder.java:225)
at org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep.buildGraphCentricQuery(JanusGraphStep.java:196)
at org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep.lambda$new$0(JanusGraphStep.java:94)
at java.util.LinkedHashMap$LinkedEntrySet.forEach(LinkedHashMap.java:671)
at org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep.lambda$new$1(JanusGraphStep.java:94)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep.lambda$new$3(JanusGraphStep.java:93)
at org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep.processNextStart(GraphStep.java:157)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:144)
at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:196)
at org.apache.tinkerpop.gremlin.console.Console$_closure3.doCall(Console.groovy:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:37)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
at org.codehaus.groovy.tools.shell.Groovysh.setLastResult(Groovysh.groovy:463)
at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:190)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:201)
at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.super$3$execute(GremlinGroovysh.groovy)