Re: ClassCastException after retrieving an Entry

Dan Creswell <[email protected]> Fri, 5 Jan 2007 14:00:21 +0000
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Gregg Wonderly wrote:
> Christian Hager wrote:
>> Ok I've put the code in. It now looks like the following.
>>
>> Entry entry = javaSpace.take (taskTmpl, txn, 30000);
>> ClassLoaderUtil.displayClassLoaderTree(entry.getClass
>> ().getClassLoader());
>> ClassLoaderUtil.displayClassLoaderTree(TaskEntry.class.getClassLoader());
>> ...
>
>
>> and that is what I get.
>
> Okay, this is interesting, but not complete.  It shows that there is
> only the
> boot classloader in common between these two objects class loader
> trees.  The
> origin of TaskEntry is hidden from the remote code because it's not
> loaded from
> a visible classloader.  I'd suggest that you might try
>
> Thread.currentThread().setContextClassLoader( TaskEntry.getClassLoader() );
>
> prior to the space.take() call to make that classloader visible.
>

And remember to restore it appropriately afterwards of course! ;)

Made that mistake a few times I have.....

And how about we dump out the current context classloader hierarchy as
well (did I miss that?)

> I'm not familiar with what eclipse is doing under the covers, but it
> appears to
> be isolating your code.  It might be that even the above will not work

I'd expect that - OSGi does exactly this sort of thing....

> because
> eclipse is using a different classloader resolution strategy than the J2SE
> loaders which always look at the context loader first, and then the app
> classloader tree.
>
> Gregg Wonderly
>
> ===========================================================================
> To unsubscribe, send email to [email protected] and include in the body
> of the message "signoff JAVASPACES-USERS".  For general help, send email to
> [email protected] and include in the body of the message "help".
>
> To view past JAVASPACES-USERS postings, please see:
> http://archives.java.sun.com/archives/javaspaces-users.html
>

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVASPACES-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

To view past JAVASPACES-USERS postings, please see:
http://archives.java.sun.com/archives/javaspaces-users.html