rionmonster commented on code in PR #2112:
URL: https://github.com/apache/fluss/pull/2112#discussion_r2643358538


##########
fluss-common/src/main/java/org/apache/fluss/utils/ExceptionUtils.java:
##########
@@ -365,10 +369,65 @@ public static <T extends Throwable> T firstOrSuppressed(T 
newException, @Nullabl
 
         if (previous == null || previous == newException) {
             return newException;
-        } else {
-            previous.addSuppressed(newException);
+        }
+
+        // If the exceptions already reference each other through the 
suppression or cause chains,
+        // return the previous exception to avoid introducing cycles.
+        if (existsInExceptionChain(newException, previous)
+                || existsInExceptionChain(previous, newException)) {
             return previous;
         }
+
+        previous.addSuppressed(newException);
+        return previous;
+    }
+
+    /**
+     * Checks whether the given {@code exception} throwable exception exists 
anywhere within the
+     * exception chain of {@code previous}. This includes both the cause chain 
and all suppressed
+     * exceptions. A visited set is used to avoid cycles and redundant 
traversal.
+     *
+     * @param exception The throwable exception to search for.
+     * @param previous The previous throwable exception chain to search in.
+     * @return True, if the exception is found within the suppressed chain, 
false otherwise.

Review Comment:
   Updated!



-- 
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]

Reply via email to