7 Replies Latest reply on Jun 20, 2003 10:05 PM by Adrian Brock

    NullPointerException in "local" EJB invocation

    pickatrail Newbie

      I have a web application (war file) that invokes an EJB on another machine. It works fine. However, when I deploy the war file on the same server that runs the EJB, I get NullPointerException:

      17:06:23,124 ERROR [LogInterceptor] RuntimeException:
      java.lang.NullPointerException
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invokeHome(StatelessSessionContainer.java:592)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:206)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(StatelessSessionInstanceInterceptor.java:51)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
        at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:92)
        at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
        at org.jboss.ejb.StatelessSessionContainer.internalInvokeHome(StatelessSessionContainer.java:310)
        at org.jboss.ejb.Container.invoke(Container.java:694)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
        at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:101)
       at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:88)
        at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
        at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
        at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:175)
        at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:82)
        at $Proxy175.create(Unknown Source)
        ....


      It seems that JBoss has decided that the invocation is local to the server, but nonetheless is not handling it properly. It is probably a bug to have a NullPointerException from the container. Is there any way to get around this problem? Thanks in advance.

      p.s. I'm using JBoss 3.2.0.

        • 1. Re: NullPointerException in "local" EJB invocation
          pickatrail Newbie

          I think I've found the cause. I'm using <loader-repository> in WEB-INF/jboss-web.xml of my war file and META-INF/jboss-app.xml of my ear file to scope class loading at application level. Therefore my home interface is loaded by multiple class loaders, and StatelessSessionContainer$ContainerInterceptor.invokeHome() cannot find a matching method during cross-application (or rather cross-loader) invocation on the local server.

          It seems like an JBoss bug to me &mdash; the invocation interceptor cannot handle the more complicated class loading scenario. Any suggestion?

          • 2. Re: NullPointerException in "local" EJB invocation
            Adrian Brock Master

            You can only use local invocations if you
            are doing pass by reference.

            You can't do pass by reference if the object
            has to be marshalled between different class
            instances.

            Regards,
            Adrian

            • 3. Re: NullPointerException in "local" EJB invocation
              pickatrail Newbie

              Thanks for the response. However, I am not using local invocation as in EJB 2.0. I suppose I didn't make it clear enough, although I did put "local" in quote on the subject. By "local" I mean the JBoss optimization to route invocation differently if both the caller and the callee are within the same JVM.

              Let me try to add more details:

              - JSP page in a standalone war file calls an EJB through its remote interface. The initial naming context for looking up the EJB home is created with an URL (jnp://host:port/).

              - The war file uses HeirarchicalLoaderRepository3 to isolate its classes from other applications.

              - The EJB is packaged in a ear file, also using HeirarchicalLoaderRepository3.

              - When the war file and the ear file are deployed on separate JBoss servers, all is well.

              - When the same war is deployed on the server hosting the ear file, NullPointerException results.

              This is probably not a class loading issue on the application part -- both deployable units are already configured with maximum isolation.

              • 4. Re: NullPointerException in "local" EJB invocation
                Juha Lindfors Master

                Is there a reason why you are isolating your web tier from your ejb tier into separate loader repositories, or did I misunderstood what you're trying to do?

                IIRC you need to configure ByValueInterceptor in case you want to invoke across different loader repositories within the same JVM, but usually you'd just configure both the web tier and the ejb tier to use the same loader repository.

                Sorry if I'm way off base.

                • 5. Re: NullPointerException in "local" EJB invocation
                  Adrian Brock Master

                  You can simulate the remote invocation
                  from a different vm by using the
                  ByValueInvokerInterceptor instead of
                  the InvokerInterceptor.

                  All parameters and return values will be marshalled.
                  The local optimization on the remote interface
                  is not used.

                  Regards,
                  Adrian

                  • 6. Re: NullPointerException in "local" EJB invocation
                    pickatrail Newbie

                    Thanks Adrian and Juha for your suggestion. Switching to ByValueInvokerInterceptor gets rids of the NullPointerException, but the failure shifts to a MarshalException:

                    23:44:35,632 ERROR [LogInterceptor] EJBException, causedBy:
                    java.rmi.MarshalException: error marshalling arguments; nested exception is:
                      java.io.NotSerializableException: org.jboss.tm.TransactionImpl
                    java.io.NotSerializableException: org.jboss.tm.TransactionImpl
                      at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1143)
                      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
                      at org.jboss.invocation.MarshalledInvocation.writeExternal(MarshalledInvocation.java:381)
                      at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1167)
                      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
                      at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:263)
                      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:101)
                      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
                      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:139)
                      at org.jboss.invocation.ByValueInvokerInterceptor.invoke(ByValueInvokerInterceptor.java:65)
                      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
                      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
                      at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:175)
                      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:82)
                      at $Proxy165.findByPrimaryKey(Unknown Source)
                      ...


                    I think I should explore using the same repository for the ear and the war. I'm new to JBoss, but so far my impression is that JBoss class loading is still evolving &mdash; http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t= is another problem I have, if you have time :)

                    • 7. Re: NullPointerException in "local" EJB invocation
                      Adrian Brock Master

                      This is fixed in jboss3.2.2RC1
                      I posted the patch in some other post if you
                      want to backport it.

                      Regards,
                      Adrian