You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2007/07/27 13:53:32 UTC

svn commit: r560205 - /myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java

Author: mmarinschek
Date: Fri Jul 27 04:53:31 2007
New Revision: 560205

URL: http://svn.apache.org/viewvc?view=rev&rev=560205
Log:
https://issues.apache.org/jira/browse/MYFACES-1685: add portlet exception to special handling

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java?view=diff&rev=560205&r1=560204&r2=560205
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java Fri Jul 27 04:53:31 2007
@@ -33,6 +33,7 @@
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 import java.text.DateFormat;
 import java.util.Arrays;
 import java.util.Collection;
@@ -339,19 +340,23 @@
         if(ex==null)
             return;
 
+        //handle Servlet-Exceptions - long know for swallowing root-causes ;)
         if(ex instanceof ServletException) {
+            Throwable rootCause = ((ServletException) ex).getRootCause();
+            initCauseIfAvailable(ex,rootCause);
+        }
+        //handle portlet-exceptions - not much better in this regard
+        else if(ex.getClass().getName().equals("javax.portlet.PortletException")) {
             try
             {
-                Throwable rootCause = ((ServletException) ex).getRootCause();
-
-                if(rootCause != null) {
-                    Method m = ServletException.class.getMethod("initCause",new Class[]{Throwable.class});
-                    m.invoke(ex,new Object[]{rootCause});
-                }
+                Method causeGetter = ex.getClass().getMethod("getCause",new Class[]{});
+                Throwable rootCause = (Throwable) causeGetter.invoke(ex,new Class[]{});
+                initCauseIfAvailable(ex,rootCause);
             } catch (Exception e1) {
                 //ignore if the method is not found - or cause has already been set.
             }
         }
+        //add other exceptions which swallow to much as appropriate
 
         prepareExceptionStack(ex.getCause());
     }
@@ -379,14 +384,23 @@
                 ex=new ServletException(e);
             }
 
-            try {
-                Method m = ServletException.class.getMethod("initCause",new Class[]{Throwable.class});
-                m.invoke(ex,new Object[]{e});
-            } catch (Exception e1) {
-                //ignore if the method is not found - or cause has already been set.
-            }
+            initCauseIfAvailable(ex, e);
 
             throw ex;
+        }
+    }
+
+    private static void initCauseIfAvailable(Throwable th, Throwable cause) {
+
+        if(cause == null)
+            return;
+
+        try
+        {
+            Method m = Throwable.class.getMethod("initCause",new Class[]{Throwable.class});
+            m.invoke(th,new Object[]{cause});
+        }
+        catch(Exception e) {
         }
     }
 }