Re: ClassCastException after retrieving an Entry

Gregg Wonderly <[email protected]> Thu, 4 Jan 2007 10:31:09 -0600
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Christian Hager wrote:
> I tried the thing with  the classloader and it gives me
>
> My Entry Loader:
> sun.rmi.server.LoaderHandler$Loader@1930ebb["ahttp://computegrid:[email protected]/codebase/codebase.jar"]
>
> My TaskEntry Loader:
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@1079781
>
> for the following code
>
> Entry entry = javaSpace.take (taskTmpl, txn, 30000);
> System.out.println("My Entry Loader: "+ entry.getClass().getClassLoader());
> System.out.println("My TaskEntry Loader: "+
> TaskEntry.class.getClassLoader());
> TaskEntry task = (TaskEntry) javaSpace.take (taskTmpl, txn, 30000);
>
> the Exception then occurs in the 4th line of the code and is as follows
>
> java.lang.ClassCastException: org.ac.computegrid.TaskEntry

Okay, so this doesn't tell us the answer yet.  The next thing that you need to
do is

Class[]cs = entry.getClass().getClasses();
for( Class c : cs ) {
        System.out.println(c.getName()+": loader="+c.getClassLoader() );
}

to see what each class in the entry is loaded by.  In particular, the loader for
TaskEntry needs to be the same class loader as "My TaskEntry Loader" shows.

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