diff --git a/platform/core-api/src/com/intellij/util/messages/impl/MessageBusImpl.java b/platform/core-api/src/com/intellij/util/messages/impl/MessageBusImpl.java index 4137697d9e6e..8a78ce1df9cb 100644 --- a/platform/core-api/src/com/intellij/util/messages/impl/MessageBusImpl.java +++ b/platform/core-api/src/com/intellij/util/messages/impl/MessageBusImpl.java @@ -449,21 +449,15 @@ public class MessageBusImpl implements MessageBus { try { invokeListener(job, handlers.get(index), messageDeliveryListener); } - catch (AbstractMethodError ignore) { - // Do nothing. This listener just does not implement something newly added yet. - } - catch (InvocationTargetException e) { - if (exceptions == null) { - exceptions = new ArrayList<>(); - } - Throwable cause = e.getCause(); - exceptions.add(cause == null ? e : cause); - } catch (Throwable e) { - if (exceptions == null) { - exceptions = new ArrayList<>(); - } - exceptions.add(e); + //noinspection InstanceofCatchParameter + Throwable cause = e instanceof InvocationTargetException && e.getCause() != null ? e.getCause() : e; + // Do nothing for AbstractMethodError. This listener just does not implement something newly added yet. + // AbstractMethodError is normally wrapped in InvocationTargetException, + // but some Java versions didn't do it in some cases (see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6531596) + if (cause instanceof AbstractMethodError) continue; + if (exceptions == null) exceptions = new SmartList<>(); + exceptions.add(cause); } if (++index != job.currentHandlerIndex) { diff --git a/platform/util/src/com/intellij/util/EventDispatcher.java b/platform/util/src/com/intellij/util/EventDispatcher.java index ad29dcd8db06..97a5f6a567b2 100644 --- a/platform/util/src/com/intellij/util/EventDispatcher.java +++ b/platform/util/src/com/intellij/util/EventDispatcher.java @@ -8,12 +8,14 @@ import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.StaticGetter; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.DisposableWrapperList; +import com.intellij.util.lang.CompoundRuntimeException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.*; @@ -120,28 +122,25 @@ public class EventDispatcher { } private static void dispatchVoidMethod(@NotNull Iterable listeners, @NotNull Method method, Object[] args) { + List exceptions = null; method.setAccessible(true); for (T listener : listeners) { try { method.invoke(listener, args); } - catch (AbstractMethodError ignored) { - // Do nothing. This listener just does not implement something newly added yet. + catch (Throwable e) { + //noinspection InstanceofCatchParameter + Throwable cause = e instanceof InvocationTargetException && e.getCause() != null ? e.getCause() : e; + // Do nothing for AbstractMethodError. This listener just does not implement something newly added yet. // AbstractMethodError is normally wrapped in InvocationTargetException, // but some Java versions didn't do it in some cases (see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6531596) - } - catch (RuntimeException e) { - throw e; - } - catch (Exception e) { - final Throwable cause = e.getCause(); - ExceptionUtil.rethrowUnchecked(cause); - if (!(cause instanceof AbstractMethodError)) { // AbstractMethodError means this listener doesn't implement some new method in interface - LOG.error(cause); - } + if (cause instanceof AbstractMethodError) continue; + if (exceptions == null) exceptions = new SmartList<>(); + exceptions.add(cause); } } + CompoundRuntimeException.throwIfNotEmpty(exceptions); } public void addListener(@NotNull T listener) {