I am somewhat stupified by some class loading results I am seeing from
Tomcat.  If I put some class X that refers to class Y in my servlet jar,
the WebappClassLoader loads X.  I DO NOT put class Y in my servlet.jar.
Instead, I put class Y in a jar that is put in common/lib.  When Y is
finally loaded as a result of X being loaded, the StandardClassLoader
loads it (as the WebappClassLoader delegates to the
StandardClassLoader).

Now the stupifying part: class Y has a reference to a class X, *BUT* I
have put that class X in Y's jar.  Bottom line, there is to be two
different class X's, one loaded by WebappClassLoader (for the specific
webapp) and one by the StandardClassLoader (for common).  Based upon my
understanding of how the JVM tries to ensure "type safety" across
ClassLoaders,  StandardClassLoader loading the second version of class X
should fail with a LinkageError - because the defining loader for X is
already WebappClassLoader, and here we are trying to say the defining
loader is now StandardClassLoader.

The rub: Tomcat does not throw a LinkageError.  Instead it goes ahead
and loads the second class X just fine.  Doing an output of
getClass().getClassLoader() in the constructors of both class X's shows
that is being loaded in two different defining loaders.  Am I missing
something?  Given that the so-called loader/loading constraints are
enforced by the JVM, not any particular ClassLoader/app, I am
dumbfounded by this behavior.

Thanks in advance for any insights.

Reply via email to