ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <bode...@apache.org>
Subject Re: AntClassLoader leads to ClassCastException
Date Wed, 27 Feb 2002 10:20:02 GMT
On Tue, 26 Feb 2002, Gurdev Parmar <gparmar@versant.com> 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.

Stefan

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message