You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "Romain Manni-Bucau (JIRA)" <ji...@apache.org> on 2015/03/16 19:50:38 UTC
[jira] [Resolved] (OPENEJB-2111) Unchecked application exceptions,
thrown in asynchronous business methods, are always wrapped in EJBException
[ https://issues.apache.org/jira/browse/OPENEJB-2111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Romain Manni-Bucau resolved OPENEJB-2111.
-----------------------------------------
Resolution: Fixed
Fix Version/s: 5.0.0-Milestone-1
4.7.2
Assignee: Romain Manni-Bucau
> Unchecked application exceptions, thrown in asynchronous business methods, are always wrapped in EJBException
> -------------------------------------------------------------------------------------------------------------
>
> Key: OPENEJB-2111
> URL: https://issues.apache.org/jira/browse/OPENEJB-2111
> Project: OpenEJB
> Issue Type: Bug
> Components: ejb31, tomee
> Affects Versions: 4.7.1
> Reporter: Petras
> Assignee: Romain Manni-Bucau
> Fix For: 4.7.2, 5.0.0-Milestone-1
>
>
> Example of my business method:
> {code}
> @Asynchronous
> public Future<AttachmentWBean> convertToPDF(File file, String contentType)
> throws FileConverterException, OperationCancelledException {
> final ConversionResultWBean wsResult = invokeFileConverterWS(file, contentType);
> return new AsyncResult<>(wsResult.getResultFile());
> }
> {code}
> FileConverterException is checked exception while OperationCancelledException class is unchecked and declared as ApplicationException:
> {code}
> @ApplicationException
> public class OperationCancelledException extends RuntimeException {
> //...
> }
> {code}
> The reason is that {{org.apache.openejb.async.AsynchronousPool.FutureAdapter#handleException}} method does not check whether exception is an unchecked ApplicationException and always wrapps it into EJBException. Only checked exceptions are returned directly:
> {code}
> private void handleException(Throwable e) throws ExecutionException {
> //unwarp the exception to find the root cause
> while (e.getCause() != null) {
> e = e.getCause();
> }
> /*
> * StatefulContainer.obtainInstance(Object, ThreadContext, Method)
> * will return NoSuchObjectException instead of NoSuchEJBException *
> * when it can't obtain an instance. Actually, the async client
> * is expecting a NoSuchEJBException. Wrap it here as a workaround.
> */
> if (e instanceof NoSuchObjectException) {
> e = new NoSuchEJBException(e.getMessage(), (Exception) e);
> }
> final boolean isExceptionUnchecked = e instanceof Error || e instanceof RuntimeException;
> // throw checked excpetion and EJBException directly.
> if (!isExceptionUnchecked || e instanceof EJBException) {
> throw new ExecutionException(e);
> }
> // wrap unchecked exception with EJBException before throwing.
> throw e instanceof Exception ? new ExecutionException(new EJBException((Exception) e))
> : new ExecutionException(new EJBException(new Exception(e)));
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)