Skip to content

Commit

Permalink
add_stacktrace_in_monitor (#181)
Browse files Browse the repository at this point in the history
* add_stacktrace_in_monitor

* Add LegacySpringBanUtil

---------

Co-authored-by: “HzjNeverStop” <“441627022@qq.com”>
  • Loading branch information
HzjNeverStop and “HzjNeverStop” committed May 30, 2023
1 parent 99d321b commit 3250b66
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/alipay/sofa/common/utils/CharsetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
}
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 3250b66

Please sign in to comment.