> -----Original Message----- > From: wohlgemuth [mailto:[EMAIL PROTECTED] > Sent: Wednesday, 9 August 2006 11:20 AM > To: user@ant.apache.org > Subject: weird problem with Class instanceOf > > hi, > > at first I work since a long time with ant and wrote arround > 50 ant tasks sofar, I thought I know what I do... > ...I was wrong > > anyway thats my problem: > > I have 3 classes > > 1. ClusterInitialzieTask, parent class:Task > > -> used to intialize a cluster and contains objects of type 2. or 3. > > 2. ClusterParameter, parent class: ProjectComponent > > -> a configuration parameter > > 3. Configuration, parent class: DataType > > -> my configuration containing objects of type 2. > > now I want to access the object configuration over a refrence > > <config id="conf"> > <parameter name="username" value="my name" /> > </config> > > > <initialize factory="tada"> > <config refid="conf"/> > </initialize> > > and always get: > > conf doesn't denote a config > at > org.apache.tools.ant.types.DataType.getCheckedRef(DataType.java:156) > at > edu.ucdavis.genomics.metabolomics.binbase.cluster.ant.Configur > ation.getContent(Configuration.java:68) > at > edu.ucdavis.genomics.metabolomics.binbase.cluster.ant.ClusterI > nitializeTask.getProperties(ClusterInitializeTask.java:122) > > method where the call happens: > > Object o = this.getCheckedRef(Configuration.class, "config"); > > > when I access the refrence object direclty in the setRefId > method and make a simple System.err: > > System.err.println(reference.getReferencedObject() instanceof > edu.ucdavis.genomics.metabolomics.binbase.cluster.ant.Configuration); > > System.err.println(reference.getReferencedObject().getClass()); > > i become an output like this: > > [initialize] false > [initialize] class > edu.ucdavis.genomics.metabolomics.binbase.cluster.ant.Configuration > > I know they are both from the same instance I just don't know > why my instanceof gives me a "false" and not a "true".
Sounds like you have a cloassloader chain issue. I'm guessing that the Configuration class that your casting to is not the same class as the Configuration class held as a reference. You confirm this by listing the system identity hashcode for both, e.g: Class local = Configuration.class; Class unknown = reference.getReferencedObject().getClass(); System.err.println( "LOCAL: " + System.identityHashCode( local ) ); System.err.println( "UNKNOWN: " + System.identityHashCode( unknown ) ); The values returned for the identity hashcode will probably be different which is why your instanceof test is failing. Assuming we are talking about separate instances it would be handy to find out where the respective classes are located. URL localURL = local.getProtectionDomain().getCodeSource().getLocation(); URL unknownURL = unknown.getProtectionDomain().getCodeSource().getLocation(); System.err.println( "LOCAL-URL: " + localURL ); System.err.println( "UNKNOWN-URL: " + unknownURL ); Assuming that the two locations are different you will need to figure out why the same class exists in two different locations (i.e. different classloaders where the common class is not actually available in a mutually accessible classloader). /Steve. > > does anybody has an idea? I can also provide the sourcecode > if requested. > > thx for your help, > > g. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] For > additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]