JBoss development,
A new message was posted in the thread "ClassPool Refactoring":
http://community.jboss.org/message/527265#527265
Author : Flavia Rainone
Profile :
http://community.jboss.org/people/flavia.rainone@jboss.com
Message:
--------------------------------------------------------------
mailto:flavia.rainone@jboss.com wrote:
My fix has never been comitted and consists of adding a check on the classes cache to
BaseClassPool.get:
*public* *class* BaseClassPool *extends* AbstractClassPool
{
...
@Override
*public* *final* CtClass get(String classname) *throws* NotFoundException
{
*boolean* trace = logger.isTraceEnabled();
*if* (trace) logger.trace(*this* + " initiating get of " + classname);
*if* (this.getClassLoader() == *null*)
{
*throw* *new* IllegalStateException("Illegal call. " + " A class
cannot be retrieved from ClassPool " +
*this* + " because the corresponding
ClassLoader is garbage collected");
}
*try*
{
>>> *if* (this.classes.containsKey(classname))
>>> {
>>> *return* (CtClass) classes.get(classname);
>>> }
CtClass clazz = super.get(classname);
*if* (trace)
logger.trace(*this* + " completed get of " + classname + "
" + getClassPoolLogStringForClass(clazz));
*return* clazz;
}
*catch* (NotFoundException e)
{
*if* (trace)
logger.trace(classname + " could not be found from " + this, e);
*throw* e;
}
}
}
[....]
While working with Kabir to fix the AOP tests for AS, he pointed out that there could be
an issue related to my fix. It seemed obviously right to me to look in the classes cache
(a cache declared in ScopedClassPool that contains all classes created by the current
class pool) before doing anything else. To me, if we have a hit in the cache, it means
that the current pool is the one that is supposed to load the class, and that there is no
need to look further by calling super.get method. But Kabir raised the following
possibility. What if the class pool scenario (a reflection of the class loader/domain
scenario) changes after the current class pool loaded the class, in a way that this class
pool is no longer the one responsible for loading that class? In that case, looking for
the class in the classes cache would be a serious mistake. Is this scenario possible?
Does anybody know the answer to this question? I can't commit it without knowing
the answer.
--------------------------------------------------------------
To reply to this message visit the message page:
http://community.jboss.org/message/527265#527265