Error when offline storing missing body messages

Hello,

We have found what we consider a “bug” in offline message storage process. Openfire fails trying to store a into the offline mesage repository if the tag is missing.

With the last review of this method, the following check has been added.

public void addMessage(Message message) {
if (message == null) {
return;
}
if (message.getBody() == null || message.getBody().length() == 0) {
// ignore empty bodied message (typically chat-state notifications).
return;
}
******

*** ***

The problem is that if the message has no tag, when message.getBody().length() is called, a NullPointerException is thrown. There is no problem in the server behaviour, since the exception is later on captured and the server keeps running. Anyway, I think it worths adding extra checking to this method, probably something like this:

public void addMessage(Message message) {
if (message == null) {
return;
}
String body = message.getBody();
if (body != null) {
int length = body.length();
if (length == 0) {
// ignore empty bodied message (typically chat-state
// notifications).
return;
}

*** …***

Another discussion is if this behaviour should change to store messages without a tag. In our case, we are using a private protocol extension based on but not using the standard architecture. Starting from 3.6.0 release, OpenFire doesn’t store messages without a tag. impying that when our service send a message to an offline destination, the message is lost since the server doesn’t store it for delayed delivery.

Don’t get me wrong, I’m not suggesting to support to this kind of messages (without tag), I just want to start a discussion about it. The decission is yours, of course.

Thanks for your time.

The problem is that if the message has no tag, when message.getBody().length() is called, a NullPointerException is thrown.
Sure? Are you using an JRE that conforms java specifications? Second part of an logical OR is only executed if the first part is false.

However, I agree that we have to think about to store also messages that contain no element. E.g. PubSub does use such messages.

public class Test {
    static boolean print(int i) {
        System.out.println("exec: " + i);
        return true;
    }     public static void main(String[] args) {
        boolean b1 = print(1) || print(2);
        boolean b2 = print(3) | print(4);
    }   
}

Output:

[coolcat@sempron2800 Java]$ javac Test.java
[coolcat@sempron2800 Java]$ java Test
exec: 1
exec: 3
exec: 4
[coolcat@sempron2800 Java]$

You are right. It was my fault. I think I deleted a “|” by mistake while debugging. Nothing more to say here.

Anyway, I think is really insteresting to support messages without a tag.

Thanks for the answer.