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(); + } }