Disclaimer I have long advocated having a ASF exam in classloaders; nobody who hasn't passed the exam would be allowed to mess with classloaders in any apache project. As there is no such exam, there is no proof that I can be considered competent enough to do this, and you should treat everything I say with caution. Test my statements, preferably in JUnit methods.
1. Adding new classes is generally rare unless you are running something that is generating java classes on the fly; JSP compilers do this. Even then, they try not to mess around with things higher up the hierarchy (exception, JBoss default classloader, the one that's broken that everyone hates).
2. Modern, OSGi-style classloaders are fairly strict, I don't think they add stuff higher up. More of a general concern when you play with classloader trees are
- it's easy to leak classloaders. retain one ref to a class loaded by a child classloader and the classloader never gets GC'd, doesn't pick up
updated JARs, consumes memory, stops your build overwriting any locked
JARs (windows only)
- all the rules about singletons and equality goes out the window.
3. I would go for caching the failure. For those people playing games with classloaders, tough. But do note that if the JSP engine does need to
compile a JSP class, then Hadoop is adding classes to some classpath
in the Hadoop JVM. So your tools may be doing what you don't think is
happening, even on a "normal" Hadoop instance.
4. Looking at the code in more detail, the things a bit of an ugly hack, a contrived workaround to avoid a cycle. If there was an elegant solution to this that didn't evolve reflection, things would be much better. Nothing obvious springs to mind.