public LegacyCodeCause() { stackTrace = new Exception().getStackTrace(); }
/** * Returns current stack trace in form of array of stack trace elements. * First stack trace element is removed. * Since an exception is thrown internally, this method is slow. */ @SuppressWarnings({"ThrowCaughtLocally"}) public static StackTraceElement[] getCurrentStackTrace() { StackTraceElement[] ste = new Exception().getStackTrace(); if (ste.length > 1) { StackTraceElement[] result = new StackTraceElement[ste.length - 1]; System.arraycopy(ste, 1, result, 0, ste.length - 1); return result; } else { return ste; } }
private static Exception throwCause(Exception e, boolean combineStackTraces) throws Exception { Throwable cause = e.getCause(); if (cause == null) { throw e; } if (combineStackTraces) { StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class); cause.setStackTrace(combined); } if (cause instanceof Exception) { throw (Exception) cause; } if (cause instanceof Error) { throw (Error) cause; } // The cause is a weird kind of Throwable, so throw the outer exception. throw e; }
public static String getExceptionMessage(Exception ex) { String result = ""; StackTraceElement[] stes = ex.getStackTrace(); for (int i = 0; i < stes.length; i++) { result = result + stes[i].getClassName() + "." + stes[i].getMethodName() + " " + stes[i].getLineNumber() + "line" + "\r\n"; } return result; }
public HTTP500V1( Exception e ) { error = e.getClass().getSimpleName()+": "+e.getMessage(); stackTrace = Arrays.toString(e.getStackTrace()); } @Override public HTTP500V1 fillInto( Handler h ) { throw H2O.fail(); }
EpoxyProcessorException(Exception e, String message) { super(message, e); setStackTrace(e.getStackTrace()); }
public static void addDeveloperErrorMessage(Map jsonMap, Exception e) { addFriendlyErrorMessage(jsonMap, e.getMessage() + ": " + e.getCause() + " at " + e.getStackTrace()[0]); }
private static Exception throwCause(Exception e, boolean combineStackTraces) throws Exception { Throwable cause = e.getCause(); if (cause == null) { throw e; } if (combineStackTraces) { StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class); cause.setStackTrace(combined); } if (cause instanceof Exception) { throw (Exception) cause; } if (cause instanceof Error) { throw (Error) cause; } // The cause is a weird kind of Throwable, so throw the outer exception. throw e; }
private Exception newPlainException(Exception e) { String type = e.getClass().getName(); if(type.startsWith("java.") || type.startsWith("javax.")) { return e; } else { Exception result = new Exception(e.getMessage()); result.setStackTrace(e.getStackTrace()); return result; } }
private static <T extends Throwable> T copyContents(final Exception source, final T throwable) { throwable.setStackTrace(source.getStackTrace()); final Throwable[] suppressed = source.getSuppressed(); if (suppressed != null) for (final Throwable t : suppressed) { throwable.addSuppressed(t); } return throwable; } }
public static void POST(int n, Exception e) { if (e.getMessage() != null) { POST(n, e.getMessage()); } POST(n, e.toString()); StackTraceElement[] els = e.getStackTrace(); for (int i = 0; i < els.length; i++) { POST(n, els[i].toString()); } } public static void POST(int n) {
@Test public void fillInClientStackTraceIfPossibleSunnyDay() throws Exception { try { throw new IllegalStateException("Mmm"); } catch (Exception ex) { int originalStackTraceLngth = ex.getStackTrace().length; RemoteInvocationUtils.fillInClientStackTraceIfPossible(ex); assertTrue("Stack trace not being filled in", ex.getStackTrace().length > originalStackTraceLngth); } }
StackTraceElement[] callStack = new Exception().getStackTrace(); StackTraceElement[] cachedCallStack = exception.getStackTrace();
protected void afterAsyncTestBase() { if (throwable != null && thrownThread != Thread.currentThread() && !awaitCalled) { // Throwable caught from non main thread throw new IllegalStateException("Assert or failure from non main thread but no await() on main thread", throwable); } if (lateFailure) { throw new IllegalStateException("Test reported a failure after completion"); } for (Map.Entry<String, Exception> entry: threadNames.entrySet()) { if (!entry.getKey().equals(mainThreadName)) { if (threadChecksEnabled && !entry.getKey().startsWith("vert.x-")) { IllegalStateException is = new IllegalStateException("Non Vert.x thread! :" + entry.getKey()); is.setStackTrace(entry.getValue().getStackTrace()); throw is; } } } }
public static RuntimeException translateException(String msg, Exception cause) { RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage())); runtimeException.setStackTrace(cause.getStackTrace()); return runtimeException; }
static void debugTrace() { if (LOG.isDebugEnabled()){ Exception e = new Exception(); LOG.debug("." + e.getStackTrace()[1].getLineNumber() + ":" + TestObjectStoreInitRetry.getInjectConnectFailure()); } }
void cleanAndResetToMaster() throws IOException { try { git.reset().setMode(ResetCommand.ResetType.HARD).call(); checkout("master"); deleteBranch(BRANCH_AT_REVISION); deleteBranch(BRANCH_AT_HEAD); } catch (Exception e) { String currentBranch = git.getRepository().getBranch(); LOGGER.error("Error while trying to clean up config repository, CurrentBranch: {} \n : \n Message: {} \n StackTrace: {}", currentBranch, e.getMessage(), e.getStackTrace(), e); throw new RuntimeException(e); } }
@Test public void findMethodAnnotationOnBridgeMethod() throws Exception { Method bridgeMethod = SimpleFoo.class.getMethod("something", Object.class); assertTrue(bridgeMethod.isBridge()); assertNull(bridgeMethod.getAnnotation(Order.class)); assertNull(getAnnotation(bridgeMethod, Order.class)); assertNotNull(findAnnotation(bridgeMethod, Order.class)); boolean runningInEclipse = Arrays.stream(new Exception().getStackTrace()) .anyMatch(element -> element.getClassName().startsWith("org.eclipse.jdt")); // As of JDK 8, invoking getAnnotation() on a bridge method actually finds an // annotation on its 'bridged' method [1]; however, the Eclipse compiler will not // support this until Eclipse 4.9 [2]. Thus, we effectively ignore the following // assertion if the test is currently executing within the Eclipse IDE. // // [1] https://bugs.openjdk.java.net/browse/JDK-6695379 // [2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=495396 // if (!runningInEclipse) { assertNotNull(bridgeMethod.getAnnotation(Transactional.class)); } assertNotNull(getAnnotation(bridgeMethod, Transactional.class)); assertNotNull(findAnnotation(bridgeMethod, Transactional.class)); }
@GwtIncompatible // lazyStackTrace private void doTestLazyStackTraceFallback() { assertFalse(lazyStackTraceIsLazy()); Exception e = new Exception(); assertThat(lazyStackTrace(e)).containsExactly((Object[]) e.getStackTrace()).inOrder(); try { lazyStackTrace(e).set(0, null); fail(); } catch (UnsupportedOperationException expected) { } e.setStackTrace(new StackTraceElement[0]); assertThat(lazyStackTrace(e)).isEmpty(); }
@GwtIncompatible // lazyStackTrace(Throwable) public void testLazyStackTrace() { Exception e = new Exception(); StackTraceElement[] originalStackTrace = e.getStackTrace(); assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder(); try { lazyStackTrace(e).set(0, null); fail(); } catch (UnsupportedOperationException expected) { } // Now we test a property that holds only for the lazy implementation. if (!lazyStackTraceIsLazy()) { return; } e.setStackTrace(new StackTraceElement[0]); assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder(); }