"the classloader used is in the parent domain"
But this isn't always the case?
Only for this piece:
// Try the before attempt (e.g. from the parent)
Loader loader = null;
if (findInParent)
loader = findBeforeLoader(name);
if (loader != null)
return loader;
But this could be cached -- if the policy permits it?
// Next use any requesting classloader, this will look at everything not just what it exports
if (classLoader != null)
{
if (trace)
log.trace(this + " trying to load " + name + " from requesting " + classLoader);
if (classLoader.getResourceLocally(name) != null)
return classLoader.getLoader();
}
That's why it can't update the Cache in the place you suggested.
For a classloader inside the domain it can globally cache, otherwise it can't.
It should cache in the domain where the classloader lives.
What needs changing is to check that cache according to the parent delegation
rules outside the synchronization block.
if (matchesParentBefore)
checkParentCache();
checkOurCache();
The difficulty comes in that we would like to add
if (matchesParentAfter)
checkParentCache();
But we can't because the next logical step is to see if we can load from our domain.
This however would work:
if (isBlackListedInOurDomain && matchesParentAfter)
checkParentCache();
because we know we won't load it from our domain.