diff --git a/scm-webapp/src/main/java/com/google/common/eventbus/ThrowingEventBus.java b/scm-webapp/src/main/java/com/google/common/eventbus/ThrowingEventBus.java index ae9a0a9112..325012a0f5 100644 --- a/scm-webapp/src/main/java/com/google/common/eventbus/ThrowingEventBus.java +++ b/scm-webapp/src/main/java/com/google/common/eventbus/ThrowingEventBus.java @@ -30,10 +30,16 @@ */ + package com.google.common.eventbus; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.base.Throwables; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import sonia.scm.event.EventBusException; //~--- JDK imports ------------------------------------------------------------ @@ -48,6 +54,14 @@ import java.lang.reflect.InvocationTargetException; public class ThrowingEventBus extends EventBus { + /** + * the logger for ThrowingEventBus + */ + private static final Logger logger = + LoggerFactory.getLogger(ThrowingEventBus.class); + + //~--- methods -------------------------------------------------------------- + /** * {@inheritDoc} * @@ -64,8 +78,13 @@ public class ThrowingEventBus extends EventBus } catch (InvocationTargetException ex) { + Throwable cause = ex.getCause(); + + Throwables.propagateIfPossible(cause); + logger.trace("could not propagate exception, throw as EventBusException"); + throw new EventBusException( - "could not handle event ".concat(event.toString()), ex); + "could not handle event ".concat(event.toString()), cause); } } } diff --git a/scm-webapp/src/test/java/sonia/scm/event/GuavaScmEventBusTest.java b/scm-webapp/src/test/java/sonia/scm/event/GuavaScmEventBusTest.java index f455158c86..2c8ed85086 100644 --- a/scm-webapp/src/test/java/sonia/scm/event/GuavaScmEventBusTest.java +++ b/scm-webapp/src/test/java/sonia/scm/event/GuavaScmEventBusTest.java @@ -30,6 +30,7 @@ */ + package sonia.scm.event; //~--- non-JDK imports -------------------------------------------------------- @@ -49,6 +50,10 @@ import sonia.scm.user.UserEvent; import static org.junit.Assert.*; +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + /** * * @author Sebastian Sdorra @@ -133,7 +138,30 @@ public class GuavaScmEventBusTest extends AbstractTestBase * */ @Test(expected = EventBusException.class) - public void testSyncPostWithException() + public void testSyncPostWithCheckedException() + { + GuavaScmEventBus eventBus = new GuavaScmEventBus(); + + eventBus.register(new Object() + { + + @Subscribe + public void handleEvent(Object event) throws IOException + { + throw new IOException("could not handle event"); + } + + }, false); + + eventBus.post(new Object()); + } + + /** + * Method description + * + */ + @Test(expected = RuntimeException.class) + public void testSyncPostWithRuntimeException() { GuavaScmEventBus eventBus = new GuavaScmEventBus();