JDK-8226809 : Circular reference in printed stack trace is not correctly indented & ambiguous
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8,11,12,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2019-06-23
  • Updated: 2020-08-28
  • Resolved: 2019-06-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 14 Other
11.0.9Fixed 14 b04Fixed openjdk8u272Fixed
Related Reports
Relates :  
Relates :  
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



Comments
Fix Request (8u) This is a safe indenting fix that improves diagnostic UX. Patch applies to 8u with reshuffling, passes tier1 tests as well.
19-08-2020

Fix Request (11u) This is a safe indenting fix that improves diagnostic UX. Patch applies cleanly to 11u, passes tier1 tests as well.
12-08-2020

Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-June/061113.html
28-06-2019

To reproduce the issue, run the attached test case: JDK 8u212- Fail JDK 11.0.2 - Fail JDK 13-ea - Fail Output: java.lang.Exception: first at JI9061369.main(JI9061369.java:5) Suppressed: java.lang.Exception: second at JI9061369.main(JI9061369.java:6) Suppressed: java.lang.Exception: third at JI9061369.main(JI9061369.java:8) Suppressed: java.lang.Exception: fourth at JI9061369.main(JI9061369.java:10) [CIRCULAR REFERENCE:java.lang.Exception: first] Suppressed: java.lang.Exception: fifth at JI9061369.main(JI9061369.java:16)
26-06-2019