Saturday, January 8, 2011

ClassLoader exceptions being memoized

Programmer Question

Hello,



I am writing a classloader for a long-running server instance. If a user has not yet uploaded a class definition, I through a ClassNotFoundException; seems reasonable.



The problem is this: There are three classes (C1, C2, and C3). C1 depends on C2, C2 depends on C3. C1 and C2 are resolvable, C3 isn't (yet). C1 is loaded. C1 subsequently performs an action that requires C2, so C2 is loaded. C2 subsequently performs an action that requires C3, so the classloader attempts to load C3, but can't resolve it, and an exception is thrown. Now C3 is added to the classpath, and the process is restarted (starting from the originally-loaded C1). The issue is, C2 seems to remember that C3 couldn't be loaded, and doesn't bother asking the classloader to find the class... it just re-throws the memoized exception.



Clearly I can't reload C1 or C2 because other classes may have linked to them (as C1 has already linked to C2).



I tried throwing different types of errors, hoping the class might not memoize them. Unfortunately, no such luck.



Is there a way to prevent the loaded class from binding to the exception? That is, I want the classloader to be allowed to keep trying if it didn't succeed the first time.



Thanks!



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails