Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8226809

Circular reference in printed stack trace is not correctly indented & ambiguous

    Details

    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      When printing the stack trace of an exception which has circular references, the text "[CIRCULAR REFERENCE:...]" is always indented with a single tab, ignoring the current indentation level. This can be confusing for suppressed exceptions as demonstrated in the provided code.

      Note also that there is a space missing after the colon:
      "[CIRCULAR REFERENCE:java.lang.Exception: first]"

      And ideally this message should include the caption (e.g. "Suppressed: [CIRCULAR ...") as well. Currently it is ambiguous whether this line represents a suppressed exception of the enclosing exception, or the cause of a preceding suppressed exception.


      ---------- BEGIN SOURCE ----------
      public class DejaVuStackTrace {
          public static void main(String[] args) {
              Exception first = new Exception("first");
              Exception second = new Exception("second");
              first.addSuppressed(second);
              Exception third = new Exception("third");
              second.addSuppressed(third);
              Exception fourth = new Exception("fourth");
              third.addSuppressed(fourth);
              
              // Create circular reference
              fourth.addSuppressed(first);
              
              fourth.addSuppressed(new Exception("fifth"));
              
              first.printStackTrace();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Suggested fix:
      https://github.com/openjdk/jdk/blob/c5cc07bec63fd7cad3e052cef53a5b19a4978e40/src/java.base/share/classes/java/lang/Throwable.java#L696
      Change the line to this:
      s.println(prefix + caption + "[CIRCULAR REFERENCE: " + this + "]");

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: