tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petras (JIRA)" <j...@apache.org>
Subject [jira] [Created] (OPENEJB-2111) Unchecked application exceptions, thrown in asynchronous business methods, are always wrapped in EJBException
Date Mon, 16 Mar 2015 11:29:38 GMT
Petras created OPENEJB-2111:
-------------------------------

             Summary: 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


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)

Mime
View raw message