4 Replies Latest reply on Aug 19, 2011 8:14 AM by vandfr

    NPE sending an ObjectMessage

    gcontini

      Hi!

      I'm using jboss6 final (Hornetq 2.1.2?) I'm trying to send an ObjectMessage on a queue. The sender.send method completes correctly but the message is not sent, and in server logs i'm getting this message:

       

       

      {code}

      10:23:00,952 ERROR [ServerSessionPacketHandler] Caught unexpected exception: java.lang.NullPointerException

                at org.hornetq.core.server.impl.ServerSessionImpl.send(ServerSessionImpl.java:992) [:6.0.0.Final]

                at org.hornetq.core.protocol.core.ServerSessionPacketHandler.handlePacket(ServerSessionPacketHandler.java:461) [:6.0.0.Final]

                at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:471) [:6.0.0.Final]

                at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:451) [:6.0.0.Final]

                at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:412) [:6.0.0.Final]

                at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:459) [:6.0.0.Final]

                at org.hornetq.core.remoting.impl.invm.InVMConnection$1.run(InVMConnection.java:135) [:6.0.0.Final]

                at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100) [:6.0.0.Final]

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_23]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_23]

                at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]

      {code}

       

      Looking at HornetQ source at line 992 of ServerSessionImpl i find:

       

          if (message.getAddress().equals(managementAddress))

       

      Here is a snippet from my jboss.xml

      {code:xml}

      <message-driven>

                <ejb-name>BloccoServiceQueue</ejb-name>

                <activation-config>

                          <activation-config-property>

                                    <activation-config-property-name>destinationType</activation-config-property-name>

                                    <activation-config-property-value>javax.jms.Queue</activation-config-property-value>

                          </activation-config-property>

                          <activation-config-property>

                                    <activation-config-property-name>destination</activation-config-property-name>

                                    <activation-config-property-value>queue/BloccoServiceQueue</activation-config-property-value>

                          </activation-config-property>

                </activation-config>

                <!-- destination-jndi-name>queue/BloccoServiceQueue</destination-jndi-name -->

                <mdb-user>guest</mdb-user>

                <mdb-passwd>guest</mdb-passwd>

                <create-destination>true</create-destination>

      </message-driven>

      {code:xml}

       

      Here is my MDB declaration:

      {code}

      @javax.ejb.MessageDriven(name = "BloccoServiceQueue", mappedName = "queue/BloccoServiceQueue")

      public class BloccoServiceQueueMDBBeanImpl implements javax.jms.MessageListener {

      {code}

       

      Here is my mdb client (inside an ejb)

      {code}

      @javax.annotation.Resource(mappedName = "java:/JmsXA")

      protected javax.jms.QueueConnectionFactory queueFactory;

      @javax.annotation.Resource(mappedName = "queue/BloccoServiceQueue")

      protected javax.jms.Destination bloccoServiceQueue;

      ....

      private void sendMsg() {

                try {

                          final Queue dest = (Queue) this.bloccoServiceQueue;

                          final QueueConnection connection = this.queueFactory.createQueueConnection();

                          final QueueSession qsess = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                          final QueueSender sender = qsess.createSender(dest);

                          final ObjectMessage message = qsess.createObjectMessage("simplePayloadToTestClassloadingIssues");

                                    LOGGER.info("Publishing Message to a Queue: " + this.bloccoServiceQueue);

                                    sender.send(message);

                          sender.close();

                          qsess.close();

                          connection.close();

                } catch (final Exception e) {

                          LOGGER.error("JMS provider fails to set the object due to some internal error.", e);

                }

      }

      {code}

       

      * Until now i haven't been able to reproduce this error on a simple example.

      * I've been trying to send an ObjectMessage whose payload is a string to avoid classloader issues. In real i need to send a complex object (i'm not worried by performances right now).

      * If i send a TextMessage everything works fine.

       

      Other people seem to have a StackTrace like mine https://issues.jboss.org/browse/HORNETQ-489

      In can provide further information/configuration.

      Any ideas?

      Thanks in advance.

      Gabriele

        • 1. Re: NPE sending an ObjectMessage
          clebert.suconic

          Do a print of bloccoServiceQueue. Maybe that's coming null for you?

           

           

          Also, can you check if this is happening at the latest 6.0 Snapshot? (with HQ 2.2)

          • 2. Re: NPE sending an ObjectMessage
            gcontini

            Thank you for answering so promptly. Just before the sender.send there is this line:

            `LOGGER.info("Publishing Message to a Queue: " + this.bloccoServiceQueue)`

             

            that outputs:

             

            2011-06-09 16:25:43,677 INFO  [it.unimaticaspa.service.conservazione.blocco.BloccoServiceTimerManagerBean] (pool-205-thread-3) Publishing Message to a Queue: HornetQQueue[BloccoServiceQueue]

             

            Thus the queue isn't null. Moreover if i send a TextMessage it works.

            I'll check against jboss 6.1.x snapshot and i'll let you know. 

            • 3. Re: NPE sending an ObjectMessage
              gcontini

              I can confirm: the current (14/jun/2011) jboss 6.1.x snapshot works fine.

              • 4. Re: NPE sending an ObjectMessage
                vandfr

                I encountered the same issue

                I have found a workaround with JBOss 6.0.0: I just delayed the sending of the JMS message.

                 

                A the beginning, I was sending the JMS message in the "start()" method of a JBoss service.

                This was causing the NullPointer.

                And then I modified my source code to send the JMS message in a concurrent thread after a delay of time (ex: 40s).

                And it works fine with JBoss 6.0.0.

                 

                Hope this will help.