tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1696 ensure lazy resources use by default container loader (UseAppClassLoader=false or null). Was not the case for auto created resources
Date Thu, 21 Jan 2016 08:09:33 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 2b5518c58 -> 0f8fd20bd


TOMEE-1696 ensure lazy resources use by default container loader (UseAppClassLoader=false
or null). Was not the case for auto created resources


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/0f8fd20b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/0f8fd20b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/0f8fd20b

Branch: refs/heads/master
Commit: 0f8fd20bd519218f3b9fdeb85b8ca010db353b53
Parents: 2b5518c
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
Authored: Thu Jan 21 09:09:26 2016 +0100
Committer: Romain Manni-Bucau <rmannibucau@gmail.com>
Committed: Thu Jan 21 09:09:26 2016 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java       | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/0f8fd20b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 4b5ed1f..ef6544b 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2659,7 +2659,7 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
     public void createResource(final ResourceInfo serviceInfo) throws OpenEJBException {
         final boolean usesCdiPwdCipher = usesCdiPwdCipher(serviceInfo);
         final Object service = "true".equalsIgnoreCase(String.valueOf(serviceInfo.properties.remove("Lazy")))
|| usesCdiPwdCipher ?
-                newLazyResource(serviceInfo) :
+            newLazyResource(serviceInfo) :
                 doCreateResource(serviceInfo);
         if (usesCdiPwdCipher && !serviceInfo.properties.contains("InitializeAfterDeployment"))
{
             serviceInfo.properties.put("InitializeAfterDeployment", "true");
@@ -2696,25 +2696,22 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
     }
 
     private LazyResource newLazyResource(final ResourceInfo serviceInfo) {
-        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
         return new LazyResource(new Callable<Object>() {
             @Override
             public Object call() throws Exception {
                 final boolean appClassLoader = "true".equals(serviceInfo.properties.remove("UseAppClassLoader"));
 
-                ClassLoader old = null;
-
+                final Thread thread = Thread.currentThread();
+                final ClassLoader old = thread.getContextClassLoader();
                 if (!appClassLoader) {
-                    old = Thread.currentThread().getContextClassLoader();
-                    Thread.currentThread().setContextClassLoader(loader);
-                }
+                    final ClassLoader classLoader = Assembler.class.getClassLoader();
+                    thread.setContextClassLoader(classLoader == null ? ClassLoader.getSystemClassLoader()
: classLoader);
+                } // else contextually we should have the app loader
 
                 try {
                     return doCreateResource(serviceInfo);
                 } finally {
-                    if (old != null) {
-                        Thread.currentThread().setContextClassLoader(old);
-                    }
+                    thread.setContextClassLoader(old);
                 }
             }
         });


Mime
View raw message