polishing

This commit fixes the handling of cached exceptions in the JSR-107
advisor. Such exceptions are now properly propagated instead of being
wrapped in a RuntimeException.

Issue: SPR-9616
This commit is contained in:
Stephane Nicoll
2014-04-08 17:03:31 +02:00
parent 0bdece700f
commit 3cda355e7f
6 changed files with 82 additions and 14 deletions

View File

@@ -67,10 +67,8 @@ public aspect JCacheCacheAspect extends JCacheAspectSupport {
return execute(aspectJInvoker, thisJoinPoint.getTarget(), method, thisJoinPoint.getArgs());
}
catch (CacheOperationInvoker.ThrowableWrapper th) {
if (th.getOriginal() instanceof RuntimeException) {
throw (RuntimeException) th.getOriginal();
}
throw th; // Lose original checked exception
AnyThrow.throwUnchecked(th.getOriginal());
return null; // never reached
}
}
@@ -109,4 +107,17 @@ public aspect JCacheCacheAspect extends JCacheAspectSupport {
private pointcut executionOfCacheRemoveAllMethod() :
execution(@CacheRemoveAll * *(..));
private static class AnyThrow {
private static void throwUnchecked(Throwable e) {
AnyThrow.<RuntimeException>throwAny(e);
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwAny(Throwable e) throws E {
throw (E)e;
}
}
}