commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From radone <debianu...@seznam.cz>
Subject Re: Javaflow - cannot be cast
Date Tue, 15 Jul 2008 10:51:22 GMT


tcurdt wrote:
> 
>>
>> I am getting:
>> java.lang.ClassCastException: my.test.MyRunnable cannot be cast to
>> my.test.IRunnable
>> 	at my.test.MyRunnable.main(MyRunnable.java:29)
> 
> 
>> I guess it has something to do with class rewriting and thus
>> my.test.IRunnable is not possible to cast to rewriten  
>> my.test.IRunnable.
>> Has anyone any suggestion how to deal with it?
> 
> I guess it's more likely to be a class loading problem.
> 
> Print out the classloaders involved. That should give you more insights.
> 
> Who loaded IRunnable? Who loaded the instance?
> 
>   Object o = clz.newInstance();
>   System.out.println(o.getClass().getClassLoader());
>   IRunnable r = (IRunnable) o;
>   System.out.println(r.getClass().getClassLoader());
> 
> 
> cheers
> --
> Torsten
> 
> 

For anyone interested in the same problem - after some debugging and reading
the Javaflow ContinuationClassLoader code I found a solution. The only thing
what is neccessary to do is to exclude the base class from JavaFlow class
loader and force the loading by "parent" class loader. This can be done by
moving the IRunnable to different package and adding this package (e.g.
"my.excluded") as a system root: 

			final ContinuationClassLoader cl = new ContinuationClassLoader(
					new URL[] { new URL("file://bin") }, MyRunnable.class
							.getClassLoader());

			cl.addSystemPackageRoot("my.excluded");
			cl.addLoaderPackageRoot("my.test");


Thanks for help.
-- 
View this message in context: http://www.nabble.com/Javaflow---cannot-be-cast-tp18460050p18462363.html
Sent from the Commons - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message