From 6963c926a71be33d79bbca6bd6ac9e5ac3f52802 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Thu, 28 Nov 2024 14:44:07 +0900 Subject: [PATCH] Fill the stack trace of `ResponseCompleteException` when sampled (#5972) Motivation: `ResponseCompleteException` is considered a safe exception for cleaning up request resources. However, it would be a good idea to leave a stack trace in case there is a bug in the implementation or the user wants to know how the error occurred. Discord thread: https://discord.com/channels/1087271586832318494/1087272728177942629/1303562249629073520 Modifications: - Create a new instance if `ResponseCompletionException` is sampled by `verboseExceptionSampler` Result: You can now sample the stack trace of `ResponseCompleteException` with `verboseExceptionSampler`. --- .../armeria/common/ResponseCompleteException.java | 12 +++++++++--- 1 file changed, 9 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..04035b2d132 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,22 @@ 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.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); } }