ActiveMQ NullPointer exceptions when creating objectmessages.

Posted on March 24, 2009. Filed under: Java |

At the moment, I’m working with Flex, BlazeDS en ActiveMQ in a Spring application. I’m using Flex to display some of my database contents, and for direct communication, I use BlazeDS, and for updating the view, I use JMS (ActiveMQ) in combation with BlazeDS. It works by publishing information to topics, which can be easily done using the following code:

    private void sendJmsUpdate() {
        this.jmsTemplate.send(this.destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return session.createObjectMessage(new ArrayList<TodoItem>(getList()));
            }
        });
    }

The above code uses the Spring JmsTemplate to created messages and send them to the topic. However, when I tried this, I got this exception:


java.lang.NullPointerException
at org.apache.activemq.ActiveMQMessageTransformation.copyProperties(ActiveMQMessageTransformation.java:188)
at org.apache.activemq.ActiveMQMessageTransformation.transformMessage(ActiveMQMessageTransformation.java:173)
at org.apache.activemq.ActiveMQSession.send(ActiveMQSession.java:1606)
at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:227)
at org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:241)
at org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:572)
at org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:549)
at org.springframework.jms.core.JmsTemplate$3.doInJms(JmsTemplate.java:516)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:447)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:514)
at org.epseelon.samples.todolist.business.TodoServiceImpl.sendJmsUpdate(TodoServiceImpl.java:77)
at org.epseelon.samples.todolist.business.TodoServiceImpl.save(TodoServiceImpl.java:39)
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:585)

After a lot of Googling, I found nothing (well, a bug report somewhere, which was totally unrelated to what I had here). Why did I get this error?? I know my remoting was working (String were send), my objects were fine since I could get the list manually by doing a Refresh with the flex client itself (which used ≶mx:RemoteObject>) to call the Spring service…. And then it occured to me that the explanation was already here. I just overlooked it (hate it when that happens): the BlazeDS service apparently doesn’t require the objects (TodoItem) to be Serializable…. JMS ofcourse does! Argh! I forgot to implement Serializable here!

So, if you ever encounter this message, which is hardly descriptive at all, check your objects to see if they are all serializable. It saves a lot of debugging!

Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

One Response to “ActiveMQ NullPointer exceptions when creating objectmessages.”

RSS Feed for Don’t mind the language Comments RSS Feed

Could it be that it’s too costly to introspect passed objects, checking whether they are able to serialize or not? Either way they could catch the NPE and rethrow it with some suggestions like

OH HAI DID U IMPLEMENTS SEERIZABL? KTNXBAI


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: