commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rice...@netscape.net (Rice Yeh)
Subject RE: RE: Re: ClassCastException raised in newFactory() method when starting from JUnit test
Date Sat, 04 May 2002 17:44:10 GMT
Hi,
  I find a quick solution to this problem. It is to add the following properties to junit's
excluded.properties file, which is located in package junit.runner.

excluded.6=org.apache.commons.logging.*
excluded.7=org.xml.*

 Because Digest's test programs seem having similar problem. By adding org.xml.* to this file,
it is solved. By adding these two properties, then these kinds of classes will be loaded by
system classloader and hence not reloadable from junit. I just wonder developer writting this
test program have any other way out or just do not meet this problem.

Regards,
Rice

riceyeh@netscape.net (Rice Yeh) wrote:

>Hi,
>  newFactory() use thread context classloader to load class. It is like
>
>clazz = classLoader.loadClass(factoryClass);
>return (LogFactory) clazz.newInstance();
>
>where classLoader is thread context loader. I am confused with java's classloader's mechanism.
Does this problem have anything to do with namespace? It should be no. Isn't?
>  Another mail said this problem is just like anothe problem rasing ClassNotFound Exception.
Could any detail explanation be provided? Thank you.
>
>Regards,
>Rice
>
>
>
>"Juozas Baliuka" <baliuka@centras.lt> wrote:
>
>>Sorry,
>>"MyCass obj = (MyCass)Class.forName(MyCass.class.getName());"
>>----- Original Message -----
>>From: "Juozas Baliuka" <baliuka@centras.lt>
>>To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
>>Sent: Wednesday, May 01, 2002 9:49 PM
>>Subject: Re: ClassCastException raised in newFactory() method when starting
>>from JUnit test
>>
>>
>>> Hi,
>>> I am not sure about "newFactory()", but in the most problem is like this:
>>>
>>>   MyCass obj = Class.forName(MyCass.class.getName());
>>>
>>> This allways throws ClassCastException if this code is loaded not by
>>> "SystemClassLoader".
>>> In this case we have two diferent classes, the same name but not
>>> ClassLoader.
>>>
>>> This is OK:
>>> MyCass obj = Class.forName(MyCass.class.getName(),true,
>>> MyCass.class.getClassLoader() );
>>>
>>> Both classes have the same name and ClassLoader.
>>>
>>> if "newFactory()" doe's "Class.forName" it must have alternatyve:
>>> "newFactory(ClassLoader cl)" and use "cl" as parameter in "Class.forName".
>>>
>>>
>>>
>>>
>>> ----- Original Message -----
>>> From: "Rice Yeh" <riceyeh@netscape.net>
>>> To: ""Jakarta Commons Developers List"" <commons-dev@jakarta.apache.org>
>>> Sent: Wednesday, May 01, 2002 2:48 PM
>>> Subject: RE: ClassCastException raised in newFactory() method when
>>starting
>>> from JUnit test
>>>
>>>
>>> > Hi,
>>> >   Sorry, I past wrong attachement. The original one will not cause this
>>> problem. I attache a new one, which just moves
>>> >
>>> >         Digester d = new Digester();
>>> >         System.out.println("OK");
>>> > to testLogging() method.
>>> >
>>> > Regards,
>>> > Rice
>>> >
>>> > riceyeh@netscape.net (Rice Yeh) wrote:
>>> >
>>> > >Hi all,
>>> > >
>>> > > Just wonder why ClassCastException is raised at line 496 of LogFactory
>>> in newFactory() method when running as a JUnit test? I found this problem
>>> when running RequiredNameTest in commons-validator. When casting a class
>>to
>>> some superclass, does classloader from other thread form a namespace and
>>so
>>> can NOT cast it? Java language spec seems not regulate this. I have proven
>>> this with a small program.
>>> > > Attached are JUnit test files I use to study this problem.
>>> > >
>>> > >Regards,
>>> > >Rice
>>> > >
>>> > >
>>> > >__________________________________________________________________
>>> > >Your favorite stores, helpful shopping tools and great gift ideas.
>>> Experience the convenience of buying online with Shop@Netscape!
>>> http://shopnow.netscape.com/
>>> > >
>>> > >Get your own FREE, personal Netscape Mail account today at
>>> http://webmail.netscape.com/
>>> > >
>>> >
>>> >
>>> > __________________________________________________________________
>>> > Your favorite stores, helpful shopping tools and great gift ideas.
>>> Experience the convenience of buying online with Shop@Netscape!
>>> http://shopnow.netscape.com/
>>> >
>>> > Get your own FREE, personal Netscape Mail account today at
>>> http://webmail.netscape.com/
>>> >
>>>
>>>
>>> --------------------------------------------------------------------------
>>--
>>> ----
>>>
>>>
>>> > /*
>>> >  * TestSuite.java
>>> >  * JUnit based test
>>> >  *
>>> >  * Created on May 1, 2002, 7:38 PM
>>> >  */
>>> >
>>> > package test;
>>> >
>>> > import junit.framework.*;
>>> > import org.apache.commons.digester.Digester;
>>> >
>>> > /**
>>> >  *
>>> >  * @author Rice Yeh
>>> >  */
>>> > public class LoggingFromDigestTest extends TestCase
>>> > {
>>> >
>>> >     public LoggingFromDigestTest(java.lang.String testName)
>>> >     {
>>> >         super(testName);
>>> >     }
>>> >
>>> >     public static void main(java.lang.String[] args)
>>> >     {
>>> >
>>> >
>>> >         junit.swingui.TestRunner.run(suite());
>>> >     }
>>> >
>>> >     public void setUp()
>>> >     {
>>> >
>>> >     }
>>> >
>>> >
>>> >
>>> >     public static Test suite()
>>> >     {
>>> >         TestSuite suite = new TestSuite(LoggingFromDigestTest.class);
>>> >
>>> >         return suite;
>>> >     }
>>> >
>>> >     public void testLogging()
>>> >     {
>>> >         Digester d = new Digester();
>>> >         System.out.println("OK");
>>> >     }
>>> >
>>> >     public void tearDown()
>>> >     {
>>> >     }
>>> > }
>>> >
>>> >
>>>
>>>
>>> --------------------------------------------------------------------------
>>--
>>> ----
>>>
>>>
>>> > --
>>> > To unsubscribe, e-mail:
>>> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
>>> > For additional commands, e-mail:
>>> <mailto:commons-dev-help@jakarta.apache.org>
>>>
>>>
>>> --
>>> To unsubscribe, e-mail:
>><mailto:commons-dev-unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail:
>><mailto:commons-dev-help@jakarta.apache.org>
>>>
>>
>>
>>--
>>To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>>
>>
>
>
>__________________________________________________________________
>Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience
of buying online with Shop@Netscape! http://shopnow.netscape.com/
>
>Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
>
>
>--
>To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>
>


__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience
of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message