From 1404ad8f8a6bb37d30c21df3e2207c402f71f3b7 Mon Sep 17 00:00:00 2001 From: Andrew Guibert Date: Thu, 25 Jul 2019 10:46:10 -0500 Subject: [PATCH] Review comments --- .../cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops | 11 ++++++----- .../com/ibm/ws/concurrent/mp/ContextualRunnable.java | 12 +++--------- .../ws/concurrent/mp/ContextualSupplierAction.java | 7 +++++-- .../mp/fat/cdi/web/MPConcurrentCDITestServlet.java | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/dev/com.ibm.ws.cdi.mp.context/resources/com/ibm/ws/cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops b/dev/com.ibm.ws.cdi.mp.context/resources/com/ibm/ws/cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops index 7054443f8d1..3b0fc309d92 100644 --- a/dev/com.ibm.ws.cdi.mp.context/resources/com/ibm/ws/cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops +++ b/dev/com.ibm.ws.cdi.mp.context/resources/com/ibm/ws/cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops @@ -26,8 +26,9 @@ # com.ibm.ws.concurrent.mp.1.0 message bundle # do not translate: CDI, CompletionStage -CWWKC1158.cannot.lazy.enlist.beans=CWWKC1158E: CDI beans used in contextual operations, such as a CompletionStage, must be accessed using a CDI bean operation, such as a public \ -method, before context for the operation is captured. The CDI beans that were not accessed before context was captured are: {0} -CWWKC1158.cannot.lazy.enlist.beans.explanation=When CDI context is captured, only CDI beans that have been accessed at that point in time have been created by the CDI \ -runtime. As a result, CDI beans that are first accessed in contextual operations cannot propagate their state correctly to subsequent contextual operations. -CWWKC1158.cannot.lazy.enlist.beans.useraction=The application must be changed to invoke some CDI bean operation, such as a public method, before context for the operation is captured. +CWWKC1158.cannot.lazy.enlist.beans=CWWKC1158E:You must access CDI beans prior to capturing context for the contextual action or task in order for the CDI \ +beans to behave correctly when accessed from the action or task. The following CDI beans must be accessed before capturing context: {0}. +CWWKC1158.cannot.lazy.enlist.beans.explanation=When CDI context is captured, only CDI beans that have been accessed at that point in time have been created by \ +the CDI runtime. As a result, CDI beans that are first accessed in contextual operations cannot propagate their state correctly to subsequent contextual operations. +CWWKC1158.cannot.lazy.enlist.beans.useraction=The application must be changed to invoke some CDI bean operation, such as a public method, before context for \ +the operation is captured. diff --git a/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualRunnable.java b/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualRunnable.java index 37831a93dd3..a90c57bc47f 100644 --- a/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualRunnable.java +++ b/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualRunnable.java @@ -58,10 +58,7 @@ public void run() { if (threadContextDescriptor != null) contextApplied = threadContextDescriptor.taskStarting(); action.run(); - } catch (Error x) { - failure = x; - throw x; - } catch (RuntimeException x) { + } catch (Error | RuntimeException x) { failure = x; throw x; } finally { @@ -69,11 +66,8 @@ public void run() { if (contextApplied != null) threadContextDescriptor.taskStopping(contextApplied); } catch (RuntimeException x) { - // prioritize surfacing an actual task failure over a failure clearing context - if (failure == null) { - failure = x; - throw x; - } + failure = x; + throw x; } finally { if (completableFuture != null) if (failure == null) diff --git a/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualSupplierAction.java b/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualSupplierAction.java index 54b842b4a6a..a344fa1f900 100644 --- a/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualSupplierAction.java +++ b/dev/com.ibm.ws.concurrent.mp.1.0/src/com/ibm/ws/concurrent/mp/ContextualSupplierAction.java @@ -47,16 +47,19 @@ public void run() { if (threadContextDescriptor != null) contextApplied = threadContextDescriptor.taskStarting(); result = action.get(); - } catch (Error x) { + } catch (RuntimeException x) { failure = x; throw x; - } catch (RuntimeException x) { + } catch (Error x) { failure = x; throw x; } finally { try { if (contextApplied != null) threadContextDescriptor.taskStopping(contextApplied); + } catch (RuntimeException x) { + failure = x; + throw x; } finally { if (failure == null) if (superComplete) diff --git a/dev/com.ibm.ws.concurrent.mp_fat/test-applications/MPConcurrentCDIApp/src/concurrent/mp/fat/cdi/web/MPConcurrentCDITestServlet.java b/dev/com.ibm.ws.concurrent.mp_fat/test-applications/MPConcurrentCDIApp/src/concurrent/mp/fat/cdi/web/MPConcurrentCDITestServlet.java index 9ee3484a961..29eaceff7f5 100644 --- a/dev/com.ibm.ws.concurrent.mp_fat/test-applications/MPConcurrentCDIApp/src/concurrent/mp/fat/cdi/web/MPConcurrentCDITestServlet.java +++ b/dev/com.ibm.ws.concurrent.mp_fat/test-applications/MPConcurrentCDIApp/src/concurrent/mp/fat/cdi/web/MPConcurrentCDITestServlet.java @@ -235,7 +235,7 @@ public void testCDIContextPropagationBeanFirstUsedInCompletionStage() throws Exc } } assertTrue("CompletableFuture should have been marked done", cf.isDone()); - assertTrue("CompletableFuture should have been marked as completex exceptionally", cf.isCompletedExceptionally()); + assertTrue("CompletableFuture should have been marked as completed exceptionally", cf.isCompletedExceptionally()); } /**