From 2f64ade0944193d108fda7fee6fe23a7fe308968 Mon Sep 17 00:00:00 2001 From: Shawn Yang Date: Tue, 27 Aug 2024 18:33:17 +0800 Subject: [PATCH] fix(java): fix reserved keyword conflict (#1819) ## What does this PR do? ## Related issues Closes #1818 ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark --- .../main/java/org/apache/fury/codegen/CodegenContext.java | 2 +- .../java/org/apache/fury/codegen/CodegenContextTest.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java b/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java index 69c4fe7ae0..d6568d46a0 100644 --- a/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java +++ b/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java @@ -124,7 +124,7 @@ public class CodegenContext { private static Map> nameConflicts = new ConcurrentHashMap<>(); Map newValNameIds = new HashMap<>(); - Set valNames = new HashSet<>(); + Set valNames = new HashSet<>(JAVA_RESERVED_WORDS); /** * State used for expression elimination/reuse. diff --git a/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java b/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java index feaf22b2b6..1b748bbc12 100644 --- a/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java @@ -82,6 +82,12 @@ public void testNewName() { } } + @Test + public void testNewNameKeywordConflict() { + Assert.assertNotEquals(new CodegenContext().newName("default"), "default"); + Assert.assertNotEquals(new CodegenContext().newNames("default", "abc")[0], "default"); + } + @Test public void testAddStaticField() { CodegenContext ctx = new CodegenContext();