4 Replies Latest reply on May 9, 2006 6:41 PM by Scott Stark

    Expand handling of ProxyFactory getClassLoader selection pro

    Scott Stark Master

      As mentioned in:
      http://jira.jboss.com/jira/browse/JASSIST-18

      the current selection of the ProxyFactory.getClassLoader does not deal with the case of the proxy superclass class loader being null. This is seen when one uses a jdk system class (java.util.AbstractCollection is the example in the testcase. Two possible expansions of the selection logic are:

      #1

       protected ClassLoader getClassLoader() {
       ClassLoader loader = null;
       if (superClass != null && !superClass.getName().equals("java.lang.Object"))
       loader = superClass.getClassLoader();
       else if (interfaces != null && interfaces.length > 0)
       loader = interfaces[0].getClassLoader();
       if( loader == null )
       loader = this.getClass().getClassLoader();
       return loader;
       // return Thread.currentThread().getContextClassLoader();
       }
      

      #2
       protected ClassLoader getClassLoader() {
       ClassLoader loader = null;
       if (superClass != null && !superClass.getName().equals("java.lang.Object"))
       loader = superClass.getClassLoader();
       else if (interfaces != null && interfaces.length > 0)
       loader = interfaces[0].getClassLoader();
       else
       loader = this.getClass().getClassLoader();
       if( loader == null )
       loader = ClassLoader.getSystemClassLoader();
       return loader;
       // return Thread.currentThread().getContextClassLoader();
       }
      


      #2 seems the most correct approach to me. I have tried this and it works for the cited testcase.