7 Replies Latest reply on Mar 3, 2010 4:18 AM by galder.zamarreno

    NPE if using Infinispan without log4j.properties

    lowecg2004

      Hello,

       

      I'm just starting to kick the tyres with Infinispan (4.0.0.FINAL) and while doing so, I attempted to launch some code without having specified a log4j.properties which resulted in the following NPE:

       

      org.infinispan.config.ConfigurationException: org.infinispan.CacheException: Unable to construct a GlobalComponentRegistry!

      at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:285)

      at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:253)

      at com.test.server.CacheTest.testCache(CacheTest.java:13)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:597)

      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)

      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)

      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)

      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)

      at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)

      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

      at org.junit.runners.ParentRunner.run(ParentRunner.java:220)

      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

      Caused by: org.infinispan.CacheException: Unable to construct a GlobalComponentRegistry!

      at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:63)

      at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:283)

      ... 26 more

      Caused by: java.lang.NullPointerException

      at org.infinispan.manager.DefaultCacheManager.getAddress(DefaultCacheManager.java:486)

      at org.infinispan.manager.DefaultCacheManager.toString(DefaultCacheManager.java:668)

      at java.lang.String.valueOf(String.java:2826)

      at java.lang.StringBuilder.append(StringBuilder.java:115)

      at org.infinispan.factories.AbstractComponentRegistry$Component.toString(AbstractComponentRegistry.java:792)

      at java.lang.String.valueOf(String.java:2826)

      at org.infinispan.util.Util.formatString(Util.java:243)

      at org.infinispan.util.logging.AbstractLogImpl.trace(AbstractLogImpl.java:12)

      at org.infinispan.factories.AbstractComponentRegistry.registerComponent(AbstractComponentRegistry.java:221)

      at org.infinispan.factories.AbstractComponentRegistry.registerComponent(AbstractComponentRegistry.java:186)

      at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:58)

      ... 27 more

       

       

      Just thought I'd let you know.  Making a log4j.properties config available in my classpath with a level above trace works around the issue.

       

      Cheers,

       

      Chris.

        • 1. Re: NPE if using Infinispan without log4j.properties
          lowecg2004

          Ahh - I know what's at play here. I had log4j.1.2.11 in my classpath rather than 1.2.15.

           

          The earlier version of log4j causes all sorts of problems.  In case anyone else goes down this path then the next error I got was with JGroups failing to start:

           

          org.infinispan.CacheException: Unable to invoke method public abstract void org.infinispan.remoting.transport.Transport.start() on object

          at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:173)

          at org.infinispan.factories.AbstractComponentRegistry$PrioritizedMethod.invoke(AbstractComponentRegistry.java:852)

          at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:672)

          at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:574)

          at org.infinispan.factories.GlobalComponentRegistry.start(GlobalComponentRegistry.java:131)

          at org.infinispan.factories.ComponentRegistry.start(ComponentRegistry.java:135)

          at org.infinispan.CacheDelegate.start(CacheDelegate.java:311)

          at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:507)

          at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:473)

          at com.test.server.CacheTest.testCache(CacheTest.java:15)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          at java.lang.reflect.Method.invoke(Method.java:597)

          at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

          at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

          at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

          at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)

          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)

          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)

          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)

          at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)

          at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

          at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:220)

          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

          Caused by: java.lang.reflect.InvocationTargetException

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          at java.lang.reflect.Method.invoke(Method.java:597)

          at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:170)

          ... 33 more

          Caused by: org.infinispan.CacheException: Unable to start JGroups channel

          at org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel(JGroupsTransport.java:285)

          at org.infinispan.remoting.transport.jgroups.JGroupsTransport.initChannel(JGroupsTransport.java:205)

          at org.infinispan.remoting.transport.jgroups.JGroupsTransport.initChannelAndRPCDispatcher(JGroupsTransport.java:221)

          at org.infinispan.remoting.transport.jgroups.JGroupsTransport.start(JGroupsTransport.java:154)

          ... 38 more

          Caused by: org.jgroups.ChannelException: unable to setup the protocol stack

          at org.jgroups.JChannel.init(JChannel.java:1706)

          at org.jgroups.JChannel.<init>(JChannel.java:243)

          at org.jgroups.JChannel.<init>(JChannel.java:209)

          at org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel(JGroupsTransport.java:283)

          ... 41 more

          Caused by: java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()Z

          at org.jgroups.logging.Log4JLogImpl.isTraceEnabled(Log4JLogImpl.java:48)

          at org.jgroups.stack.Configurator.determineIpVersionFromAddresses(Configurator.java:468)

          at org.jgroups.stack.Configurator.setupProtocolStack(Configurator.java:102)

          at org.jgroups.stack.Configurator.setupProtocolStack(Configurator.java:54)

          at org.jgroups.stack.ProtocolStack.setup(ProtocolStack.java:453)

          at org.jgroups.JChannel.init(JChannel.java:1702)

          ... 44 more

           

          The solution is to get log4j.1.2.15 and make sure this is version that appears first in your CP.

           

          Cheers,

           

          Chris.

          • 2. Re: NPE if using Infinispan without log4j.properties
            yahro
            The same problem here, however upgrading to log4j 1.2.15 does not solve the problem. In general, for trace level of logging I'm getting NPE.
            • 3. Re: NPE if using Infinispan without log4j.properties
              galder.zamarreno

              I can't see any NPE in the stacktrace you posted, but I suspect this NPE might be this: https://jira.jboss.org/jira/browse/ISPN-355

               

              Can you verify?

              • 4. Re: NPE if using Infinispan without log4j.properties
                lowecg2004

                In Eclipse, I also had to make sure that log4j.1.2.15 appeared first in my classpath - some other libraries used by my project had their own version of log4j defined.

                 

                Also, at runtime I was accessing Infinispan from a servlet so I had to manually remove an old log4j jar from my WEB-INF/lib and replace with the new version.

                 

                Cheers,

                 

                Chris.

                • 5. Re: NPE if using Infinispan without log4j.properties
                  lowecg2004

                  Hi Galder,

                   

                  The exception is wrapped a few times before being dumped to log.  At the bottom of the stack trace posted in the first entry there is the following:

                   

                  Caused by: java.lang.NullPointerException

                  at org.infinispan.manager.DefaultCacheManager.getAddress(DefaultCacheManager.java:486)

                  at org.infinispan.manager.DefaultCacheManager.toString(DefaultCacheManager.java:668)

                  at java.lang.String.valueOf(String.java:2826)

                  at java.lang.StringBuilder.append(StringBuilder.java:115)

                  at org.infinispan.factories.AbstractComponentRegistry$Component.toString(AbstractComponentRegistry.java:792)

                  at java.lang.String.valueOf(String.java:2826)

                   

                  Cheers,

                   

                  Chris.

                  • 6. Re: NPE if using Infinispan without log4j.properties
                    lowecg2004

                    I've just checked the Jira case and it looks like a match to me:

                     

                    From the Jira case:


                    Caused by: java.lang.NullPointerException
                    at org.infinispan.manager.DefaultCacheManager.getAddress(DefaultCacheManager.java:486)
                    at org.infinispan.manager.DefaultCacheManager.toString(DefaultCacheManager.java:668)

                    at java.lang.String.valueOf(String.java:2838)
                    at java.lang.StringBuilder.append(StringBuilder.java:132)
                    at org.infinispan.factories.AbstractComponentRegistry$Component.toString(AbstractComponentRegistry.java:792)
                    at java.lang.String.valueOf(String.java:2838)
                    at org.infinispan.util.Util.formatString(Util.java:243)
                    at org.infinispan.util.logging.AbstractLogImpl.trace(AbstractLogImpl.java:12)
                    at org.infinispan.factories.AbstractComponentRegistry.registerComponent(AbstractComponentRegistry.java:221)
                    at org.infinispan.factories.AbstractComponentRegistry.registerComponent(AbstractComponentRegistry.java:186)
                    at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:58)
                    ... 34 more

                     

                     

                    From my post:

                     

                    Caused by: java.lang.NullPointerException

                    at org.infinispan.manager.DefaultCacheManager.getAddress(DefaultCacheManager.java:486)

                    at org.infinispan.manager.DefaultCacheManager.toString(DefaultCacheManager.java:668)

                    at java.lang.String.valueOf(String.java:2826)

                    at java.lang.StringBuilder.append(StringBuilder.java:115)

                    at org.infinispan.factories.AbstractComponentRegistry$Component.toString(AbstractComponentRegistry.java:792)

                    at java.lang.String.valueOf(String.java:2826)

                     

                     

                    Cheers,

                     

                    Chris.

                    • 7. Re: NPE if using Infinispan without log4j.properties
                      galder.zamarreno

                      The issue has been fixed in both trunk (http://anonsvn.jboss.org/repos/infinispan/trunk/) and a 4.0.x branch (http://anonsvn.jboss.org/repos/infinispan/branches/4.0.x/) we've created last week. So, if you really need the fix, simply export or check out one of them two and run:

                       

                      mvn -Dmaven.test.skip.exec=true install -P distribution