@Test public void testPlatformSupportsFaskStackAccess() { assertThat(FastStackGetter.createIfSupported()).isNotNull(); }
@NullableDecl public static FastStackGetter createIfSupported() { try { Object javaLangAccess = Class.forName("sun.misc.SharedSecrets").getMethod("getJavaLangAccess").invoke(null); Method getElementMethod = Class.forName("sun.misc.JavaLangAccess") .getMethod("getStackTraceElement", Throwable.class, int.class); Method getDepthMethod = Class.forName("sun.misc.JavaLangAccess").getMethod("getStackTraceDepth", Throwable.class); @SuppressWarnings("unused") StackTraceElement unusedElement = (StackTraceElement) getElementMethod.invoke(javaLangAccess, new Throwable(), 0); @SuppressWarnings("unused") int unusedDepth = (int) (Integer) getDepthMethod.invoke(javaLangAccess, new Throwable()); return new FastStackGetter(javaLangAccess, getElementMethod, getDepthMethod); } catch (ThreadDeath t) { throw t; } catch (Throwable t) { return null; } }
FastStackGetter { @NullableDecl public static FastStackGetter createIfSupported() { try { Object javaLangAccess = Class.forName("sun.misc.SharedSecrets").getMethod("getJavaLangAccess").invoke(null); Method getElementMethod = Class.forName("sun.misc.JavaLangAccess") .getMethod("getStackTraceElement", Throwable.class, int.class); Method getDepthMethod = Class.forName("sun.misc.JavaLangAccess").getMethod("getStackTraceDepth", Throwable.class); @SuppressWarnings("unused") StackTraceElement unusedElement = (StackTraceElement) getElementMethod.invoke(javaLangAccess, new Throwable(), 0); @SuppressWarnings("unused") int unusedDepth = (int) (Integer) getDepthMethod.invoke(javaLangAccess, new Throwable()); return new FastStackGetter(javaLangAccess, getElementMethod, getDepthMethod); } catch (ThreadDeath t) { throw t; } catch (Throwable t) { return null; } } }
FastStackGetter { @NullableDecl public static FastStackGetter createIfSupported() { try { Object javaLangAccess = Class.forName("sun.misc.SharedSecrets").getMethod("getJavaLangAccess").invoke(null); Method getElementMethod = Class.forName("sun.misc.JavaLangAccess") .getMethod("getStackTraceElement", Throwable.class, int.class); Method getDepthMethod = Class.forName("sun.misc.JavaLangAccess").getMethod("getStackTraceDepth", Throwable.class); @SuppressWarnings("unused") StackTraceElement unusedElement = (StackTraceElement) getElementMethod.invoke(javaLangAccess, new Throwable(), 0); @SuppressWarnings("unused") int unusedDepth = (int) (Integer) getDepthMethod.invoke(javaLangAccess, new Throwable()); return new FastStackGetter(javaLangAccess, getElementMethod, getDepthMethod); } catch (ThreadDeath t) { throw t; } catch (Throwable t) { return null; } } private  FastStackGetter(Object javaLangAccess, Method getElementMethod, Method getDepthMethod); }
FastStackGetter { @NullableDecl public static FastStackGetter createIfSupported() { try { Object javaLangAccess = Class.forName("sun.misc.SharedSecrets").getMethod("getJavaLangAccess").invoke(null); Method getElementMethod = Class.forName("sun.misc.JavaLangAccess") .getMethod("getStackTraceElement", Throwable.class, int.class); Method getDepthMethod = Class.forName("sun.misc.JavaLangAccess").getMethod("getStackTraceDepth", Throwable.class); @SuppressWarnings("unused") StackTraceElement unusedElement = (StackTraceElement) getElementMethod.invoke(javaLangAccess, new Throwable(), 0); @SuppressWarnings("unused") int unusedDepth = (int) (Integer) getDepthMethod.invoke(javaLangAccess, new Throwable()); return new FastStackGetter(javaLangAccess, getElementMethod, getDepthMethod); } catch (ThreadDeath t) { throw t; } catch (Throwable t) { return null; } } private  FastStackGetter(Object javaLangAccess, Method getElementMethod, Method getDepthMethod); @NullableDecl static FastStackGetter createIfSupported(); StackTraceElement getStackTraceElement(Throwable throwable, int n); int getStackTraceDepth(Throwable throwable); }
FastStackGetter { @NullableDecl public static FastStackGetter createIfSupported() { try { Object javaLangAccess = Class.forName("sun.misc.SharedSecrets").getMethod("getJavaLangAccess").invoke(null); Method getElementMethod = Class.forName("sun.misc.JavaLangAccess") .getMethod("getStackTraceElement", Throwable.class, int.class); Method getDepthMethod = Class.forName("sun.misc.JavaLangAccess").getMethod("getStackTraceDepth", Throwable.class); @SuppressWarnings("unused") StackTraceElement unusedElement = (StackTraceElement) getElementMethod.invoke(javaLangAccess, new Throwable(), 0); @SuppressWarnings("unused") int unusedDepth = (int) (Integer) getDepthMethod.invoke(javaLangAccess, new Throwable()); return new FastStackGetter(javaLangAccess, getElementMethod, getDepthMethod); } catch (ThreadDeath t) { throw t; } catch (Throwable t) { return null; } } private  FastStackGetter(Object javaLangAccess, Method getElementMethod, Method getDepthMethod); @NullableDecl static FastStackGetter createIfSupported(); StackTraceElement getStackTraceElement(Throwable throwable, int n); int getStackTraceDepth(Throwable throwable);  }