powered by Jive Software

Chat state causing PacketParserUtils.parseMessage to throw IllegalStateException in Smack 4.2.0-rc2

With Smack 4.2.0-rc2, when PacketParserUtils.parseMessage receives a packet with a chatestate such as :

<message from=‘test1@test.chat/My-Mac-Pro’

xmlns=‘jabber:client’ xml:lang=‘en’ type=‘chat’ to=‘test2@test.chat’ id=‘aacba’>

Test

<active

xmlns=‘http://jabber.org/protocol/chatstates’/>

A IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of ") is thrown here:

public static Message parseMessage(XmlPullParser parser){

int eventType = parser.next();

switch (eventType) {

case XmlPullParser.START_TAG:

String elementName = parser.getName();

String namespace = parser.getNamespace();

switch(elementName) {

case XmlPullParser.TEXT:

throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of ");

}

}

}

Am I missing something in smack 4.2 to be able to handle messages with chat state? Or is this a bug?

<message from=‘test1@test.chat/My-Mac-Pro’

xmlns=‘jabber:client’ xml:lang=‘en’ type=‘chat’ to=‘test2@test.chat’ id=‘aacba’>

Test

<active

xmlns=‘http://jabber.org/protocol/chatstates’/>

Are you positive that this stanza triggers it?

The message is wrapped inside a Mam message. But all the other messages that are pulled down from mam without a chat state element are parsed without problem.

Please show the complete stanza.

Full message stanza :

<message from='test1@test.chat' to='test1@test.chat/Android-51022b787fb44d76'><result queryid='89532d30-d2d1-4437-91b1-fef93e91de00' xmlns='urn:xmpp:mam:1' id='AESBQLFD89G1'><forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' from='test2@test.chat/My-Mac-Pro' stamp='2016-09-02T20:04:09Z'></delay><message from='test2@test.chat/My-Mac-Pro' xmlns='jabber:client' xml:lang='en' type='chat' to='test1@test.chat' id='aacba'>
<body>test</body>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message></forwarded></result><delay xmlns='urn:xmpp:delay' from='atlas.chat' stamp='2017-01-23T05:42:54.923769Z'>Offline Storage</delay></message>

We have the same issue on Smack 4.2.0-rc2.

Our analysis is, it is caused by messages sent by a clients that formats its XML-messages. Also its very easy to replicate.

Use the EnhancedDebugger, Copy a message from the ‘All packets’ tab, this is nicely formatted to make it readable, Paste this message in the ‘Ad hoc message’, press Send and see your client halt with the mentioned exception.

text

It applies for messages and presences.

Please try the latest 4.2.0-rc3-SNAPSHOT and report back if it fixes the issue. Thank you.

Working for me! Thanks!

And for me! (@Luca You may set the question to answered now)