----- Original Message -----
From: "Andrew Inggs" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, July 27, 2001 10:01 AM
Subject: RE: WebappClassLoader question


> Hi Vincent
>
> You seem to be missing at least two things here:
>
> 1. In your original post you said:
>
> > When I access the servlet, I get a ClassNotFoundException on a
> > JUnit class. So far it is normal ...
> > When I debugged it, I have actually found that the error was
> > happening when ServletTestRedirector was instancianting
> > MyProxyClass (which does _not_ make use of JUnit) and before
> > it was calling its method.
>
> This does not look right.  You say MyProxyClass does not make
> use of JUnit, but it *does*.  This is the line that causes it to:
>
> > testInstance = (ServletTestCase)constructor.newInstance(new Object[] {
> theMethod });
>
> You see here you are explicitly referencing ServletTestCase which
> extends junit.framework.TestCase, this introduces the dependency.
>

That's true. I may have used the wrong word. What I meant is that the
MyProxyClass did not have a JUnit import statement, meaning it did not make
a _direct_ use of JUnit. But as you point out, ServletTestCase does make a
direct use of JUnit.

> 2. You seem to be assuming that NoClassDefFoundError extends
> Exception, but it doesn't.  If you want to catch a
> NoClassDefFoundError you'll have to catch it directly, or one of
> its superclasses (java.lang.LinkageError, java.lang.Error, or
> java.lang.Throwable).  This is why "I would have thought here"
> never gets printed out:
>
> >       } catch (Exception e) {
> >         log("I would have thought here");
> >       }
>

That's also true but that's the question I am asking ... ! Why do I get a
NoClassDefFoundError whereas I was expecting a ClassNotFoundException !
Please see Craig's answer and my other posts for a better description of
what error I am getting and what I am trying to achieve.

> As an aside, I'm not sure what you are trying to achieve here?
> You don't have junit.jar in your classpath, and then you're say
> you get this strange error.  The details aside, isn't that what
> you'd expect :-)?  Even if you hadn't referenced ServletTestCase
> directly, you still wouldn't have been able to instantiate it
> using reflection without junit.jar in the classpath.  What are
> you really trying to achieve?
>

As Alex kindly answered on the list, I would like to catch this error nicely
(when junit.jar is not in the classpath) so that I can display a good and
relevant message for the end user, telling him to put the class on the class
path ... When I debugged the code to know why I wasn't catching the
exception, I noticed that the error happened in a strange place, i.e. the
first class in the chain of dependencies and that's what I find strange. I
have had no previous experience of this kind of class loading mechanism and
I find it very very hard to debug (It means you have to put try catch blocks
everywhere in your first class being called in your webapp if you want to
catch for possible error resulting from classes not in the classapth !).

> -- Andrew

Thanks Andrew for your help!
-Vincent

Reply via email to