You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Paul Galbraith <pg...@trigoncanada.com> on 2004/08/03 23:59:30 UTC

[Logging] ClassLoader hierarchy problems under JUnit swingui TestRunner

I made a very simple class that created a static log instance, and ran
it under JUnit's swing testrunner, and commons logging puked with
exceptions regarding an invalid ClassLoader hierarchy.  Have I done
something stupid?  Or is this just a fact of life, and I can't test
logging apps using JUnit's GUI TestRunner?

Cheers,

Paul

------------

For reference, I'm using JUnit 3.8.1, Logging 1.04, and Sun JDK 1.4.2.
My test class is:

import junit.framework.*;
import org.apache.commons.logging.*;

public class TestLogging extends TestCase {
    private static Log log = LogFactory.getLog(TestLogging.class);
    public void testLogging() {
	assertTrue(log != null);
    }
}

Compiling and running "java -classpath '.;junit.jar;commons-logging.jar'
junit.swingui.TestRunner TestLogging" dumps the exception stack trace to
the console.

Here is the output I see:

----------

java.lang.ExceptionInInitializerError
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at junit.framework.TestSuite.createTest(TestSuite.java:131)
	at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
	at junit.framework.TestSuite.<init>(TestSuite.java:75)
	at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:103)
	at junit.swingui.TestRunner.runSuite(TestRunner.java:591)
	at
junit.swingui.TestRunner$9.actionPerformed(TestRunner.java:283)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown
Source)
	at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown
Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown
Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException: Invalid class
loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed. (Caused
by org.apache.commons.logging.LogConfigurationException: Invalid class
loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed.) (Caused
by org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException: Invalid class
loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed. (Caused
by org.apache.commons.logging.LogConfigurationException: Invalid class
loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed.))
	at
org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImp
l.java:543)
	at
org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImp
l.java:235)
	at
org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImp
l.java:209)
	at
org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
	at TestLogging.<clinit>(TestLogging.java:5)
	... 33 more
Caused by: org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException: Invalid class
loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed. (Caused
by org.apache.commons.logging.LogConfigurationException: Invalid class
loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed.)
	at
org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFact
oryImpl.java:397)
	at
org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImp
l.java:529)
	... 37 more
Caused by: org.apache.commons.logging.LogConfigurationException: Invalid
class loader hierarchy.  You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed.
	at
org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFact
oryImpl.java:385)
	... 38 more


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Logging] ClassLoader hierarchy problems under JUnit swingui TestRunner

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi paul

it looks to me like there are two versions of commons-logging present  
in your classpath. try running the test without the commons-logging.jar  
on the classpath. if this doesn't work but print up an exception  
concerning not being able to find a particular log implementation then  
you need to take a look at the jars which ship with the testrunning and  
replace their commons-logging jar with your own.

- robert

On 3 Aug 2004, at 22:59, Paul Galbraith wrote:

> I made a very simple class that created a static log instance, and ran
> it under JUnit's swing testrunner, and commons logging puked with
> exceptions regarding an invalid ClassLoader hierarchy.  Have I done
> something stupid?  Or is this just a fact of life, and I can't test
> logging apps using JUnit's GUI TestRunner?
>
> Cheers,
>
> Paul
>
> ------------
>
> For reference, I'm using JUnit 3.8.1, Logging 1.04, and Sun JDK 1.4.2.
> My test class is:
>
> import junit.framework.*;
> import org.apache.commons.logging.*;
>
> public class TestLogging extends TestCase {
>     private static Log log = LogFactory.getLog(TestLogging.class);
>     public void testLogging() {
> 	assertTrue(log != null);
>     }
> }
>
> Compiling and running "java -classpath  
> '.;junit.jar;commons-logging.jar'
> junit.swingui.TestRunner TestLogging" dumps the exception stack trace  
> to
> the console.
>
> Here is the output I see:
>
> ----------
>
> java.lang.ExceptionInInitializerError
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
> Source)
> 	at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
> Source)
> 	at java.lang.reflect.Constructor.newInstance(Unknown Source)
> 	at junit.framework.TestSuite.createTest(TestSuite.java:131)
> 	at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
> 	at junit.framework.TestSuite.<init>(TestSuite.java:75)
> 	at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:103)
> 	at junit.swingui.TestRunner.runSuite(TestRunner.java:591)
> 	at
> junit.swingui.TestRunner$9.actionPerformed(TestRunner.java:283)
> 	at javax.swing.AbstractButton.fireActionPerformed(Unknown
> Source)
> 	at
> javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
> Source)
> 	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
> Source)
> 	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> 	at
> javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown  
> Source)
> 	at java.awt.Component.processMouseEvent(Unknown Source)
> 	at java.awt.Component.processEvent(Unknown Source)
> 	at java.awt.Container.processEvent(Unknown Source)
> 	at java.awt.Component.dispatchEventImpl(Unknown Source)
> 	at java.awt.Container.dispatchEventImpl(Unknown Source)
> 	at java.awt.Component.dispatchEvent(Unknown Source)
> 	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown
> Source)
> 	at java.awt.LightweightDispatcher.processMouseEvent(Unknown
> Source)
> 	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> 	at java.awt.Container.dispatchEventImpl(Unknown Source)
> 	at java.awt.Window.dispatchEventImpl(Unknown Source)
> 	at java.awt.Component.dispatchEvent(Unknown Source)
> 	at java.awt.EventQueue.dispatchEvent(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
> Source)
> 	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
> Source)
> 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> 	at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: org.apache.commons.logging.LogConfigurationException:
> org.apache.commons.logging.LogConfigurationException:
> org.apache.commons.logging.LogConfigurationException: Invalid class
> loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed. (Caused
> by org.apache.commons.logging.LogConfigurationException: Invalid class
> loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed.)  
> (Caused
> by org.apache.commons.logging.LogConfigurationException:
> org.apache.commons.logging.LogConfigurationException: Invalid class
> loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed. (Caused
> by org.apache.commons.logging.LogConfigurationException: Invalid class
> loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed.))
> 	at
> org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryIm 
> p
> l.java:543)
> 	at
> org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryIm 
> p
> l.java:235)
> 	at
> org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryIm 
> p
> l.java:209)
> 	at
> org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
> 	at TestLogging.<clinit>(TestLogging.java:5)
> 	... 33 more
> Caused by: org.apache.commons.logging.LogConfigurationException:
> org.apache.commons.logging.LogConfigurationException: Invalid class
> loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed. (Caused
> by org.apache.commons.logging.LogConfigurationException: Invalid class
> loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed.)
> 	at
> org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFac 
> t
> oryImpl.java:397)
> 	at
> org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryIm 
> p
> l.java:529)
> 	... 37 more
> Caused by: org.apache.commons.logging.LogConfigurationException:  
> Invalid
> class loader hierarchy.  You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not allowed.
> 	at
> org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFac 
> t
> oryImpl.java:385)
> 	... 38 more
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org