Skip to content

Commit eabfcba

Browse files
committed
Fix null map key parsing in GenericLiteralVisitor
The visitor treated all keyword map keys as their text representation, so a null key in [null:"value"] was parsed as the String "null" instead of Java null. This broke round-tripping maps with null keys through GremlinLang serialization and ANTLR parsing.
1 parent a4e433e commit eabfcba

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GenericLiteralVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ public Object visitGenericMapLiteral(final GremlinParser.GenericMapLiteralContex
350350
} else if (kctx instanceof GremlinParser.GenericMapLiteralContext) {
351351
key = visitGenericMapLiteral((GremlinParser.GenericMapLiteralContext) kctx);
352352
} else if (kctx instanceof GremlinParser.KeywordContext) {
353-
key = ((GremlinParser.KeywordContext) kctx).getText();
353+
final String keywordText = ((GremlinParser.KeywordContext) kctx).getText();
354+
key = keywordText.equals("null") ? null : keywordText;
354355
} else if (kctx instanceof GremlinParser.NakedKeyContext) {
355356
key = ((GremlinParser.NakedKeyContext) kctx).getText();
356357
} else if (kctx instanceof TerminalNode) {

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GeneralLiteralVisitorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ public static Iterable<Object[]> generateTestParameters() {
632632
{"[{'x'}: 'x']", createMap(new Object[]{new HashSet<>(Arrays.asList("x")), "x"})},
633633
{"[['x']: ['x',{'y'}]]", createMap(new Object[]{Arrays.asList("x"), Arrays.asList("x", new HashSet<>(Arrays.asList("y")))})},
634634
{"[['x']: ['x',['y']]]", createMap(new Object[]{Arrays.asList("x"), Arrays.asList("x", Arrays.asList("y"))})},
635+
{"[null:'x']", createMap(new Object[]{null, "x"})},
636+
{"[null:null]", createMap(new Object[]{null, null})},
637+
{"[null:'x','y':'z']", createMap(new Object[]{null, "x", "y", "z"})},
638+
{"['null':'x']", createMap(new Object[]{"null", "x"})},
635639
});
636640
}
637641

0 commit comments

Comments
 (0)