From f4a10ea9f7b698428852782a9400d83205f74c3c Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Wed, 13 Mar 2024 15:41:10 -0400 Subject: [PATCH] Add correct exception logging in the ExecutorUtil --- .../apache/solr/common/util/ExecutorUtil.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java index c97658efebdc..b5bd42257d7e 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java @@ -314,15 +314,19 @@ public void execute(final Runnable command) { if (t instanceof OutOfMemoryError) { throw t; } - if (enableSubmitterStackTrace) { - log.error( - "Uncaught exception {} thrown by thread: {}", - t, - currentThread.getName(), - submitterStackTrace); - } else { - log.error("Uncaught exception {} thrown by thread: {}", t, currentThread.getName()); + // Flip around the exception cause tree, because it is in reverse order + Throwable baseCause = t; + Throwable nextCause = submitterStackTrace; + while (nextCause != null) { + baseCause = new Exception(nextCause.getMessage(), baseCause); + baseCause.setStackTrace(nextCause.getStackTrace()); + nextCause = nextCause.getCause(); } + log.error( + "Uncaught exception {} thrown by thread: {}", + t, + currentThread.getName(), + baseCause); throw t; } finally { isServerPool.remove();