Skip to content

Commit 28cbf79

Browse files
committed
[FLUSS-2091][common] Improved Documentation/Verbiage for Exception Cycle Detection
1 parent 197cdc7 commit 28cbf79

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

fluss-common/src/main/java/org/apache/fluss/utils/ExceptionUtils.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,35 +383,37 @@ public static <T extends Throwable> T firstOrSuppressed(T newException, @Nullabl
383383
}
384384

385385
/**
386-
* Checks whether the given {@code exception} throwable exception exists anywhere within the
387-
* exception chain of {@code previous}. This includes both the cause chain and all suppressed
388-
* exceptions. A visited set is used to avoid cycles and redundant traversal.
386+
* Checks whether the given {@code targetException} exists anywhere within the exception chain
387+
* of {@code exceptionChain}. This includes both the cause chain and all suppressed exceptions.
388+
* A visited set is used to avoid cycles and redundant traversal.
389389
*
390-
* @param exception The throwable exception to search for.
391-
* @param previous The previous throwable exception chain to search in.
392-
* @return True, if the exception is found within the suppressed chain, false otherwise.
390+
* @param targetException The throwable exception to search for.
391+
* @param exceptionChain The previous throwable exception chain to search in.
392+
* @return {@code true}, if the exception is found within the exception chain (suppressed or
393+
* cause), {@code false} otherwise.
393394
*/
394-
private static boolean existsInExceptionChain(Throwable exception, Throwable previous) {
395-
if (exception == null || previous == null) {
395+
private static boolean existsInExceptionChain(
396+
Throwable targetException, Throwable exceptionChain) {
397+
if (targetException == null || exceptionChain == null) {
396398
return false;
397399
}
398-
if (exception == previous) {
400+
if (targetException == exceptionChain) {
399401
return true;
400402
}
401403

402404
// Apply cycle prevention through a graph-like traversal of existing
403405
// suppressed or cause chain exceptions
404-
Set<Throwable> previousExceptions = new HashSet<>();
406+
Set<Throwable> visitedExceptions = new HashSet<>();
405407
Deque<Throwable> exceptionStack = new ArrayDeque<>();
406-
exceptionStack.push(previous);
408+
exceptionStack.push(exceptionChain);
407409

408410
while (!exceptionStack.isEmpty()) {
409411
Throwable currentException = exceptionStack.pop();
410-
if (!previousExceptions.add(currentException)) {
412+
if (!visitedExceptions.add(currentException)) {
411413
continue;
412414
}
413415

414-
if (currentException == exception) {
416+
if (currentException == targetException) {
415417
return true;
416418
}
417419

fluss-common/src/test/java/org/apache/fluss/utils/ExceptionUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void testFirstOrSuppressedCyclePreventionThroughCauseChain() {
160160
Exception result = ExceptionUtils.firstOrSuppressed(exceptionA, exceptionB);
161161
assertThat(result).isEqualTo(exceptionB);
162162

163-
// verify the exception cycle was prevented (B should not have A suppressed)
163+
// verify the exception cycle was prevented (B should not have A suppressed)
164164
assertThat(exceptionB.getSuppressed()).doesNotContain(exceptionA);
165165
assertThat(exceptionA.getCause()).isEqualTo(exceptionB);
166166

0 commit comments

Comments
 (0)