Skip to content

Commit 430cc36

Browse files
committed
TINKERPOP-3140 Prevent NPE for repeat()
NPE raised during calls to hashcode() during strategy application if the repeat() child traversal was null, like if you did g.V().emit() by mistake. This change allows the existing error message we've long used to get raised. CTR
1 parent d16f4b7 commit 430cc36

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
3939
* Deprecated `gremlin_python.process.__.has_key_` in favor of `gremlin_python.process.__.has_key`.
4040
* Added `gremlin.spark.outputRepartition` configuration to customize the partitioning of HDFS files from `OutputRDD`.
4141
* Allowed `mergeV()` and `mergeE()` to supply `null` in `Map` values.
42+
* Improved error message for when `emit()` is used without `repeat()`.
4243
4344
[[release-3-7-3]]
4445
=== TinkerPop 3.7.3 (October 23, 2024)

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,13 @@ public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) {
179179

180180
@Override
181181
public int hashCode() {
182-
int result = super.hashCode() ^ this.repeatTraversal.hashCode();
182+
int result = super.hashCode();
183+
184+
// not a normal state, but prevents NPE during strategy application allowing the better
185+
// user-friendly error message to show up at iteration
186+
if (this.repeatTraversal != null)
187+
result ^= repeatTraversal.hashCode();
188+
183189
result ^= Boolean.hashCode(this.untilFirst);
184190
result ^= Boolean.hashCode(this.emitFirst) << 1;
185191
if (this.loopName != null)

0 commit comments

Comments
 (0)