This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 071b9072b fix(java): Fix flakiness in LazyMapTest#testMap (#2692)
071b9072b is described below

commit 071b9072b9197c5254c2944ab4b639643562e402
Author: JACKDABOSS <[email protected]>
AuthorDate: Fri Oct 3 01:49:09 2025 -0500

    fix(java): Fix flakiness in LazyMapTest#testMap (#2692)
    
    ## What does this PR do?
    
    `LazyMapTest#testMap` assumes that `HashMap` maintains constant
    ordering, which can lead to non-deterministic failures if the ordering
    of `map` when calling `toString()` is different from the ordering of
    `map` when initializing `LazyMap`.
    
    > This class makes no guarantees as to the order of the map; in
    particular, it does not guarantee that the order will remain constant
    over time.
    
    We can reproduce the non-deterministic failures with
    [NonDex](https://github.com/TestingResearchIllinois/NonDex):
    ```
    mvn -pl fory-core edu.illinois:nondex-maven-plugin:2.1.7:nondex 
-Dtest=org.apache.fory.collection.LazyMapTest#testMap
    ```
    
    Instead of `HashMap`, use `LinkedHashMap` to gurrantee constant ordering
    over time.
    
    ## Does this PR introduce any user-facing change?
    
    No
    
    Co-authored-by: Shawn Yang <[email protected]>
---
 .../src/test/java/org/apache/fory/collection/LazyMapTest.java          | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/java/fory-core/src/test/java/org/apache/fory/collection/LazyMapTest.java 
b/java/fory-core/src/test/java/org/apache/fory/collection/LazyMapTest.java
index b4626faa0..c840c786e 100644
--- a/java/fory-core/src/test/java/org/apache/fory/collection/LazyMapTest.java
+++ b/java/fory-core/src/test/java/org/apache/fory/collection/LazyMapTest.java
@@ -26,6 +26,7 @@ import static org.testng.Assert.assertTrue;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import org.apache.fory.Fory;
 import org.apache.fory.ForyTestBase;
@@ -37,7 +38,7 @@ public class LazyMapTest extends ForyTestBase {
 
   @Test
   public void testMap() throws NoSuchFieldException, IllegalAccessException {
-    Map<String, Integer> map = new HashMap<>();
+    Map<String, Integer> map = new LinkedHashMap<>();
     map.put("k1", 1);
     map.put("k2", 2);
     LazyMap<String, Integer> map1 = new LazyMap<>(new 
ArrayList<>(map.entrySet()));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to