Yukio Suzuki created WW-5414: -------------------------------- Summary: AfterInvocation of BackgroundProcess is not called when an exception occurs when using ExecuteAndWaitInterceptor Key: WW-5414 URL: https://issues.apache.org/jira/browse/WW-5414 Project: Struts 2 Issue Type: Bug Components: Core Interceptors Affects Versions: 6.3.0, 2.5.30 Reporter: Yukio Suzuki
In my project, we are using Struts2.5.x and recently started using the ExecuteAndWaitInterceptor. We have extended BackgroundProcess and overridden the beforeInvocation and afterInvocation methods to perform certain actions before and after the invocation of an action. However, we are facing a problem where afterInvocation is not called when an exception occurs. Here is the relevant code: {code:java} final Thread t = new Thread(new Runnable() { public void run() { try { beforeInvocation(); result = invocation.invokeActionOnly(); afterInvocation(); } catch (Exception e) { exception = e; } done = true; } }); {code} In the existing code, the beforeInvocation and afterInvocation methods set and clear the context, but it seems unintentional that the context is not cleared when an exception occurs. {code:java} protected void beforeInvocation() throws Exception { ActionContext.setContext(invocation.getInvocationContext()); } protected void afterInvocation() throws Exception { ActionContext.setContext(null); }{code} One possible improvement is to modify the code as follows, ensuring that afterInvocation is called even when an exception occurs: {code:java} beforeInvocation(); try { result = invocation.invokeActionOnly(); } finally { afterInvocation(); }{code} Alternatively, if compatibility is a concern, you can add an afterInvocation(Throwable t) method and modify the code as follows: {code:java} beforeInvocation(); try { result = invocation.invokeActionOnly(); } catch (Throwable t) { afterInvocation(t); throw t; } beforeInvocation();{code} Please consider these modifications to ensure that afterInvocation is called even when an exception occurs. -- This message was sent by Atlassian Jira (v8.20.10#820010)