carterkozak commented on a change in pull request #335: Import of 
LogstashLayout as JsonTemplateLayout
URL: https://github.com/apache/logging-log4j2/pull/335#discussion_r405623558
 
 

 ##########
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java
 ##########
 @@ -40,12 +40,26 @@ private Throwables() {
      * @return the deepest throwable or the given throwable
      */
     public static Throwable getRootCause(final Throwable throwable) {
+
+        // Keep a second pointer that slowly walks the causal chain. If the 
fast
+        // pointer ever catches the slower pointer, then there's a loop.
+        Throwable slowPointer = throwable;
+        boolean advanceSlowPointer = false;
+
+        Throwable parent = throwable;
         Throwable cause;
-        Throwable root = throwable;
-        while ((cause = root.getCause()) != null) {
-            root = cause;
+        while ((cause = parent.getCause()) != null) {
+            parent = cause;
+            if (parent == slowPointer) {
+                throw new IllegalArgumentException("loop in causal chain");
 
 Review comment:
   This isn't something we expect to happen often, but I wonder if we should 
return the input `throwable` and debug log to the status logger in this case?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to