List of usage examples for java.lang Throwable setStackTrace
public void setStackTrace(StackTraceElement[] stackTrace)
From source file:org.mule.config.ExceptionHelper.java
/** * Removes some internal Mule entries from the stacktrace. Modifies the * passed-in throwable stacktrace./*from www . j ava2s . co m*/ */ public static Throwable sanitize(Throwable t) { if (t == null) { return null; } StackTraceElement[] trace = t.getStackTrace(); List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement stackTraceElement : trace) { if (!isMuleInternalClass(stackTraceElement.getClassName())) { newTrace.add(stackTraceElement); } } StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); Throwable cause = t.getCause(); while (cause != null) { sanitize(cause); cause = cause.getCause(); } return t; }
From source file:StackTraceHelper.java
/** * Removes the AspectWerkz specific elements from the stack trace. * * @param exception the Throwable to modify the stack trace on * @param className the name of the fake origin class of the exception *///from w w w.j av a 2 s. c o m public static void hideFrameworkSpecificStackTrace(final Throwable exception, final String className) { if (exception == null) { throw new IllegalArgumentException("exception can not be null"); } if (className == null) { throw new IllegalArgumentException("class name can not be null"); } final List newStackTraceList = new ArrayList(); final StackTraceElement[] stackTrace = exception.getStackTrace(); int i; for (i = 1; i < stackTrace.length; i++) { if (stackTrace[i].getClassName().equals(className)) { break; } } for (int j = i; j < stackTrace.length; j++) { newStackTraceList.add(stackTrace[j]); } final StackTraceElement[] newStackTrace = new StackTraceElement[newStackTraceList.size()]; int k = 0; for (Iterator it = newStackTraceList.iterator(); it.hasNext(); k++) { final StackTraceElement element = (StackTraceElement) it.next(); newStackTrace[k] = element; } exception.setStackTrace(newStackTrace); }
From source file:org.objectweb.proactive.core.body.future.ContextAwareMethodCallResult.java
/** * @param result the method call's result * @param exception the exception thrown during the method call execution */// w w w. j av a2 s .c o m public ContextAwareMethodCallResult(Object result, Throwable exception, StackTraceElement[] context) { super(result, exception); if (exception != null && context != null) { StackTraceElement[] stack = ArrayUtils.addAll(exception.getStackTrace(), context); exception.setStackTrace(stack); } }
From source file:com.hazelcast.stabilizer.Utils.java
public static void fixRemoteStackTrace(Throwable remoteCause, StackTraceElement[] localSideStackTrace) { StackTraceElement[] remoteStackTrace = remoteCause.getStackTrace(); StackTraceElement[] newStackTrace = new StackTraceElement[localSideStackTrace.length + remoteStackTrace.length];//from ww w . j av a2 s . c om System.arraycopy(remoteStackTrace, 0, newStackTrace, 0, remoteStackTrace.length); newStackTrace[remoteStackTrace.length] = new StackTraceElement(EXCEPTION_SEPARATOR, "", null, -1); System.arraycopy(localSideStackTrace, 1, newStackTrace, remoteStackTrace.length + 1, localSideStackTrace.length - 1); remoteCause.setStackTrace(newStackTrace); }
From source file:com.thoughtworks.go.plugin.infra.service.DefaultPluginLoggingServiceIntegrationTest.java
@Test public void shouldLogThrowableDetailsAlongwithMessage() throws Exception { Throwable throwable = new RuntimeException("oops"); throwable.setStackTrace(new StackTraceElement[] { new StackTraceElement("class", "method", "field", 20) }); pluginLoggingService.error(pluginID(1), "LoggingClass", "error", throwable); assertMessageInLog(pluginLog(1), "ERROR", "LoggingClass", "error", "java\\.lang\\.RuntimeException:\\soops[\\s\\S]*at\\sclass\\.method\\(field:20\\)[\\s\\S]*$"); }
From source file:org.gradle.initialization.ExceptionDecoratingClassGenerator.java
public <T> T newInstance(Class<T> type, Object... parameters) { Throwable throwable = ReflectionUtil.newInstance(generate(type), parameters); throwable.setStackTrace(((Throwable) parameters[0]).getStackTrace()); return type.cast(throwable); }
From source file:griffon.util.GriffonUtil.java
/** * <p>Remove all apparently Griffon-internal trace entries from the exception instance<p> * <p>This modifies the original instance and returns it, it does not clone</p> * @param t//from w w w . j a v a2s . c o m * @return The exception passed in, after cleaning the stack trace */ public static Throwable sanitize(Throwable t) { // Note that this getProperty access may well be synced... if (!Boolean.valueOf(System.getProperty("griffon.full.stacktrace")).booleanValue()) { StackTraceElement[] trace = t.getStackTrace(); List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); for (int i = 0; i < trace.length; i++) { StackTraceElement stackTraceElement = trace[i]; if (isApplicationClass(stackTraceElement.getClassName())) { newTrace.add(stackTraceElement); } } // Only trim the trace if there was some application trace on the stack // if not we will just skip sanitizing and leave it as is if (newTrace.size() > 0) { // We don't want to lose anything, so log it STACK_LOG.error("Sanitizing stacktrace:", t); StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); } } return t; }
From source file:org.eclipse.epp.internal.logging.aeri.ui.log.StandInStacktraceProvider.java
public void insertStandInStacktraceIfEmpty(final Status status, ServerConfiguration configuration) { if (requiresStandInStacktrace(status)) { Throwable syntetic = new StandInException(STAND_IN_MESSAGE); syntetic.fillInStackTrace();/*from w w w .ja va 2 s .c o m*/ StackTraceElement[] stacktrace = syntetic.getStackTrace(); StackTraceElement[] clearedStacktrace = clearBlacklistedTopStackframes(stacktrace, Constants.STAND_IN_STACKTRACE_BLACKLIST); syntetic.setStackTrace(clearedStacktrace); status.setException(Reports.newThrowable(syntetic)); status.setFingerprint(computeFingerprintFor(status, configuration)); } }
From source file:com.elusive_code.newsboy.EventNotifierTask.java
private void updateStackTrace(Throwable ex) { if (eventStackTrace == null) return;//from w ww .ja v a2 s . c om try { StackTraceElement[] stack1 = ex.getStackTrace(); StackTraceElement[] stack2 = eventStackTrace.getStackTrace(); StackTraceElement[] result = ArrayUtils.addAll(stack1, stack2); ex.setStackTrace(result); } catch (Throwable t) { LOG.log(Level.FINE, "Failed to update stack trace for " + ex, t); } }
From source file:org.topazproject.otm.impl.SessionImpl.java
private static Throwable trimStackTrace(Throwable t, int offset, int levels) { StackTraceElement[] trace = t.getStackTrace(); if (trace.length > offset) { if ((trace.length - offset) < levels) levels = trace.length - offset; StackTraceElement[] copy = new StackTraceElement[levels]; System.arraycopy(trace, offset, copy, 0, levels); t.setStackTrace(copy); }/*from w ww .ja v a 2 s . co m*/ return t; }