Currently Throwable.backtrace is treated by Class.getDeclaredField like an injected field; it is not reported back to the caller. The reason it is hidden is because a crash that was reported (JDK-4496456) when a user tries to get the contents of the backtrace Object array.
Without knowing the history hereJDK-4496456 was very likely because of the specific representation behind Throwable.backtrace back then. This changed. The Object[] looks now like:
Object[] backtrace = { short[] method_ids, int[] bcis, Object[] mirrors };
and it's perfectly sane to do:
// Retrieve the class of throwable.backtrace[0][0].
Class class2 = ((Object[]) ((Object[]) backtrace)[0])[0].getClass();
(although it will bail out with a ClassCastException).
To make sure this doesn't break again we could take the test case ofJDK-4496456 and make a regression test.
Without knowing the history here
Object[] backtrace = { short[] method_ids, int[] bcis, Object[] mirrors };
and it's perfectly sane to do:
// Retrieve the class of throwable.backtrace[0][0].
Class class2 = ((Object[]) ((Object[]) backtrace)[0])[0].getClass();
(although it will bail out with a ClassCastException).
To make sure this doesn't break again we could take the test case of
- relates to
-
JDK-4763881 REGRESSION: Class.getDeclaredFields() doesn't return Throwable.backtrace
-
- Closed
-
-
JDK-5026971 (hotspot) Clean up hiding of exception backtrace field
-
- Closed
-
-
JDK-8158237 JVMTI hides critical debug information for memory leak tracing
-
- Resolved
-
-
JDK-4496456 Segmentation fault introspecting ((Throwable) obj).backtrace[0][0]
-
- Closed
-