You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by im...@apache.org on 2025/10/06 21:45:54 UTC
(asterixdb) 05/15: [NO ISSUE][HYR][MISC] Add utility method to abbreviate a stack overflow error
This is an automated email from the ASF dual-hosted git repository.
imaxon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 570e2a1c69ff635edcb295c894f464e80f2d1659
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Wed Sep 17 16:13:49 2025 -0400
[NO ISSUE][HYR][MISC] Add utility method to abbreviate a stack overflow error
Ext-ref: MB-68587
Change-Id: I97c2f2ae000c84681976bbf6cbc385f2ffa0ee54
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20390
Reviewed-by: Ian Maxon <im...@apache.org>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
---
.../org/apache/hyracks/api/util/ExceptionUtils.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
index a0863b2702..30c02382dd 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
@@ -236,4 +236,22 @@ public class ExceptionUtils {
public static boolean isErrorCode(HyracksDataException throwable, ErrorCode code) {
return throwable.getError().isPresent() && throwable.getError().get() == code;
}
+
+ public static Throwable truncateStackOverflowStack(Throwable ex, int limit) {
+ if (ex instanceof StackOverflowError) {
+ StackTraceElement[] fullTrace = ex.getStackTrace();
+ if (fullTrace.length > limit * 2) {
+ StackOverflowError copy = new StackOverflowError(ex.getMessage());
+ // keep the cause if there was one
+ copy.initCause(ex.getCause());
+ StackTraceElement[] trimmedTrace = new StackTraceElement[limit + 1];
+ System.arraycopy(fullTrace, 0, trimmedTrace, 0, limit);
+ trimmedTrace[limit] = new StackTraceElement("...<truncated " + (fullTrace.length - limit) + " lines>",
+ "..", null, -1);
+ copy.setStackTrace(trimmedTrace);
+ return copy;
+ }
+ }
+ return ex;
+ }
}