Revision: 1509
Author: sberlin
Date: Mon Feb 28 07:08:01 2011
Log: update stack trace pruning (for AOP-internal methods & generated
methods) to include causes.
http://code.google.com/p/google-guice/source/detail?r=1509
Modified:
/trunk/core/src/com/google/inject/internal/InterceptorStackCallback.java
/trunk/core/test/com/google/inject/MethodInterceptionTest.java
=======================================
---
/trunk/core/src/com/google/inject/internal/InterceptorStackCallback.java
Fri Jan 14 23:06:25 2011
+++
/trunk/core/src/com/google/inject/internal/InterceptorStackCallback.java
Mon Feb 28 07:08:01 2011
@@ -99,17 +99,19 @@
/**
* Removes stacktrace elements related to AOP internal mechanics from the
- * throwable's stack trace.
+ * throwable's stack trace and any causes it may have.
*/
private void pruneStacktrace(Throwable throwable) {
- StackTraceElement[] stackTrace = throwable.getStackTrace();
- List<StackTraceElement> pruned = Lists.newArrayList();
- for (StackTraceElement element : stackTrace) {
- String className = element.getClassName();
- if (!AOP_INTERNAL_CLASSES.contains(className)
&& !className.contains("$EnhancerByGuice$")) {
- pruned.add(element);
- }
- }
- throwable.setStackTrace(pruned.toArray(new
StackTraceElement[pruned.size()]));
+ for(Throwable t = throwable; t != null; t = t.getCause()) {
+ StackTraceElement[] stackTrace = t.getStackTrace();
+ List<StackTraceElement> pruned = Lists.newArrayList();
+ for (StackTraceElement element : stackTrace) {
+ String className = element.getClassName();
+ if (!AOP_INTERNAL_CLASSES.contains(className)
&& !className.contains("$EnhancerByGuice$")) {
+ pruned.add(element);
+ }
+ }
+ t.setStackTrace(pruned.toArray(new
StackTraceElement[pruned.size()]));
+ }
}
}
=======================================
--- /trunk/core/test/com/google/inject/MethodInterceptionTest.java Tue Jan
18 11:41:12 2011
+++ /trunk/core/test/com/google/inject/MethodInterceptionTest.java Mon Feb
28 07:08:01 2011
@@ -171,11 +171,14 @@
interceptable.explode();
fail();
} catch (Exception e) {
- StackTraceElement[] stackTraceElement = e.getStackTrace();
- assertEquals("explode", stackTraceElement[0].getMethodName());
- assertEquals("invoke", stackTraceElement[1].getMethodName());
- assertEquals("invoke", stackTraceElement[2].getMethodName());
- assertEquals("testInterceptedMethodThrows",
stackTraceElement[3].getMethodName());
+ // validate all causes.
+ for (Throwable t = e; t != null; t = e.getCause()) {
+ StackTraceElement[] stackTraceElement = t.getStackTrace();
+ assertEquals("explode", stackTraceElement[0].getMethodName());
+ assertEquals("invoke", stackTraceElement[1].getMethodName());
+ assertEquals("invoke", stackTraceElement[2].getMethodName());
+ assertEquals("testInterceptedMethodThrows",
stackTraceElement[3].getMethodName());
+ }
}
}
@@ -226,7 +229,7 @@
}
public String explode() throws Exception {
lastElements = Thread.currentThread().getStackTrace();
- throw new Exception("kaboom!");
+ throw new Exception("kaboom!", new RuntimeException("boom!"));
}
}
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.