4 Replies Latest reply on May 15, 2008 1:49 PM by Flavia Rainone

    Relying on ClassLoader.getResource results in unexpected beh

    Flavia Rainone Master

      A JBoss AOP user discovered a bug in JBoss AOP when using a class loader he himself defined to load interceptors and intercepted classes:

      http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4150812#4150812


      JBoss AOP Class Pool is not able of finding the generated abstract joinpoint class (the one that is generated to be super class of the generated joinpoint classes). My theory is that this is happening because AOPClassPool assumes that, if it can find the resource through ClassLoader.getResource method, then the class is available. Since the class loader defined by the user does not overwrite getResource, it will return null, even if it can load the queried class. As a consequence, AOPClassPool.getCached(String) returns null, and ScopedClassPool will try to find the class file by itself. But Javassist also relies on the ClassLoader.getResource and ClassLoader.getResourceAsStream methods (at LoaderClassPath class). So, Javassist also fails to load the class.

      I haven't found a Java documentation affirming that we can rely on getResource methods to figure out the class file. If this is the case, is it possible to avoid this situation? If not, we should add at a constraint to the documentation.