Skip to content

Commit

Permalink
Exception proxy stack traces are now properly set.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Aug 22, 2013
1 parent 682c6c9 commit 5d14943
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

import javassist.util.proxy.MethodFilter;
Expand All @@ -30,6 +31,7 @@
*/
public class ClassLoaderAdapterCallback implements MethodHandler
{
private static final Logger log = Logger.getLogger(ClassLoaderAdapterCallback.class.getName());
private static final ClassLoader JAVASSIST_LOADER = ProxyObject.class.getClassLoader();

private final Object delegate;
Expand Down Expand Up @@ -197,8 +199,9 @@ private Object enhanceResult(final Method method, Object result)
return result;
}

private Exception enhanceException(final Method method, Exception exception)
private Exception enhanceException(final Method method, final Exception exception)
{
Exception result = exception;
try
{
if (exception != null)
Expand All @@ -224,18 +227,21 @@ private Exception enhanceException(final Method method, Exception exception)

if (!Modifier.isFinal(unwrappedExceptionType.getModifiers()))
{
exception = enhance(callingLoader, exceptionLoader, method, exception, exceptionHierarchy);
result = enhance(callingLoader, exceptionLoader, method, exception, exceptionHierarchy);
result.setStackTrace(exception.getStackTrace());
}
}
}
}
catch (Exception e)
{
throw new ContainerException("Failed to enhance exception type: [" + exception.getClass().getName()
+ "] during proxied invocation of [" + method.getDeclaringClass().getName() + "." + method.getName()
+ "]. \n\nOriginal exception was: ", e);
log.log(Level.WARNING,
"Could not enhance exception for passing through ClassLoader boundary. Exception type ["
+ exception.getClass().getName() + "], Caller [" + callingLoader + "], Delegate ["
+ delegateLoader + "]");
return exception;
}
return exception;
return result;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand Down

0 comments on commit 5d14943

Please sign in to comment.