I've just recently had to work around an issue I had with the getCached() method in org.jboss.aop.AOPClassPool. In my scenario, I am using JBoss AOP in an application that utilizes multiple classloaders to load different services, some of which contain identical classes. Here's an example to summarise:

ClassLoader A first loads class org.test.MyClassClassLoader B then also loads class org.test.MyClass.

The issue that occurs is that when MyClass is loaded with classloader B, it has already been loaded by classloader A, and the getCached() method will not find a locally cached MyClass for classloader B, and iterates through the other registered classloaders/pools to attempt to locate the class. This results in a CtClass instance being returned from classloader A's class pool instead of classloader B's.

The fix (I believe) for this solution is to check whether the local classloader is capable of loading the specified classname, and if it is then it shouldn't search the other registered classloaders. Here's a patched version of getCached() that does this:

I'd be interested in hearing other people's thoughts on this issue. The solution I've proposed does not feel very elegant but I'm not yet familiar enough with the JBoss AOP source to suggest anything better.