diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java index 23396b4..cc7cd98 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java @@ -93,9 +93,7 @@ public class ExceptionHandlerInterceptor implements Serializable { CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class); if (!bootstrap.isAnnotatedType(type)) { - getLogger().debug( - getBundle().getString("proxy-detected", type, - type.getSuperclass())); + getLogger().debug(getBundle().getString("proxy-detected", type, type.getSuperclass())); type = type.getSuperclass(); } @@ -103,8 +101,8 @@ public class ExceptionHandlerInterceptor implements Serializable { } /** - * If there is an handler in the current class or superClass for the expected exception, then this method will be returned; Else - * returns null; + * If there is an handler in the current class or superClass for the expected exception, then this method will be + * returned; Else returns null; * * @param type * @param causeClass @@ -112,17 +110,15 @@ public class ExceptionHandlerInterceptor implements Serializable { */ private final Method getMethod(final Class type, final Class causeClass) { Method handler = null; + Map, Method> map = cache.get(type); - if (cache.containsKey(type) ){ - Map, Method> map = cache.get(type); - if(Throwable.class.isAssignableFrom(causeClass)){ - if(map.containsKey(causeClass)){ - handler = map.get(causeClass); - }else{ - handler = getMethod(type, causeClass.getSuperclass()); - } - } - } + if (map != null && Throwable.class.isAssignableFrom(causeClass)) { + if (map.containsKey(causeClass)) { + handler = map.get(causeClass); + } else { + handler = getMethod(type, causeClass.getSuperclass()); + } + } return handler; } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java index d9df1b4..1c10661 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java @@ -210,19 +210,6 @@ public class ExceptionHandlerInterceptorTest { } @Test - public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { - ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); - expect(this.context.proceed()).andThrow(new DemoiselleException("")); - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); - replayAll(this.context, this.coreBootstrap, Beans.class); - - assertNull(this.interceptor.manage(this.context)); - assertEquals(1, classWithException.times); - verifyAll(); - } - - @Test public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); @@ -352,4 +339,3 @@ public class ExceptionHandlerInterceptorTest { } } } - -- libgit2 0.21.2