Description
When extracting step metrics from ProfileStep, this code block below[1] assumes that step metrics is always initialized. But if a step does not invoke starts hasNext() or next() methods for any particular reason, this throws an NPE.
An example case where this could happen is if a step decides not to invoke any upstream step by halting the execution:
step1 -> ProfileStep -> step2 -> ProfileStep -> step3 -> ProfileStep -> step4 -> ProfileStep
In this case if say step3/4 decides not to get starts from previous step, then the step metrics on all the preceding ProfileStep are left uninitialized.
Sample trace:
java.lang.NullPointerException: null at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics.addTopLevelMetrics(DefaultTraversalMetrics.java:157) at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics.setMetrics(DefaultTraversalMetrics.java:143) at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileSideEffectStep.hasNext(ProfileSideEffectStep.java:75) at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.hasNext(ExpandableStepIterator.java:42) ...