< prev index next >

src/java.base/share/classes/java/lang/Throwable.java

Print this page
rev 50866 : 8203826: Chain exception from initialization in later NoClassDefFoundErrors.

@@ -831,10 +831,34 @@
         }
         return stackTrace;
     }
 
     /**
+     * This method is currently only called from the VM for instances of
+     * ExceptionInInitializerError which are stored for later chaining into a
+     * NoClassDefFoundError in order to prevent keeping classes from the native
+     * backtrace alive.
+     */
+    private static void removeNativeBacktrace(Throwable throwable) {
+        Throwable t = throwable;
+        while ((t != null)) {
+            // Triggers the generation of the stack trace elements.
+            t.getOurStackTrace();
+            if (t.suppressedExceptions != null) {
+                // If there are any suppressed exceptions,
+                // remove their native backtraces as well.
+                for (Throwable s : t.suppressedExceptions) {
+                    removeNativeBacktrace(s);
+                }
+            }
+            // Now we don't need the native backtrace any more
+            t.backtrace = null;
+            t = t.getCause();
+        }
+    }
+
+    /**
      * Sets the stack trace elements that will be returned by
      * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
      * and related methods.
      *
      * This method, which is designed for use by RPC frameworks and other
< prev index next >