Author: rich
Date: Mon Jun 20 08:09:12 2005
New Revision: 191486

URL: http://svn.apache.org/viewcvs?rev=191486&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/BEEHIVE-826 : Misleading secondary 
exception when an Error is thrown from an action

tests: bvt in netui (WinXP)
BB: self (linux)


Modified:
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java?rev=191486&r1=191485&r2=191486&view=diff
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
 Mon Jun 20 08:09:12 2005
@@ -1403,6 +1403,7 @@
             {
                 if ( ex instanceof ServletException ) throw ( ServletException 
) ex;
                 if ( ex instanceof IOException ) throw ( IOException ) ex;
+                if ( ex instanceof Error ) throw ( Error ) ex;
                 throw new ServletException( ex );
             }
             

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java?rev=191486&r1=191485&r2=191486&view=diff
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
 Mon Jun 20 08:09:12 2005
@@ -312,7 +312,11 @@
                             //
                             // If a Throwable escapes out of the page, let the 
current FlowController handle it.
                             //
-                            if ( ! handleException( th, curJpf, request, 
response ) ) throw new ServletException( th );
+                            if ( ! handleException( th, curJpf, request, 
response ) )
+                            {
+                                if ( th instanceof Error ) throw ( Error ) th;
+                                throw new ServletException( th );
+                            }
                         }
                         finally
                         {

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java?rev=191486&r1=191485&r2=191486&view=diff
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
 Mon Jun 20 08:09:12 2005
@@ -596,7 +596,7 @@
         catch ( UnhandledException unhandledException )
         {
             // If we get here, then we've already tried to find an exception 
handler.  Just throw.
-            throw unhandledException;
+            rethrowUnhandledException( unhandledException );
         }
         catch ( ServletException servletEx )
         {
@@ -611,7 +611,11 @@
         catch ( Throwable th )
         {
             // If a Throwable escapes out of any of the processing methods, 
let the current FlowController handle it.
-            if ( ! handleException( th, currentFlowController, request, 
response ) ) throw new ServletException( th );
+            if ( ! handleException( th, currentFlowController, request, 
response ) )
+            {
+                if ( th instanceof Error ) throw ( Error ) th;
+                throw new ServletException( th );
+            }
         }
     }
     
@@ -671,10 +675,19 @@
                 processForwardConfig( request, response, fwd );
                 return true;
             }
+            catch ( UnhandledException unhandledException )
+            {
+                if ( _log.isInfoEnabled() )
+                {
+                    _log.info( "This exception was unhandled by any exception 
handler.", unhandledException );
+                }
+                
+                return false;
+            }
             catch ( Throwable t )
             {
                 _log.error( "Exception while handling exception " + 
th.getClass().getName()
-                            + ".  The original exception will be thrown.", th 
);
+                            + ".  The original exception will be thrown.", t );
                 return false;
             }
         }
@@ -965,17 +978,47 @@
         return REDIRECT_REQUEST_ATTRS_PREFIX + hash + webappRelativeURI;
     }
     
+    private static final void rethrowUnhandledException( UnhandledException ex 
)
+        throws ServletException
+    {
+        Throwable rootCause = ex.getRootCause();
+        
+        //
+        // We shouldn't (and don't need to) wrap Errors or RuntimeExceptions.
+        //
+        if ( rootCause instanceof Error )
+        {
+            throw ( Error ) rootCause;
+        }
+        else if ( rootCause instanceof RuntimeException )
+        {
+            throw ( RuntimeException ) rootCause;
+        }
+        
+        throw ex;
+    }
+    
     public ActionForward processException( HttpServletRequest request, 
HttpServletResponse response,
                                            Exception ex, ActionForm form, 
ActionMapping mapping )
         throws IOException, ServletException
     {
         //
-        // Note: we should only get here if FlowController.handleException 
itself throws an exception,
-        // or if the user has merged in Struts code that delegates to an 
action/exception-handler outside
-        // of the pageflow.
+        // Note: we should only get here if FlowController.handleException 
itself throws an exception, or if the user
+        // has merged in Struts code that delegates to an 
action/exception-handler outside of the pageflow.
+        //
+        // If this is an UnhandledException thrown from 
FlowController.handleException, don't try to re-handle it here.
         //
         
-        return super.processException( request, response, ex, form, mapping );
+        if ( ex instanceof UnhandledException )
+        {
+            rethrowUnhandledException( ( UnhandledException ) ex );
+            assert false;   // rethrowUnhandledException always throws 
something.
+            return null;
+        }
+        else
+        {
+            return super.processException( request, response, ex, form, 
mapping );
+        }
     }
     
     /**


Reply via email to