NullPointerException thrown when trying to sendMessage from ChatManager

Hi,

I’m getting NullPointerException randomly (not always reproducible) when trying to send a Chat message.

Method is sendMessage and it’s happening when it tries to make connection().sendPacket(message).

Looking at the code I’ve seen connection returns a weakReference and it is null when trying to get it. Maybe there is a need of adding a null check for connection on the following method?

**void **sendMessage(Chat chat, Message message) **throws **NotConnectedException {  
       **for**(Map.Entry<MessageListener, PacketFilter> interceptor : **interceptors**.entrySet()) {    
               PacketFilter filter = interceptor.getValue();        
**               if**(filter != **null **&& filter.accept(message)) {
                       interceptor.getKey().processMessage(message);        
               }    
       }    
*// Ensure that messages being sent have a proper FROM value **   
***     if **(message.getFrom() == **null**) {        
               message.setFrom(connection().getUser());    
     }    
     connection().sendPacket(message);
}

Could you please take a look?

The library version is: 4.1.0-beta1 (4.0.6-416-gfd69a4c 2015-01-14)

Thanks in advance!

Please follow the instructions found at https://github.com/igniterealtime/Smack/wiki/How-to-ask-for-help-or-report-an-is sue . A stacktrace would be very helpful in this case. Also note that 4.1.0-rc1 is the latest version of Smack 4.1 at the time of writing.

Thanks for your answer.

I have read the instructions before posting the question, but I’m only able to provide the info I did already since the exception is happening at ramdom as I have said, so I’m not able to provide the full stacktrace nor the trace of the exchanged stream elements.

I will try to use the version you are saying and see if it does not crash.

I have read the instructions before posting the question, but I’m only able to provide the info I did already since the exception is happening at ramdom as I have said, so I’m not able to provide the full stacktrace nor the trace of the exchanged stream elements.
That sounds like your application is not logging uncatched exceptions. May I recommend installing an uncaught exception handler? See Thread (Java Platform SE 7 )

The trace doesn’t appear to be important in this case. What’s important is the exception, the stacktrace and the exact used smack version.