From 2d0ed0c55ce3a964a4c34f4680698172f2b4fb43 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Thu, 7 Nov 2024 15:30:25 +0900 Subject: [PATCH] Fill the stacktrace of `ResponseCompleteException` when `verboseResponses = true` Motivation: `ResponseCompleteException` is considered a safe exception to clean up request resources. However, it would be a good idea to leave a stacktrace in case there is a bug in the implementation or the user wants to know how the error occurred. Modifications: - Create a new instance if `verboseResponse = true` and `ResponseCompletionException` is sampled by `verboseExceptionSampler` Result: You can now sees the stacktrace of `ResponseCompleteException` when `Flags.verboseResponse()` is true. --- .../armeria/common/ResponseCompleteException.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/ResponseCompleteException.java b/core/src/main/java/com/linecorp/armeria/common/ResponseCompleteException.java index 5f767a94064..0c1f5981f2c 100644 --- a/core/src/main/java/com/linecorp/armeria/common/ResponseCompleteException.java +++ b/core/src/main/java/com/linecorp/armeria/common/ResponseCompleteException.java @@ -26,16 +26,23 @@ public final class ResponseCompleteException extends CancellationException { private static final long serialVersionUID = 6090278381004263949L; - private static final ResponseCompleteException INSTANCE = new ResponseCompleteException(); + private static final ResponseCompleteException INSTANCE = new ResponseCompleteException(false); /** * Returns the singleton {@link ResponseCompleteException}. */ public static ResponseCompleteException get() { - return INSTANCE; + if (Flags.verboseResponses() && + Flags.verboseExceptionSampler().isSampled(ResponseCompleteException.class)) { + return new ResponseCompleteException(); + } else { + return INSTANCE; + } } - private ResponseCompleteException() { + private ResponseCompleteException() {} + + private ResponseCompleteException(@SuppressWarnings("unused") boolean dummy) { super(null, null, false, false); } }