[prev in list] [next in list] [prev in thread] [next in thread]
List: struts-dev
Subject: [jira] [Work logged] (WW-5414) AfterInvocation of BackgroundProcess is not called when an exception
From: "ASF GitHub Bot (Jira)" <jira () apache ! org>
Date: 2024-05-14 17:56:00
Message-ID: JIRA.13575785.1713146103000.77356.1715709360039 () Atlassian ! JIRA
[Download RAW message or body]
[ https://issues.apache.org/jira/browse/WW-5414?focusedWorklogId=919370&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-919370 \
]
ASF GitHub Bot logged work on WW-5414:
--------------------------------------
Author: ASF GitHub Bot
Created on: 14/May/24 17:55
Start Date: 14/May/24 17:55
Worklog Time Spent: 10m
Work Description: lukaszlenart merged PR #932:
URL: https://github.com/apache/struts/pull/932
Issue Time Tracking
-------------------
Worklog Id: (was: 919370)
Time Spent: 1h 50m (was: 1h 40m)
> 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: 1h 50m
> 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)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic