From e45ba162d0c0b21bb1e32999e3861487f257e31b Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Thu, 23 Aug 2012 16:41:02 +0200 Subject: [PATCH] QueueProcessor: survive on LOG.error in tests (more correct) --- .../util/concurrency/QueueProcessor.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java b/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java index 1b216f2135bf..8a7bba3a3963 100644 --- a/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java +++ b/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java @@ -77,18 +77,13 @@ public class QueueProcessor { private static PairConsumer wrappingProcessor(final Consumer processor) { return new PairConsumer() { @Override - public void consume(T item, Runnable runnable) { - try { - processor.consume(item); - } - catch (Throwable e) { - try { - LOG.error(e); + public void consume(final T item, Runnable runnable) { + runSafely(new Runnable() { + @Override + public void run() { + processor.consume(item); } - catch (Exception ignore) { - // should survive assertions - } - } + }); runnable.run(); } }; @@ -202,17 +197,12 @@ public class QueueProcessor { @Override public void run() { if (myDeathCondition.value(null)) return; - try { - myProcessor.consume(item, myContinuationContext); - } - catch (Throwable t) { - try { - LOG.error(t); + runSafely(new Runnable() { + @Override + public void run() { + myProcessor.consume(item, myContinuationContext); } - catch (Throwable e2) { - e2.printStackTrace(); - } - } + }); } }; final Application application = ApplicationManager.getApplication(); @@ -231,6 +221,20 @@ public class QueueProcessor { return true; } + public static void runSafely(Runnable run) { + try { + run.run(); + } + catch (Throwable e) { + try { + LOG.error(e); + } + catch (Throwable e2) { + e2.printStackTrace(); + } + } + } + public boolean isEmpty() { synchronized (myQueue) { return myQueue.isEmpty() && (!isProcessing);