[ 
https://issues.apache.org/jira/browse/WW-5414?focusedWorklogId=922078&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-922078
 ]

ASF GitHub Bot logged work on WW-5414:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Jun/24 05:42
            Start Date: 05/Jun/24 05:42
    Worklog Time Spent: 10m 
      Work Description: sonarcloud[bot] commented on PR #955:
URL: https://github.com/apache/struts/pull/955#issuecomment-2148902161

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=955) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 New 
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=955&resolved=false&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=955&resolutions=WONTFIX)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=955&resolved=false&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [100.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=955&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=955&metric=new_duplicated_lines_density&view=list)
  
     
   [See analysis details on 
SonarCloud](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=955)
   
   




Issue Time Tracking
-------------------

    Worklog Id:     (was: 922078)
    Time Spent: 2h 20m  (was: 2h 10m)

> 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 20m
>  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)

Reply via email to