|
Re: ClassLoader Problem (ClassCastException)? [message #461553 is a reply to message #461543] |
Fri, 12 January 2007 00:11 |
|
Christian Hager wrote:
> Hi,
>
> I'm having some difficulties with osgi classloading and I'm hoping
> someone here can help me.
>
> I have one class ResultEntry and a class FactorialResult which extends
> ResultEntry. Now in one of my bundles I get an resultEntry object which
> really is a FactorialTask from another bundle an then I want to
> FactorialTask using the following code
>
> FactorialResult fact = (FactorialResult) resultEntry;
>
> Now when I try to do so I get a the following exception.
>
> java.lang.ClassCastException:
> org.ac.computegrid.jobs.fibfact.FactorialResult
I know this sounds odd, but is FactorialTask a subclass of
FactorialResult (since you only mentioned FactorialResult is a subclass
of ResultEntry).
If it is, then something to be careful about is that each class is only
contributed once. i.e. if plugin A has ResultEntry and FactorialResult
and plugin B had FactorialResult and FactorialTask, you can get into
trouble.
Later,
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
|
|
Re: ClassLoader Problem (ClassCastException)? [message #461595 is a reply to message #461543] |
Fri, 12 January 2007 23:33 |
|
Christian Hager wrote:
> Hi,
>
> I'm having some difficulties with osgi classloading and I'm hoping
> someone here can help me.
>
> I have one class ResultEntry and a class FactorialResult which extends
> ResultEntry. Now in one of my bundles I get an resultEntry object which
> really is a FactorialTask from another bundle an then I want to
> FactorialTask using the following code
>
> FactorialResult fact = (FactorialResult) resultEntry;
>
> Now when I try to do so I get a the following exception.
>
> java.lang.ClassCastException:
> org.ac.computegrid.jobs.fibfact.FactorialResult
OK, sorry about that. Let me try a different tact.
Plugins can see classes in their Bundle-ClassPath (PDE Editor>Runtime
tab>Classpath) ... which means they can see classes in that plugin + any
jars included in the plugin.
Plugins can see classes from their required plugins, if the required
plugin exports the appropriate package.
So if plugin A has ResultEntry and FactorialResult and exports the
correct packages, plugin B can cast a ResultEntry to a FactorialResult.
If Plugin A exports ResultEntry and plugin B exports FactorialResult and
plugin C gets a ResultEntry from A (which happens to be a
FactorialResult), plugin C cannot cast the ResultEntry to a
FactorialResult because it cannot see plugin B (unless it requires both
plugin A and plugin B).
In your setup, which plugin defines ResultEntry and FactorialResult?
Which plugin returns a ResultEntry that is a FactorialResult? Which
plugin requests the ResultEntry that is a FactorialResult?
What are the plugin dependencies?
Later,
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
|
|
Re: ClassLoader Problem (ClassCastException)? [message #461616 is a reply to message #461614] |
Sat, 13 January 2007 19:07 |
Christian Hager Messages: 53 Registered: July 2009 Location: Germany |
Member |
|
|
In article <eob5n1$49b$1@utils.eclipse.org>,
Paul Webster <pwebster@ca.ibm.com> wrote:
> Christian Hager wrote:
> > Ok let me try to explain more in detail. First we have Plugin A which
> > contains ResultEntry, second Plugin B which contains the
> > FactorialResult. Now I've Plugin C which requires A and takes the
> > ResultEntry from the JavaSpace and hands it over to Plugin B. Plugin B
> > requires Plugin A and itsself contains FactorialResult as told above. So
> > if I get your description right I should be able to cast, right?
>
> Who is doing the cast? Plugin B, after Plugin C hands it the resultEntry?
>
> If plugin A creates the object, it will only be a ResultEntry, right?
> That cannot be cast to a FactorialResult, since it isn't one.
>
> If I've misinterpreted your description, please post again :-)
>
> Later,
> PW
Plugin B is doing the cast. The object really is a FactorialResult which
I can see from the eclipse debugger. It is created remotely by my worker
application and stored in the javaspace. Plugin C takes it from the
JavaSpace with the code from my post before.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03999 seconds