[ https://issues.apache.org/jira/browse/WW-5414?focusedWorklogId=922073&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-922073 ]
ASF GitHub Bot logged work on WW-5414: -------------------------------------- Author: ASF GitHub Bot Created on: 05/Jun/24 05:36 Start Date: 05/Jun/24 05:36 Worklog Time Spent: 10m Work Description: lukaszlenart opened a new pull request, #955: URL: https://github.com/apache/struts/pull/955 Small refactoring of how `CspSettings` class is created plus additional tests. Refs [WW-5414](https://issues.apache.org/jira/browse/WW-5414) Issue Time Tracking ------------------- Worklog Id: (was: 922073) Time Spent: 2h (was: 1h 50m) > 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: 2.5.30, 6.3.0 > Reporter: Yukio Suzuki > Assignee: Lukasz Lenart > Priority: Major > Fix For: 6.5.0 > > Time Spent: 2h > Remaining Estimate: 0h > > 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; > } > afterInvocation();{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)