JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Use Agile By Default
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile Access more options (Alt+g)
  • Create Issue
  • Mule
  • MULE-4924

Exception strategy invoked twice on TransactionTemplate

  • Agile Board
  • More Actions
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.2.5 (EE only)
  • Fix Version/s: 2.2.6 (EE only), 3.0.0
  • Component/s: Core: Exception Handling
  • Labels:
    None
  • User impact:
    Low
  • Similar Issues:
    None

Description

The exceptions handled by the TransactionTemplate can be doubly handled if, despite having an ExceptionListener, they are not in a transaction.

Issue Links

relates to

Bug - A problem which impairs or prevents the functions of the product. MULE-4955 Refactor Exception Strategy invocation so we don't get exception strategies invoked twice

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Transitions
  • Commits
  • Source
  • Builds
Hide
Permalink
Edu Pereda added a comment - 30/Jun/10 11:34 AM

This issue was detected on EE-1968.

Show
Edu Pereda added a comment - 30/Jun/10 11:34 AM This issue was detected on EE-1968.
Hide
Permalink
Edu Pereda added a comment - 30/Jun/10 11:38 AM

This is a proposed fix that would avoid the double call to the exception handler.

It means that the TransactionTemplate will only handle the exception if it has an exceptionListener AND it has a transaction, otherwise, the exception is rethrown. If it is handled, then it won't be rethrown.

It was committed on http://fisheye.codehaus.org/changelog/mule/?cs=17753 for 2.2.x

Index: core/src/main/java/org/mule/transaction/TransactionTemplate.java
===================================================================
--- core/src/main/java/org/mule/transaction/TransactionTemplate.java	(revision 17734)
+++ core/src/main/java/org/mule/transaction/TransactionTemplate.java	(working copy)
@@ -10,8 +10,6 @@
 
 package org.mule.transaction;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.mule.api.MuleContext;
 import org.mule.api.transaction.ExternalTransactionAwareTransactionFactory;
 import org.mule.api.transaction.Transaction;
@@ -23,6 +21,9 @@
 
 import java.beans.ExceptionListener;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 public class TransactionTemplate
 {
     private static final Log logger = LogFactory.getLog(TransactionTemplate.class);
@@ -130,7 +131,7 @@
         catch (Exception e)
         {
             tx = TransactionCoordination.getInstance().getTransaction();
-            if (exceptionListener != null)
+            if (isExceptionHandledAtThisLevel(tx))
             {
                 logger.info("Exception Caught in Transaction template.  Handing off to exception handler: "
                     + exceptionListener);
@@ -163,9 +164,10 @@
                 // the context delimited by XA's ALWAYS_BEGIN
                 return null;
             }
-            else if (exceptionListener != null && tx != null)
+            else if (isExceptionHandledAtThisLevel(tx))
             {
-                // if there's an exception listener, it has been handled already, don't loop
+                // if exception is handled at this level, it has been handled
+                // already, don't loop
                 return null;
             }
             else
@@ -189,6 +191,18 @@
         }
     }
 
+    /**
+     * The exception must be handled at this level if there is an
+     * {@link #exceptionListener} and there is a transaction.
+     * 
+     * @param tx
+     * @return
+     */
+    protected boolean isExceptionHandledAtThisLevel(Transaction tx)
+    {
+        return exceptionListener != null && tx != null;
+    }
+
     protected void resolveTransaction(Transaction tx) throws TransactionException
     {
         if (tx.isRollbackOnly())
Show
Edu Pereda added a comment - 30/Jun/10 11:38 AM This is a proposed fix that would avoid the double call to the exception handler. It means that the TransactionTemplate will only handle the exception if it has an exceptionListener AND it has a transaction, otherwise, the exception is rethrown. If it is handled, then it won't be rethrown. It was committed on http://fisheye.codehaus.org/changelog/mule/?cs=17753 for 2.2.x
Index: core/src/main/java/org/mule/transaction/TransactionTemplate.java
===================================================================
--- core/src/main/java/org/mule/transaction/TransactionTemplate.java	(revision 17734)
+++ core/src/main/java/org/mule/transaction/TransactionTemplate.java	(working copy)
@@ -10,8 +10,6 @@
 
 package org.mule.transaction;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.mule.api.MuleContext;
 import org.mule.api.transaction.ExternalTransactionAwareTransactionFactory;
 import org.mule.api.transaction.Transaction;
@@ -23,6 +21,9 @@
 
 import java.beans.ExceptionListener;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 public class TransactionTemplate
 {
     private static final Log logger = LogFactory.getLog(TransactionTemplate.class);
@@ -130,7 +131,7 @@
         catch (Exception e)
         {
             tx = TransactionCoordination.getInstance().getTransaction();
-            if (exceptionListener != null)
+            if (isExceptionHandledAtThisLevel(tx))
             {
                 logger.info("Exception Caught in Transaction template.  Handing off to exception handler: "
                     + exceptionListener);
@@ -163,9 +164,10 @@
                 // the context delimited by XA's ALWAYS_BEGIN
                 return null;
             }
-            else if (exceptionListener != null && tx != null)
+            else if (isExceptionHandledAtThisLevel(tx))
             {
-                // if there's an exception listener, it has been handled already, don't loop
+                // if exception is handled at this level, it has been handled
+                // already, don't loop
                 return null;
             }
             else
@@ -189,6 +191,18 @@
         }
     }
 
+    /**
+     * The exception must be handled at this level if there is an
+     * {@link #exceptionListener} and there is a transaction.
+     * 
+     * @param tx
+     * @return
+     */
+    protected boolean isExceptionHandledAtThisLevel(Transaction tx)
+    {
+        return exceptionListener != null && tx != null;
+    }
+
     protected void resolveTransaction(Transaction tx) throws TransactionException
     {
         if (tx.isRollbackOnly())
Hide
Permalink
Edu Pereda added a comment - 02/Jul/10 08:21 AM

Added this small change: http://fisheye.codehaus.org/changelog/mule/?cs=17812

Show
Edu Pereda added a comment - 02/Jul/10 08:21 AM Added this small change: http://fisheye.codehaus.org/changelog/mule/?cs=17812
Hide
Permalink
Edu Pereda added a comment - 15/Jul/10 09:51 AM

This is fixed on 2.2.x (it will be out in 2.2.6).

I am not closing this until we merge it to 3.x.

Show
Edu Pereda added a comment - 15/Jul/10 09:51 AM This is fixed on 2.2.x (it will be out in 2.2.6). I am not closing this until we merge it to 3.x.
Hide
Permalink
Edu Pereda added a comment - 15/Sep/10 03:02 PM

Merged to 3.x:
http://fisheye.codehaus.org/changelog/mule/?cs=17830

Closing.

Show
Edu Pereda added a comment - 15/Sep/10 03:02 PM Merged to 3.x: http://fisheye.codehaus.org/changelog/mule/?cs=17830 Closing.

People

  • Assignee:
    Edu Pereda
    Reporter:
    Edu Pereda
Vote (0)
Watch (0)

Dates

  • Created:
    30/Jun/10 11:33 AM
    Updated:
    15/Sep/10 03:02 PM
    Resolved:
    15/Sep/10 03:02 PM

Agile

  • View on Board
  • Atlassian JIRA (v5.0.7#734-sha1:8ad78a6)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for MuleForge. Try JIRA - bug tracking software for your team.