zrlw commented on code in PR #16369:
URL: https://github.com/apache/dubbo/pull/16369#discussion_r3670576278


##########
dubbo-serialization/dubbo-serialization-fastjson2/src/test/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2SerializationTest.java:
##########
@@ -620,4 +678,95 @@ void testLimit5() throws IOException, 
ClassNotFoundException {
             frameworkModel.destroy();
         }
     }
+
+    private byte[] serializeRefOuter(Serialization serialization, URL url) 
throws IOException {
+        RefOuter outer = new RefOuter();
+        List<RefInner> items = new ArrayList<>();
+        List<Long> sharedIds = new ArrayList<>();
+        sharedIds.add(1L);
+        sharedIds.add(2L);
+        for (int i = 0; i < 20; i++) {
+            RefInner inner = new RefInner();
+            inner.setName("item-" + i);
+            inner.setIds(sharedIds);
+            items.add(inner);
+        }
+        outer.setItems(items);
+
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ObjectOutput objectOutput = serialization.serialize(url, outputStream);
+        objectOutput.writeObject(outer);
+        objectOutput.flushBuffer();
+        return outputStream.toByteArray();
+    }
+
+    private int countConcurrentNullIds(Serialization serialization, URL url, 
byte[] bytes) throws Exception {
+        int rounds = 10;
+        int threadCount = 200;
+        AtomicInteger totalNullTasks = new AtomicInteger();
+        AtomicReference<Throwable> failure = new AtomicReference<>();
+
+        for (int round = 0; round < rounds; round++) {
+            clearObjectReaderCache();
+            CyclicBarrier barrier = new CyclicBarrier(threadCount);
+            CountDownLatch endLatch = new CountDownLatch(threadCount);
+            AtomicInteger roundNullTasks = new AtomicInteger();
+            for (int i = 0; i < threadCount; i++) {
+                Thread thread = new Thread(() -> {
+                    try {
+                        barrier.await();
+                        if (countNullIds(serialization, url, bytes) > 0) {
+                            roundNullTasks.incrementAndGet();
+                        }
+                    } catch (Throwable throwable) {
+                        failure.compareAndSet(null, throwable);
+                    } finally {
+                        endLatch.countDown();
+                    }
+                });
+                thread.start();
+            }
+            endLatch.await();
+            if (failure.get() != null) {
+                throw new AssertionError("Concurrent deserialization failed", 
failure.get());
+            }
+            totalNullTasks.addAndGet(roundNullTasks.get());
+        }
+
+        return totalNullTasks.get();
+    }
+
+    private int countNullIds(Serialization serialization, URL url, byte[] 
bytes) throws Exception {
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
+        ObjectInput objectInput = serialization.deserialize(url, inputStream);
+        RefOuter outer = objectInput.readObject(RefOuter.class);
+        if (outer == null || outer.getItems() == null) {
+            return 1;
+        }
+
+        int nullCount = 0;
+        for (RefInner inner : outer.getItems()) {
+            if (inner == null || inner.getIds() == null) {
+                nullCount++;
+            }
+        }
+        return nullCount;
+    }
+
+    @SuppressWarnings("unchecked")
+    private void clearObjectReaderCache() throws Exception {
+        ObjectReaderProvider provider = 
JSONFactory.getDefaultObjectReaderProvider();
+        for (String fieldName : new String[] {"cache", "cacheFieldBased"}) {

Review Comment:
   Reflecting on internal fields and silently swallowing NoSuchFieldException 
means the test's effectiveness depends on the specific fastjson2 version. When 
fastjson2 renames cache in a point release, this test becomes "always green" — 
it no longer reproduces the race, so any future regression slips through.
   
   Options:
   
   Run each round in a fresh classloader / JVM to get a clean provider,
   Explicitly document that this test is meaningful only within a specific 
fastjson2 version range.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to