Author: hlship
Date: Thu Feb 22 16:57:35 2007
New Revision: 510738
URL: http://svn.apache.org/viewvc?view=rev&rev=510738
Log:
Filter out of stack traces any stack trace elements that are obviously runtime
generated proxies
Modified:
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionAnalyzerImpl.java
Modified:
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionAnalyzerImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionAnalyzerImpl.java?view=diff&rev=510738&r1=510737&r2=510738
==============================================================================
---
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionAnalyzerImpl.java
(original)
+++
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionAnalyzerImpl.java
Thu Feb 22 16:57:35 2007
@@ -12,100 +12,102 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.internal.services;
-
+package org.apache.tapestry.ioc.internal.services;
+
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry.ioc.services.ClassPropertyAdapter;
-import org.apache.tapestry.ioc.services.ExceptionAnalysis;
-import org.apache.tapestry.ioc.services.ExceptionAnalyzer;
-import org.apache.tapestry.ioc.services.ExceptionInfo;
-import org.apache.tapestry.ioc.services.PropertyAccess;
-
-/**
- *
- */
-public class ExceptionAnalyzerImpl implements ExceptionAnalyzer
-{
- private final PropertyAccess _propertyAccess;
-
- private final Set<String> _throwableProperties;
-
- public ExceptionAnalyzerImpl(PropertyAccess propertyAccess)
- {
- _propertyAccess = propertyAccess;
-
- _throwableProperties =
newSet(_propertyAccess.getAdapter(Throwable.class)
- .getPropertyNames());
- }
-
- public ExceptionAnalysis analyze(Throwable rootException)
- {
- List<ExceptionInfo> list = CollectionFactory.newList();
-
- Throwable t = rootException;
-
- while (t != null)
- {
- ExceptionInfo info = extractInfo(t);
-
- list.add(info);
-
- t = t.getCause();
- }
-
- return new ExceptionAnalysisImpl(list);
- }
-
- private ExceptionInfo extractInfo(Throwable t)
- {
- Map<String, Object> properties = newMap();
-
- ClassPropertyAdapter adapter = _propertyAccess.getAdapter(t);
-
- for (String name : adapter.getPropertyNames())
- {
- if (_throwableProperties.contains(name))
- continue;
-
- Object value = adapter.get(t, name);
-
- if (value == null)
- continue;
-
- // An interesting property, let's save it for the analysis.
-
- properties.put(name, value);
- }
-
- List<String> stackTrace = Collections.emptyList();
-
- // Usually, I'd use a terniary expression here, but Generics gets in
- // the way here.
-
- if (t.getCause() == null)
- stackTrace = extractStackTrace(t);
-
- return new ExceptionInfoImpl(t, properties, stackTrace);
- }
-
- private List<String> extractStackTrace(Throwable t)
- {
- List<String> trace = newList();
-
- for (StackTraceElement e : t.getStackTrace())
- {
- trace.add(e.toString());
- }
-
- return trace;
- }
-}
+import org.apache.tapestry.ioc.services.ClassPropertyAdapter;
+import org.apache.tapestry.ioc.services.ExceptionAnalysis;
+import org.apache.tapestry.ioc.services.ExceptionAnalyzer;
+import org.apache.tapestry.ioc.services.ExceptionInfo;
+import org.apache.tapestry.ioc.services.PropertyAccess;
+
+/**
+ *
+ */
+public class ExceptionAnalyzerImpl implements ExceptionAnalyzer
+{
+ private final PropertyAccess _propertyAccess;
+
+ private final Set<String> _throwableProperties;
+
+ public ExceptionAnalyzerImpl(PropertyAccess propertyAccess)
+ {
+ _propertyAccess = propertyAccess;
+
+ _throwableProperties =
newSet(_propertyAccess.getAdapter(Throwable.class)
+ .getPropertyNames());
+ }
+
+ public ExceptionAnalysis analyze(Throwable rootException)
+ {
+ List<ExceptionInfo> list = CollectionFactory.newList();
+
+ Throwable t = rootException;
+
+ while (t != null)
+ {
+ ExceptionInfo info = extractInfo(t);
+
+ list.add(info);
+
+ t = t.getCause();
+ }
+
+ return new ExceptionAnalysisImpl(list);
+ }
+
+ private ExceptionInfo extractInfo(Throwable t)
+ {
+ Map<String, Object> properties = newMap();
+
+ ClassPropertyAdapter adapter = _propertyAccess.getAdapter(t);
+
+ for (String name : adapter.getPropertyNames())
+ {
+ if (_throwableProperties.contains(name)) continue;
+
+ Object value = adapter.get(t, name);
+
+ if (value == null) continue;
+
+ // An interesting property, let's save it for the analysis.
+
+ properties.put(name, value);
+ }
+
+ List<String> stackTrace = Collections.emptyList();
+
+ // Usually, I'd use a terniary expression here, but Generics gets in
+ // the way here.
+
+ if (t.getCause() == null) stackTrace = extractStackTrace(t);
+
+ return new ExceptionInfoImpl(t, properties, stackTrace);
+ }
+
+ private List<String> extractStackTrace(Throwable t)
+ {
+ List<String> trace = newList();
+
+ for (StackTraceElement e : t.getStackTrace())
+ {
+ // Edit out IoC Proxy classes. They always start with a '$'
+ // and don't have any line number information.
+
+ if (e.getClassName().startsWith("$") && e.getLineNumber() < 0)
continue;
+
+ trace.add(e.toString());
+ }
+
+ return trace;
+ }
+}