ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: AntClassLoader leads to ClassCastException
Date Wed, 27 Feb 2002 10:20:02 GMT
On Tue, 26 Feb 2002, Gurdev Parmar <> wrote:

> public TestClient createDynamically(String classname, AntClassLoader acl) { 
>     Class clazz = acl.findClass(classname);
>     return (TestClient) clazz.newInstance();
> }

> The method is invoked with classname as "TestEjbSelect".
> I get a ClassCastException at the "return (TestClient)
> clazz.newInstance()" point. When run in debug mode I can see that
> TestClient and TestEjbSelect are being loaded from the ant loader.

I don't see that.

I see TestClient being loaded by ant class loader(s) twice, which
makes me suspect you have two instances of AntClassloader's loading
this class (those would be incompatible).

And I don't see any message that TestEjbSelect has been loaded at all.
The messages about TestEjbSelect look as if you had called
forceLoadClass which you certainly don't do in the code snippet above.

What I suspect is happening here is that you load TestClient and
TestEjbSelect in AntClassLoader 1, then again load TestClient in
AntClassLoader 2 and try to cast TestEjbSelect from class loader 1 to
a TestClient from 2.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message