Author: rony
Date: Sat Oct 29 17:26:26 2011
New Revision: 1194939

URL: http://svn.apache.org/viewvc?rev=1194939&view=rev
Log:
Resolve issue [#BSF-36]: use context class loader only, if set

Modified:
    
commons/proper/bsf/trunk/src/main/java/org/apache/bsf/util/ReflectionUtils.java

Modified: 
commons/proper/bsf/trunk/src/main/java/org/apache/bsf/util/ReflectionUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/bsf/trunk/src/main/java/org/apache/bsf/util/ReflectionUtils.java?rev=1194939&r1=1194938&r2=1194939&view=diff
==============================================================================
--- 
commons/proper/bsf/trunk/src/main/java/org/apache/bsf/util/ReflectionUtils.java 
(original)
+++ 
commons/proper/bsf/trunk/src/main/java/org/apache/bsf/util/ReflectionUtils.java 
Sat Oct 29 17:26:26 2011
@@ -59,6 +59,9 @@ import org.apache.bsf.util.type.TypeConv
 
      2011-10-29: Rony G. Flatscher, in case an event is not found, create a
           user-friendly error message that lists all available event names
+
+     2011-10-29: Rony G. Flatscher, make sure that the context class loader
+          is used only, if not null
  */
 public class ReflectionUtils {
     // rgf, 20070921: class loaders that we might need to load classes
@@ -205,6 +208,7 @@ public class ReflectionUtils {
   //////////////////////////////////////////////////////////////////////////
 
 
+
   /**
    * Create a bean using given class loader and using the appropriate
    * constructor for the given args of the given arg types.
@@ -256,21 +260,23 @@ public class ReflectionUtils {
           }
 
           if (cl==null) {
-              try {         // CTXCL
-                  
cl=Thread.currentThread().getContextClassLoader().loadClass(className);
-              }
-              catch (ClassNotFoundException e01)  {
+              // load context class loader, only use it, if not null
+              ClassLoader tccl=Thread.currentThread().getContextClassLoader();
+              if (tccl!=null) {
+                  try {         // CTXCL
+                          cl=tccl.loadClass(className);
+                      }
+                  catch (ClassNotFoundException e01) {}
               }
           }
 
-
           if (cl==null) {   // class not loaded yet
                     // defined CL
               if (cld != bsfManagerDefinedCL) {   // if not used already, 
attempt to load
                   cl=bsfManagerDefinedCL.loadClass(className);
               }
-              else {    // already , throw exception
-                  throw exCTX;        // re-throw very first exception
+              else {    // classloader was already used, hence re-throw 
exception
+                  throw exCTX;      // re-throw very first exception
               }
           }
 // -----------------------------


Reply via email to