Hello,
Please review the fix for
JDK-8226809: hCircular reference in printed stack trace is not
correctly indented & ambiguous
http://cr.openjdk.java.net/~darcy/8226809.0/
Patch below.
Consider the code which creates various circularities in the suppressed
and caused links of an exception:
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);
// Circular reference
fourth.addSuppressed(first);
fourth.addSuppressed(new Exception("fifth"));
// Another Circular reference
fourth.initCause(second);
first.printStackTrace();
}
}
The existing implementation prints the stack trace as:
java.lang.Exception: first
at DejaVuStackTrace.main(DejaVuStackTrace.java:3)
Suppressed: java.lang.Exception: second
at DejaVuStackTrace.main(DejaVuStackTrace.java:4)
Suppressed: java.lang.Exception: third
at DejaVuStackTrace.main(DejaVuStackTrace.java:6)
Suppressed: java.lang.Exception: fourth
at DejaVuStackTrace.main(DejaVuStackTrace.java:8)
[CIRCULAR REFERENCE:java.lang.Exception: first]
Suppressed: java.lang.Exception: fifth
at DejaVuStackTrace.main(DejaVuStackTrace.java:14)
[CIRCULAR REFERENCE:java.lang.Exception: second]
and the revised code prints this more helpfully as
java.lang.Exception: first
at DejaVuStackTrace.main(DejaVuStackTrace.java:3)
Suppressed: java.lang.Exception: second
at DejaVuStackTrace.main(DejaVuStackTrace.java:4)
Suppressed: java.lang.Exception: third
at DejaVuStackTrace.main(DejaVuStackTrace.java:6)
Suppressed: java.lang.Exception: fourth
at DejaVuStackTrace.main(DejaVuStackTrace.java:8)
Suppressed: [CIRCULAR REFERENCE: java.lang.Exception:
first]
Suppressed: java.lang.Exception: fifth
at DejaVuStackTrace.main(DejaVuStackTrace.java:14)
Caused by: [CIRCULAR REFERENCE: java.lang.Exception: second]
The format of the printed stack trace is not specified and I don't think
it is worthwhile to write a regression test for this change.
Cheers,
-Joe
diff -r c9093341cfe2 src/java.base/share/classes/java/lang/Throwable.java
--- a/src/java.base/share/classes/java/lang/Throwable.java Fri Jun 28
13:02:18 2019 -0700
+++ b/src/java.base/share/classes/java/lang/Throwable.java Fri Jun 28
16:34:15 2019 -0700
@@ -693,7 +693,7 @@
Set<Throwable> dejaVu) {
assert Thread.holdsLock(s.lock());
if (dejaVu.contains(this)) {
- s.println("\t[CIRCULAR REFERENCE:" + this + "]");
+ s.println(prefix + caption + "[CIRCULAR REFERENCE: " + this
+ "]");
} else {
dejaVu.add(this);
// Compute number of frames in common between this and
enclosing trace