You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jc...@apache.org on 2005/09/06 05:40:11 UTC

svn commit: r278903 - /jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/ExecutorMethodInterceptor.java

Author: jcarman
Date: Mon Sep  5 20:40:08 2005
New Revision: 278903

URL: http://svn.apache.org/viewcvs?rev=278903&view=rev
Log:
Added special case for finalize() method.

Modified:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/ExecutorMethodInterceptor.java

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/ExecutorMethodInterceptor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/ExecutorMethodInterceptor.java?rev=278903&r1=278902&r2=278903&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/ExecutorMethodInterceptor.java (original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/ExecutorMethodInterceptor.java Mon Sep  5 20:40:08 2005
@@ -22,10 +22,12 @@
 
 /**
  * A method interceptor that uses an {@link Executor} to execute the method invocation.
- * <p />
- * <b>Note</b>: Only <em>void</em> methods can be intercepted using this class!  Any attempts to intercept
- * non-void methods will result in an {@link IllegalArgumentException}.  If the proxy interfaces include non-void
- * methods, try using a {@link FilteredMethodInterceptor} along with a {@link org.apache.commons.proxy.interceptor.filter.ReturnTypeFilter} to wrap an instance of this class.
+ * <p/>
+ * <b>Note</b>: Only <em>void</em> methods can be intercepted using this class!  Any attempts to intercept non-void
+ * methods will result in an {@link IllegalArgumentException}.  If the proxy interfaces include non-void methods, try
+ * using a {@link FilteredMethodInterceptor} along with a {@link org.apache.commons.proxy.interceptor.filter.ReturnTypeFilter}
+ * to wrap an instance of this class.
+ *
  * @author James Carman
  * @version 1.0
  */
@@ -42,21 +44,30 @@
     {
         if( Void.TYPE.equals( methodInvocation.getMethod().getReturnType() ) )
         {
-            executor.execute( new Runnable()
+            // Special case for finalize() method (should not be run in a different thread...
+            if( !( methodInvocation.getMethod().getName().equals( "finalize" ) &&
+                   methodInvocation.getMethod().getParameterTypes().length == 0 ) )
             {
-                public void run()
+                executor.execute( new Runnable()
                 {
-                    try
+                    public void run()
                     {
-                        methodInvocation.proceed();
+                        try
+                        {
+                            methodInvocation.proceed();
+                        }
+                        catch( Throwable t )
+                        {
+                            getLog().error( "Method invocation threw an exception.", t );
+                        }
                     }
-                    catch( Throwable t )
-                    {
-                        getLog().error( "Method invocation threw an exception.", t );
-                    }
-                }
-            } );
-            return null;
+                } );
+                return null;
+            }
+            else
+            {
+                return methodInvocation.proceed();
+            }
         }
         else
         {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org