deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-1039 LinkageError on container reboot
Date Wed, 09 Dec 2015 09:38:28 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 080a62e11 -> 1ce13b856


DELTASPIKE-1039 LinkageError on container reboot

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1ce13b85
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1ce13b85
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1ce13b85

Branch: refs/heads/master
Commit: 1ce13b85647a5695667927d0692cc63560e36bd3
Parents: 080a62e
Author: tandraschko <tandraschko@apache.org>
Authored: Wed Dec 9 10:38:00 2015 +0100
Committer: tandraschko <tandraschko@apache.org>
Committed: Wed Dec 9 10:38:00 2015 +0100

----------------------------------------------------------------------
 .../apache/deltaspike/core/util/ClassUtils.java | 32 ++++++++++++++++++++
 .../proxy/api/DeltaSpikeProxyFactory.java       | 13 ++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ce13b85/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
index 044e6d9..af574c2 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
@@ -114,6 +114,19 @@ public abstract class ClassUtils
     {
         return (Class<T>) tryToLoadClassForName(name);
     }
+    
+    /**
+     * Tries to load a class based on the given name and interface or abstract class.
+     * @param name name of the concrete class
+     * @param targetType target type (interface or abstract class)
+     * @param classLoader The {@link ClassLoader}.
+     * @param <T> current type
+     * @return loaded class or null if it isn't in the classpath
+     */
+    public static <T> Class<T> tryToLoadClassForName(String name, Class<T>
targetType, ClassLoader classLoader)
+    {
+        return (Class<T>) tryToLoadClassForName(name, classLoader);
+    }
 
     /**
      * Tries to load a class based on the given name
@@ -132,6 +145,25 @@ public abstract class ClassUtils
             return null;
         }
     }
+    
+    /**
+     * Tries to load a class based on the given name
+     * @param name name of the class
+     * @param classLoader The {@link ClassLoader}.
+     * @return loaded class or <code>null</code> if it isn't in the classpath
+     */
+    public static Class tryToLoadClassForName(String name, ClassLoader classLoader)
+    {
+        try
+        {
+            return classLoader.loadClass(name);
+        }
+        catch (ClassNotFoundException e)
+        {
+            //do nothing - it's just a try
+            return null;
+        }
+    }
 
     /**
      * Loads class for the given name

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ce13b85/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
index 1e19ab1..ddd9d00 100644
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
+++ b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
@@ -78,11 +78,20 @@ public abstract class DeltaSpikeProxyFactory
         return GeneratorHolder.generator;
     }
 
+    public <T> Class<T> resolveAlreadyDefinedProxyClass(Class<T> targetClass)
+    {
+        Class<T> proxyClass = ClassUtils.tryToLoadClassForName(constructProxyClassName(targetClass),
+                targetClass,
+                targetClass.getClassLoader());
+
+        return proxyClass;
+    }
+    
     public <T> Class<T> getProxyClass(BeanManager beanManager, Class<T>
targetClass,
             Class<? extends InvocationHandler> delegateInvocationHandlerClass)
     {
         // check if a proxy is already defined for this class
-        Class<T> proxyClass = ClassUtils.tryToLoadClassForName(constructProxyClassName(targetClass),
targetClass);
+        Class<T> proxyClass = resolveAlreadyDefinedProxyClass(targetClass);
         if (proxyClass == null)
         {
             proxyClass = createProxyClass(beanManager, targetClass.getClassLoader(), targetClass,
@@ -95,7 +104,7 @@ public abstract class DeltaSpikeProxyFactory
     private synchronized <T> Class<T> createProxyClass(BeanManager beanManager,
ClassLoader classLoader,
             Class<T> targetClass, Class<? extends InvocationHandler> delegateInvocationHandlerClass)
     {
-        Class<T> proxyClass = ClassUtils.tryToLoadClassForName(constructProxyClassName(targetClass),
targetClass);
+        Class<T> proxyClass = resolveAlreadyDefinedProxyClass(targetClass);
         if (proxyClass == null)
         {
             ArrayList<Method> allMethods = collectAllMethods(targetClass);


Mime
View raw message