[FELIX-4942] Make sure all exceptions are propagated back to the caller when using the executor

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1690737 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java b/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
index 9a98d33..2e2add3 100644
--- a/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
+++ b/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
@@ -2355,6 +2355,7 @@
     {
         private final Executor executor;
         private final AtomicInteger count = new AtomicInteger();
+        private Throwable throwable;
 
         public EnhancedExecutor(Executor executor)
         {
@@ -2372,6 +2373,16 @@
                     {
                         runnable.run();
                     }
+                    catch (Throwable t)
+                    {
+                        synchronized (count)
+                        {
+                            if (throwable == null)
+                            {
+                                throwable = t;
+                            }
+                        }
+                    }
                     finally
                     {
                         if (count.decrementAndGet() == 0)
@@ -2400,6 +2411,21 @@
                     {
                         throw new IllegalStateException(e);
                     }
+                    if (throwable != null)
+                    {
+                        if (throwable instanceof RuntimeException)
+                        {
+                            throw (RuntimeException) throwable;
+                        }
+                        else if (throwable instanceof Error)
+                        {
+                            throw (Error) throwable;
+                        }
+                        else
+                        {
+                            throw new RuntimeException(throwable);
+                        }
+                    }
                 }
             }
         }