powered by Jive Software

ChatStateManager Exception


I recently began trying to use the new ChatState system in Smack 3.0.2 and have run into the following exception:

java.lang.NullPointerException: null values not allowed

at org.jivesoftware.smack.util.collections.AbstractReferenceMap.put(AbstractRefere nceMap.java:252)

at org.jivesoftware.smackx.ChatStateManager.updateChatState(ChatStateManager.java: 122)

at org.jivesoftware.smackx.ChatStateManager.access$300(ChatStateManager.java:45)

at org.jivesoftware.smackx.ChatStateManager$OutgoingMessageInterceptor.interceptPa cket(ChatStateManager.java:144)

at org.jivesoftware.smack.ChatManager.sendMessage(ChatManager.java:228)

at org.jivesoftware.smack.Chat.sendMessage(Chat.java:113)

After looking at the code, I believe to fix the null pointer line 122 of ChatStateManager should be this:

chatStates.put(chat, newState);

instead of this:

chatStates.put(chat, lastChatState);



I am about to check in this fix:




Hi Alex,

Thanks for checking in the fix. Since my original post I now have a working example of using your chat state system (I like it a lot more than message events). One other stumbling block I ran into for a while was that I didn’'t initially realize you need to call ChatStateManager.getInstance() right after the connection was created in order to receive all the typing notifications I was expecting. I originally only made that call when I needed to send typing notifications because I assumed it registered listeners at startup behind the scenes. I eventually figured it out after some debugging, but a more clear statement about it in the Javadoc would be nice for future developers.



Thanks, for the idea! I added the note to the JavaDoc, though longer term I would like a better way to handle this automatically.

I would like it so that you will only advertise that you support ChatStates on a chat if you have a listener on the chat listening for the update.




It seems the fix you checked in does not actually fix my problem. The use case is as follows:

1.) User A sends a message for the first time to user B.

2.) User B starts typing a reply for the first time and therefore sends a chat state.

3.) The exception is thrown.

The original fix I posted works for me, please see lines 146-150 of ChatStateManager:

ChatState lastChatState = chatStates.get(chat);

if (lastChatState == null || lastChatState != newState) {

chatStates.put(chat, lastChatState);

return true;


You see that the first time a chat state is ever sent for a chat, lastChatState will be null. Since the chatStates variable can never have null values, I don’'t think you would ever want to check that lastChatState == null and then go ahead and try to put into the map.



My apologies, I missed the fix. I have been working on some test cases for it so I am sorry you are a bit of a guinea pig. Anyways I checked in again and it should work as expected.



No worries Alex :). I just grabbed your latest patch and it seems to be working fine now.

Thanks for your support,