cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r232525 - in /cocoon/branches/BRANCH_2_1_X/src: java/org/apache/cocoon/util/location/ webapp/stylesheets/system/
Date Sat, 13 Aug 2005 21:21:08 GMT
Author: sylvain
Date: Sat Aug 13 14:20:59 2005
New Revision: 232525

URL: http://svn.apache.org/viewcvs?rev=232525&view=rev
Log:
Ensure all locations are in the stacktrace (e.g. SAXParseException does have a location but
does not print it)

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
    cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java?rev=232525&r1=232524&r2=232525&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
Sat Aug 13 14:20:59 2005
@@ -20,6 +20,7 @@
 import java.util.List;
 
 import org.apache.avalon.framework.CascadingException;
+import org.apache.cocoon.util.ExceptionUtils;
 
 /**
  * A cascading and located <code>Exception</code>. It is also {@link MultiLocatable}
to easily build
@@ -33,21 +34,50 @@
     private List locations;
 
     public LocatedException(String message) {
-        super(message, null);
+        this(message, null, null);
     }
     
-    public LocatedException(String message, Throwable thr) {
-        super(message, thr);
+    public LocatedException(String message, Throwable cause) {
+        this(message, cause, null);
     }
     
     public LocatedException(String message, Location location) {
-        super(message, null);
-        addLocation(location);
+        this(message, null, location);
     }
     
-    public LocatedException(String message, Throwable thr, Location location) {
-        super(message, thr);
+    public LocatedException(String message, Throwable cause, Location location) {
+        super(message, cause);
+        addCauseLocations(this, cause);
         addLocation(location);
+    }
+    
+    /**
+     * 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
+     * their location in printStackTrace().
+     * <p>
+     * Traversal of the call chain stops at the first <code>Locatable</code>
exception which is supposed
+     * to handle the loction of its causes by itself.
+     * <p>
+     * This method is static as a convenience for {@link LocatedRuntimeException other implementations}
+     * of locatable exceptions.
+     * 
+     * @param self the current locatable exception
+     * @param cause the cause of <code>self</code>
+     */
+    public static void addCauseLocations(MultiLocatable self, Throwable cause) {
+        if (cause == null || cause instanceof Locatable) {
+            // Locatable handles its location itself
+            return;
+        }
+        // Add parent location first
+        addCauseLocations(self, ExceptionUtils.getCause(cause));
+        // then ourselve's
+        Location loc = ExceptionUtils.getLocation(cause);
+        if (loc != null) {
+            loc = new LocationImpl("[cause location]", loc.getURI(), loc.getLineNumber(),
loc.getColumnNumber());
+            self.addLocation(loc);
+        }
     }
 
     public Location getLocation() {

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java?rev=232525&r1=232524&r2=232525&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
Sat Aug 13 14:20:59 2005
@@ -33,20 +33,21 @@
     private List locations;
 
     public LocatedRuntimeException(String message) {
-        super(message, null);
+        this(message, null, null);
     }
     
-    public LocatedRuntimeException(String message, Throwable thr) {
-        super(message, thr);
+    public LocatedRuntimeException(String message, Throwable cause) {
+        this(message, cause, null);
     }
     
     public LocatedRuntimeException(String message, Location location) {
-        super(message, null);
+        this(message, null, location);
         addLocation(location);
     }
     
-    public LocatedRuntimeException(String message, Throwable thr, Location location) {
-        super(message, thr);
+    public LocatedRuntimeException(String message, Throwable cause, Location location) {
+        super(message, cause);
+        LocatedException.addCauseLocations(this, cause);
         addLocation(location);
     }
 

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java?rev=232525&r1=232524&r2=232525&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java Sat
Aug 13 14:20:59 2005
@@ -30,7 +30,7 @@
     /**
      * Constant for unknown locations.
      */
-    public static final Location UNKNOWN = new LocationImpl(null, null);
+    public static final Location UNKNOWN = LocationImpl.UNKNOWN;
     
     /**
      * Get the description of this location

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java?rev=232525&r1=232524&r2=232525&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
Sat Aug 13 14:20:59 2005
@@ -30,6 +30,9 @@
     private final int line;
     private final int column;
     private final String description;
+    
+    // Package private: outside this package, use Location.UNKNOWN.
+    static final LocationImpl UNKNOWN = new LocationImpl(null, null);
 
     /**
      * The string representation of an unknown location: "<code>[unknown location]</code>".
@@ -92,7 +95,7 @@
         if (location instanceof LocationImpl) {
             return (LocationImpl)location;
         } else if (location == null) {
-            return (LocationImpl)Location.UNKNOWN;
+            return UNKNOWN;
         } else {
             return new LocationImpl(location);
         }
@@ -103,11 +106,11 @@
      * "<code>path/to/file.xml:3:40</code>") to a Location object.
      * 
      * @param text the text to parse
-     * @return the location
+     * @return the location (possibly UNKNOWN if text was null or in an incorrect format)
      */
-    public static LocationImpl valueOf(String text) {
+    public static LocationImpl valueOf(String text) throws IllegalArgumentException {
         if (text == null || text.length() == 0) {
-            return (LocationImpl)Location.UNKNOWN;
+            return UNKNOWN;
         }
 
         // Do we have a description?
@@ -138,10 +141,10 @@
                 }
             }
         } catch(Exception e) {
-            // Ignore: we throw another one below
+            // Ignore: handled below
         }
         
-        throw new IllegalArgumentException("Invalid location string: " + text);
+        return UNKNOWN;
     }
 
     /**

Modified: cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt?rev=232525&r1=232524&r2=232525&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt (original)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt Sat Aug
13 14:20:59 2005
@@ -82,8 +82,9 @@
                </xsl:for-each>
             </strong>
             <table>
-              <xsl:for-each select="ex:locations/*">
-                <!--xsl:sort select="position()" order="descending"/-->
+               <xsl:for-each select="ex:locations/*[string(.) != '[cause location]']">
+                 <!-- [cause location] indicates location of a cause, which 
+                      the exception generator outputs separately -->
                 <tr class="row-{position() mod 2}">
                    <td><xsl:call-template name="print-location"/></td>
                    <td><em><xsl:value-of select="."/></em></td>



Mime
View raw message