From 3250b667b4ebb088b13e4c5db238c387e9ce1484 Mon Sep 17 00:00:00 2001 From: HzjNeverStop <441627022@qq.com> Date: Tue, 30 May 2023 11:08:09 +0800 Subject: [PATCH] add_stacktrace_in_monitor (#181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add_stacktrace_in_monitor * Add LegacySpringBanUtil --------- Co-authored-by: “HzjNeverStop” <“441627022@qq.com”> --- .../com/alipay/sofa/common/utils/CharsetUtil.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alipay/sofa/common/utils/CharsetUtil.java b/src/main/java/com/alipay/sofa/common/utils/CharsetUtil.java index c944bb1..4d6d4a6 100644 --- a/src/main/java/com/alipay/sofa/common/utils/CharsetUtil.java +++ b/src/main/java/com/alipay/sofa/common/utils/CharsetUtil.java @@ -98,8 +98,8 @@ public static void checkUTF8WellFormed(byte[] bytes, int off, int len, int mode) case MODE_ASSERT: throw new IllegalArgumentException("Input byte array is not well formed utf-8"); case MODE_MONITOR: - CHARSET_MONITOR_LOG.error("Detect not well formed utf-8 input: {}", new String( - bytes, off, len, StandardCharsets.UTF_8)); + CHARSET_MONITOR_LOG.error("Detect not well formed utf-8 input: {}, trace:{}", + new String(bytes, off, len, StandardCharsets.UTF_8), currentStackTrace()); default: } } @@ -199,4 +199,15 @@ private static boolean isWellFormedSlowPath(byte[] bytes, int off, int end) { } } } + + private static String currentStackTrace() { + StringBuilder sb = new StringBuilder(); + sb.append("\n"); + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + // 5 means the caller method + for (int i = 5; i < stackTraceElements.length; i++) { + sb.append(" ").append(stackTraceElements[i]).append("\n"); + } + return sb.toString(); + } }