]
Alejandro Guizar updated JBPM-2133:
-----------------------------------
Assignee: Alejandro Guizar
Fix Version/s: jBPM 3.2.10
Consider this proposal in future jBPM3 release.
Error handling in CommandServiceBean.execute
--------------------------------------------
Key: JBPM-2133
URL:
https://issues.jboss.org/browse/JBPM-2133
Project: jBPM
Issue Type: Patch
Security Level: Public(Everyone can see)
Affects Versions: jBPM 3.2.6.SP1
Environment: irrelevant
Reporter: Volker Börchers
Assignee: Alejandro Guizar
Priority: Minor
Fix For: jBPM 3.2.10
Attachments: jbpm-jira-2133-stacktrace.txt
regards CommndServiceBean.execute(Command command):
public Object execute(Command command)
{
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try
{
log.debug("executing " + command);
return command.execute(jbpmContext);
}
catch (RuntimeException e)
{
sessionContext.setRollbackOnly();
throw e;
}
catch (Exception e)
{
sessionContext.setRollbackOnly();
throw new JbpmException("failed to execute " + command, e);
}
finally
{
jbpmContext.close();
}
}
If an exception occurres in Command.excute() it's important that this exception is
propagated to the client to allow for proper exception handling to differentiate e.g.
between a concurrency issue ("job is locked by...") and a database error.
These exceptions are not propagated to the client if the jbpmContext.close() in the
finally block throws an exceptions. This might very well happen since it performs
non-trivial operations, e.g. access the database. (Actually it it seems to me as if the
failure of jbpmContext.close() always happen, maybe since after the setRollbackOnly() no
new connections are possible.)
The following change will fix the problem:
public Object execute(Command command)
{
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
boolean exceptionThrown = false;
try
{
log.debug("executing " + command);
return command.execute(jbpmContext);
}
catch (RuntimeException e)
{
sessionContext.setRollbackOnly();
exceptionThrown = true;
throw e;
}
catch (Exception e)
{
sessionContext.setRollbackOnly();
exceptionThrown = true;
throw new JbpmException("failed to execute " + command, e);
}
finally
{
try
{
jbpmContext.close();
}
catch (RuntimeException e2) {
if (exceptionThrown)
{
// JIRA XX: do not hide thrown exception
log.error("exception on context close", e2);
}
else
{
throw e2;
}
}
}
}
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: