Re: Strange ClassCastException: A puzzle for Java/ImageJ experts to help me wit?.

Posted by ctrueden on
URL: http://imagej.273.s1.nabble.com/Strange-ClassCastException-A-puzzle-for-Java-ImageJ-experts-to-help-me-wit-tp3692688p3692696.html

Hi Bill,

I agree with Dscho that it must be two ClassLoaders, each with their own
version of the class. I have never heard of this happening before, but it is
conceivable, since ImageJ uses its own ClassLoader, and maybe QTJava does
too (not sure).

Try this code:

ClassLoader stackLoader = stack.getClass().getClassLoader();
ClassLoader mqtvsLoader = MultiQTVirtualStack.class.getClassLoader();
IJ.log("stack loader = " + stackLoader);
IJ.log("mqtvs loader = " + mqtvsLoader);
IJ.log("Loaders equal? " + (stackLoader == mqtvsLoader) + "/" +
stackLoader.equals(mqtvsLoader));
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
ClassLoader ijLoader = ij.IJ.getClassLoader();
IJ.log("system loader = " + systemLoader);
IJ.log("ImageJ loader = " + ijLoader);

Check whether the numerical codes for the stack & mqtvs loaders line up with
the system and/or ImageJ loaders. Then you'll know which class loader is
loading which version of the class. But ultimately, this bug may not be
something easily fixed within your code -- it may require a change to
ImageJ. Not sure without further messing around...

-Curtis

On Wed, Apr 29, 2009 at 11:06 AM, Johannes Schindelin <
[hidden email]> wrote:

> Hi,
>
> On Wed, 29 Apr 2009, Bill Mohler wrote:
>
> > Thanks, Curtis.  Here's what I get
> >
> > MultiQTVirtualStack1
> > stack class = MultiQTVirtualStack
> > MultiQTVirtualStack class = MultiQTVirtualStack
> > Classes equal? false/false
> > path to MultiQTVirtualStack class =
> >
> file:/Applications/ImageJ/plugins/QuickTime_Plugins_MMRD041109/MultiQTVirtualStack.class
> > path to stack class =
> >
> file:/Applications/ImageJ/plugins/QuickTime_Plugins_MMRD041109/MultiQTVirtualStack.class
> > beforetheloop imp[3-Movie Overlay #1 : see Log window for details
> > 600x411x38961]
> > stack[600x411x38961]
> > intheloop j= 0 imp[3-Movie Overlay #1 : see Log window for details
> > 600x411x38961]
> > stack[600x411x38961]
> > MultiQTVirtualStack2
> > MultiQTVirtualStack3
> >
> >
> > So, mysteriously to me, the code you sent reports that they are NOT equal
> > classes.  However both paths point to the same class file!
>
> Then I am pretty certain that two different class loaders are competing
> for the class.
>
> Could you print ...getClass().getClassLoader(), too?
>
> Ciao,
> Dscho
>