7 Replies Latest reply on Dec 3, 2006 8:11 AM by Marilen Corciovei

    ClassCastException when JBoss configures Log4j

    luisfpg Newbie

      I´m having problems when deploying an application within an EAR with it's own ClassLoader (via jboss-app.xml) containing an web module inside (which has the java2ClassLoadingCompliance="false").

      When JBoss tries to configure log4j, a ClassCastException occours.

      I've debugged and noticed that the ClassLoader containing the org.apache.log4j.Appender class is different from the one that contains the appender instance (org.jboss.logging.appender.DailyRollingFileAppender). The Appender class ClassLoader is a org.apache.catalina.loader.WebappClassLoader, while the DailyRollingFileAppender ClassLoader is a org.jboss.system.server.NoAnnotationURLClassLoader.

      So, with different ClassLoaders, the ClassCastException occours.

      How can I configure a web module that way (my app REQUIRES that the EAR ClassLoader is unique)?

      Thanks, and sorry if the post is a bit confusing ;)

        • 1. Re: ClassCastException when JBoss configures Log4j
          Scott Stark Master

          Show the full exception stack trace

          • 2. Re: ClassCastException when JBoss configures Log4j
            luisfpg Newbie

            Here's the full stack trace.
            The error happens after that JBoss has added the certificates.

            11:30:48,592 INFO [Engine] ContextConfig[/dbguardian]: Added certificates -> request attribute Valve
            11:30:51,256 INFO [EmbeddedCatalinaService41] Using Java2 parent classloader delegation: false
            11:30:51,256 INFO [Engine] StandardManager[/dbguardian]: Seeding random number generator class java.security.SecureRandom
            11:30:51,256 INFO [Engine] StandardManager[/dbguardian]: Seeding of random number generator has been completed
            11:30:54,200 ERROR [STDERR] log4j:ERROR Could not create an Appender. Reported error follows.
            11:30:54,200 ERROR [STDERR] java.lang.ClassCastException
            11:30:54,200 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:165)
            11:30:54,200 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:140)
            11:30:54,210 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:153)
            11:30:54,210 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:415)
            11:30:54,210 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:384)
            11:30:54,420 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:783)
            11:30:54,470 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:666)
            11:30:54,470 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:616)
            11:30:54,470 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:602)
            11:30:54,470 ERROR [STDERR] at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
            11:30:54,480 ERROR [STDERR] at org.apache.log4j.LogManager.(LogManager.java:113)
            11:30:54,650 ERROR [STDERR] at org.apache.log4j.Category.getInstance(Category.java:530)
            11:30:54,650 ERROR [STDERR] at org.apache.commons.logging.impl.Log4jFactory.getInstance(Log4jFactory.java:140)
            11:30:54,660 ERROR [STDERR] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:257)
            11:30:54,660 ERROR [STDERR] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:390)
            11:30:54,660 ERROR [STDERR] at org.apache.struts.action.ActionServlet.(ActionServlet.java:375)
            11:30:54,660 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            11:30:54,660 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            11:30:54,680 ERROR [STDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            11:30:54,680 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
            11:30:54,680 ERROR [STDERR] at java.lang.Class.newInstance0(Class.java:308)
            11:30:54,690 ERROR [STDERR] at java.lang.Class.newInstance(Class.java:261)
            11:30:54,690 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:903)
            11:30:54,690 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:823)
            11:30:54,700 ERROR [STDERR] at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3420)
            11:30:55,171 ERROR [STDERR] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3608)
            11:30:55,171 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:821)
            11:30:55,171 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
            11:30:55,181 ERROR [STDERR] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:579)
            11:30:55,331 ERROR [STDERR] at org.jboss.web.catalina.EmbeddedCatalinaService41.createWebContext(EmbeddedCatalinaService41.java:417)
            11:30:55,371 ERROR [STDERR] at org.jboss.web.catalina.EmbeddedCatalinaService41.performDeploy(EmbeddedCatalinaService41.java:266)
            11:30:55,391 ERROR [STDERR] at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:357)
            11:30:55,441 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
            11:30:55,441 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:824)
            11:30:55,441 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:640)
            11:30:55,441 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:613)
            11:30:55,451 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
            11:30:55,622 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            11:30:55,632 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
            11:30:55,632 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            11:30:55,632 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
            11:30:55,772 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
            11:30:55,772 ERROR [STDERR] at $Proxy7.deploy(Unknown Source)
            11:30:55,772 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
            11:30:55,772 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:458)
            11:30:55,782 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:200)
            11:30:55,782 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:211)
            11:30:55,782 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:190)
            11:30:55,792 ERROR [STDERR] log4j:ERROR Could not parse input source [org.xml.sax.InputSource@c99877].
            11:30:55,792 ERROR [STDERR] java.lang.NullPointerException
            11:30:55,792 ERROR [STDERR] at java.util.Hashtable.put(Hashtable.java:393)
            11:30:55,792 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:141)
            11:30:55,792 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:153)
            11:30:55,802 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:415)
            11:30:55,802 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:384)
            11:30:55,802 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:783)
            11:30:55,842 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:666)
            11:30:55,882 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:616)
            11:30:56,433 ERROR [STDERR] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:602)
            11:30:56,443 ERROR [STDERR] at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
            11:30:56,443 ERROR [STDERR] at org.apache.log4j.LogManager.(LogManager.java:113)
            11:30:56,443 ERROR [STDERR] at org.apache.log4j.Category.getInstance(Category.java:530)
            11:30:56,443 ERROR [STDERR] at org.apache.commons.logging.impl.Log4jFactory.getInstance(Log4jFactory.java:140)
            11:30:56,443 ERROR [STDERR] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:257)
            11:30:56,453 ERROR [STDERR] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:390)
            11:30:56,453 ERROR [STDERR] at org.apache.struts.action.ActionServlet.(ActionServlet.java:375)
            11:30:56,493 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            11:30:56,753 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            11:30:56,773 ERROR [STDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            11:30:56,773 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
            11:30:56,773 ERROR [STDERR] at java.lang.Class.newInstance0(Class.java:308)
            11:30:56,773 ERROR [STDERR] at java.lang.Class.newInstance(Class.java:261)
            11:30:56,773 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:903)
            11:30:56,793 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:823)
            11:30:56,793 ERROR [STDERR] at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3420)
            11:30:56,793 ERROR [STDERR] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3608)
            11:30:56,793 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:821)
            11:30:56,793 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
            11:30:56,793 ERROR [STDERR] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:579)
            11:30:56,803 ERROR [STDERR] at org.jboss.web.catalina.EmbeddedCatalinaService41.createWebContext(EmbeddedCatalinaService41.java:417)
            11:30:56,813 ERROR [STDERR] at org.jboss.web.catalina.EmbeddedCatalinaService41.performDeploy(EmbeddedCatalinaService41.java:266)
            11:30:56,823 ERROR [STDERR] at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:357)
            11:30:56,823 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
            11:30:56,843 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:824)
            11:30:56,873 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:640)
            11:30:56,913 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:613)
            11:30:56,953 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
            11:30:56,993 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            11:30:57,023 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
            11:30:57,064 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            11:30:57,094 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
            11:30:57,134 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
            11:30:57,134 ERROR [STDERR] at $Proxy7.deploy(Unknown Source)
            11:30:57,684 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
            11:30:57,714 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:458)
            11:30:57,754 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:200)
            11:30:57,754 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:211)
            11:30:57,764 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:190)

            • 3. Re: ClassCastException when JBoss configures Log4j
              Scott Stark Master

              This is why the use of singletons/static blocks in frameworks used by application code is bad. The org.apache.log4j.LogManager is reloading the conf/log4j.xml file and is loading jboss specific appenders which have already been linked against the log4j classes loaded outside of the ear.

              Set the log4j.defaultInitOverride System property to true to prevent this from occurring.

              • 4. Re: ClassCastException when JBoss configures Log4j
                Bunty K Newbie

                Hi,
                How do i set log4j.defaultInitOverride in my web application?

                • 5. Re: ClassCastException when JBoss configures Log4j
                  Matthew Parrish Newbie

                  At least the JBoss team is consistent with not finishing their replies.

                  You can set the log4j.defaultInitOverride system property by adding

                  -Dlog4j.defaultInitOverride=true

                  to the JAVA_OPTS line your run.bat (windows) or run.conf (linux) file.

                  • 6. Re: ClassCastException when JBoss configures Log4j
                    Marilen Corciovei Newbie

                    In fact this does not solves the problem as I am discussing here: http://www.len.ro/work/articles/jboss/webapp-logging/. The solution can be found in fact here: http://wiki.jboss.org/wiki/Wiki.jsp?page=Log4jConflictsInJBoss as this was the problem in my case.