@Test public void testBlameBankdroidWithCause() { Exception e = ExceptionFactory.getExceptionWithCause(); String before = toStringWithStacktrace(e); ExceptionUtils.blameBankdroid(e); String after = toStringWithStacktrace(e); String description = String.format("\n---- Before ----\n%s---- After ----\n%s----", before, after); String[] afterLines = after.split("\n"); int firstCausedByIndex = 0; for (int i = 0; i < afterLines.length; i++) { if (afterLines[i].startsWith("Caused by: ")) { firstCausedByIndex = i; break; } } Assert.assertNotEquals(description, 0, firstCausedByIndex); Assert.assertTrue(description, afterLines[firstCausedByIndex + 1].startsWith("\tat not.bankdroid.at.all.")); int lastCausedByIndex = 0; for (int i = 0; i < afterLines.length; i++) { if (afterLines[i].startsWith("Caused by: ")) { lastCausedByIndex = i; } } Assert.assertNotEquals(description, 0, lastCausedByIndex); Assert.assertTrue(description, afterLines[lastCausedByIndex + 1].startsWith("\tat com.liato.bankdroid.")); }
public static void blameBankdroid(Throwable exception) { Throwable ultimateCause = getUltimateCause(exception); if (ultimateCause == null) { return; } StackTraceElement[] bankdroidifiedStacktrace = bankdroidifyStacktrace(ultimateCause.getStackTrace()); if (bankdroidifiedStacktrace.length == 0) { return; } if (bankdroidifiedStacktrace.length == ultimateCause.getStackTrace().length) { return; } Throwable fakeCause = cloneException(ultimateCause); if (fakeCause == null) { Timber.w(new RuntimeException( "Unable to bankdroidify exception of class: " + ultimateCause.getClass())); return; } fakeCause.setStackTrace(concatArrays(bankdroidifiedStacktrace, fakeCause.getStackTrace())); ultimateCause.initCause(fakeCause); }
ExceptionUtils { public static void blameBankdroid(Throwable exception) { Throwable ultimateCause = getUltimateCause(exception); if (ultimateCause == null) { return; } StackTraceElement[] bankdroidifiedStacktrace = bankdroidifyStacktrace(ultimateCause.getStackTrace()); if (bankdroidifiedStacktrace.length == 0) { return; } if (bankdroidifiedStacktrace.length == ultimateCause.getStackTrace().length) { return; } Throwable fakeCause = cloneException(ultimateCause); if (fakeCause == null) { Timber.w(new RuntimeException( "Unable to bankdroidify exception of class: " + ultimateCause.getClass())); return; } fakeCause.setStackTrace(concatArrays(bankdroidifiedStacktrace, fakeCause.getStackTrace())); ultimateCause.initCause(fakeCause); } }
ExceptionUtils { public static void blameBankdroid(Throwable exception) { Throwable ultimateCause = getUltimateCause(exception); if (ultimateCause == null) { return; } StackTraceElement[] bankdroidifiedStacktrace = bankdroidifyStacktrace(ultimateCause.getStackTrace()); if (bankdroidifiedStacktrace.length == 0) { return; } if (bankdroidifiedStacktrace.length == ultimateCause.getStackTrace().length) { return; } Throwable fakeCause = cloneException(ultimateCause); if (fakeCause == null) { Timber.w(new RuntimeException( "Unable to bankdroidify exception of class: " + ultimateCause.getClass())); return; } fakeCause.setStackTrace(concatArrays(bankdroidifiedStacktrace, fakeCause.getStackTrace())); ultimateCause.initCause(fakeCause); }  }
ExceptionUtils { public static void blameBankdroid(Throwable exception) { Throwable ultimateCause = getUltimateCause(exception); if (ultimateCause == null) { return; } StackTraceElement[] bankdroidifiedStacktrace = bankdroidifyStacktrace(ultimateCause.getStackTrace()); if (bankdroidifiedStacktrace.length == 0) { return; } if (bankdroidifiedStacktrace.length == ultimateCause.getStackTrace().length) { return; } Throwable fakeCause = cloneException(ultimateCause); if (fakeCause == null) { Timber.w(new RuntimeException( "Unable to bankdroidify exception of class: " + ultimateCause.getClass())); return; } fakeCause.setStackTrace(concatArrays(bankdroidifiedStacktrace, fakeCause.getStackTrace())); ultimateCause.initCause(fakeCause); }  static void blameBankdroid(Throwable exception); }
ExceptionUtils { public static void blameBankdroid(Throwable exception) { Throwable ultimateCause = getUltimateCause(exception); if (ultimateCause == null) { return; } StackTraceElement[] bankdroidifiedStacktrace = bankdroidifyStacktrace(ultimateCause.getStackTrace()); if (bankdroidifiedStacktrace.length == 0) { return; } if (bankdroidifiedStacktrace.length == ultimateCause.getStackTrace().length) { return; } Throwable fakeCause = cloneException(ultimateCause); if (fakeCause == null) { Timber.w(new RuntimeException( "Unable to bankdroidify exception of class: " + ultimateCause.getClass())); return; } fakeCause.setStackTrace(concatArrays(bankdroidifiedStacktrace, fakeCause.getStackTrace())); ultimateCause.initCause(fakeCause); }  static void blameBankdroid(Throwable exception);  }