cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r291771 - /cocoon/trunk/src/java/org/apache/cocoon/util/location/LocatedException.java
Date Mon, 26 Sep 2005 22:33:04 GMT
Author: vgritsenko
Date: Mon Sep 26 15:32:55 2005
New Revision: 291771

URL: http://svn.apache.org/viewcvs?rev=291771&view=rev
Log:
remove reflection: trunk is java 1.4 only.

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/util/location/LocatedException.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/util/location/LocatedException.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/util/location/LocatedException.java?rev=291771&r1=291770&r2=291771&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/util/location/LocatedException.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/util/location/LocatedException.java Mon Sep 26
15:32:55 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,7 +15,6 @@
  */
 package org.apache.cocoon.util.location;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -23,69 +22,53 @@
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.commons.lang.exception.NestableException;
 
-
 /**
  * A cascading and located <code>Exception</code>. It is also {@link MultiLocatable}
to easily build
  * stack traces.
- * 
+ *
  * @since 2.1.8
  * @version $Id$
  */
-public class LocatedException extends NestableException implements LocatableException, MultiLocatable
{
+public class LocatedException extends NestableException
+                              implements LocatableException, MultiLocatable {
 
     private List locations;
 
     public LocatedException(String message) {
         this(message, null, null);
     }
-    
+
     public LocatedException(String message, Throwable cause) {
         this(message, cause, null);
     }
-    
+
     public LocatedException(String message, Location location) {
         this(message, null, location);
     }
-    
+
     public LocatedException(String message, Throwable cause, Location location) {
         super(message, cause);
         ensureCauseChainIsSet(cause);
         addCauseLocations(this, cause);
         addLocation(location);
     }
-    
-    private static Method INIT_CAUSE_METHOD = null;
-    static {
-        try {
-            INIT_CAUSE_METHOD = Throwable.class.getMethod("initCause", new Class[] { Throwable.class}
);
-        } catch(Exception e) {
-            // JDK < 1.4: ignore
-        }
-    }
-    
+
     /**
-     * Crawl the cause chain and ensure causes are properly set using "initCause" on JDK
>= 1.4.
-     * This is needed because some exceptions (e.g. SAXException) don't have a getCause()
that is
-     * used to print stacktraces.
+     * Crawl the cause chain and ensure causes are properly set using {@ link Throwable#initCause}.
+     * This is needed because some exceptions (e.g. SAXException) don't have a {@ link Throwable#getCause}
+     * that is used to print stacktraces.
      */
     public static void ensureCauseChainIsSet(Throwable thr) {
-        if (INIT_CAUSE_METHOD == null)
-            return;
-        
         // Loop either until null or encountering exceptions that use this method.
-        while(thr != null && !(thr instanceof LocatedRuntimeException) &&
!(thr instanceof LocatedException)) {
+        while (thr != null && !(thr instanceof LocatedRuntimeException) &&
!(thr instanceof LocatedException)) {
             Throwable parent = ExceptionUtils.getCause(thr);
-            if (parent != null) {
-                try {
-                    INIT_CAUSE_METHOD.invoke(thr, new Object[]{ parent });
-                } catch(Exception e) {
-                    // can happen if parent already set on exception
-                }
+            if (thr.getCause() == null && parent != null) {
+                thr.initCause(parent);
             }
             thr = parent;
         }
     }
-    
+
     /**
      * Add to the location stack all locations of an exception chain. This allows to have
all possible
      * location information in the stacktrace, as some exceptions like SAXParseException
don't output
@@ -96,7 +79,7 @@
      * <p>
      * This method is static as a convenience for {@link LocatedRuntimeException other implementations}
      * of locatable exceptions.
-     * 
+     *
      * @param self the current locatable exception
      * @param cause a cause of <code>self</code>
      */
@@ -136,10 +119,10 @@
     /**
      * Standard way of building the message of a {@link LocatableException}, as a Java-like
      * stack trace of locations.
-     * 
+     *
      * @param message the exception's message, given by <code>super.getMessage()</code>
(can be null)
      * @param locations the location list (can be null)
-     * 
+     *
      * @return the message, or <code>null</code> no message and locations were
given.
      */
     public static String getMessage(String message, List locations) {
@@ -158,7 +141,7 @@
     public String getMessage() {
         return getMessage(super.getMessage(), locations);
     }
-    
+
     public void addLocation(Location loc) {
         if (LocationUtils.isUnknown(loc))
             return;



Mime
View raw message