Crash when receiving other Message types

The Xmpp server I’m connecting to has another chat type that isn’t “chat” or “groupchat”. When this message comes in the stream gets force disconnected. For the time being, is there an area I might be able to throw into a try catch? I don’t want this to hold up a story I’m working on.

2019-11-22 11:58:36.598 15536-15668/{package name} W/hrowingCallbackWithHint: Parsing exception encountered. This exception will be re-thrown, leading to a disconnect. You can change this behavior by setting a different ParsingExceptionCallback using setParsingExceptionCallback(). More information an be found in AbstractXMPPConnection's javadoc.
2019-11-22 11:58:36.621 15536-16142/{package name}W/AbstractXMPPConnection: Connection XMPPTCPConnection[{user's jid}] (0) closed with error
    java.lang.IllegalArgumentException: No enum constant org.jivesoftware.smack.packet.Message.Type.{unsupported type}
        at java.lang.Enum.valueOf(Enum.java:257)
        at org.jivesoftware.smack.packet.Message$Type.valueOf(Message.java:724)
        at org.jivesoftware.smack.packet.Message$Type.fromString(Message.java:761)
        at org.jivesoftware.smack.util.PacketParserUtils.parseMessage(PacketParserUtils.java:231)
        at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:155)
        at org.jivesoftware.smack.AbstractXMPPConnection.parseAndProcessStanza(AbstractXMPPConnection.java:1084)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1300(XMPPTCPConnection.java:155)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1144)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$1000(XMPPTCPConnection.java:1092)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1112)
        at java.lang.Thread.run(Thread.java:919)

Smack is adhering the specification.
In rfc3921 §2.1.1 is a list of allowed message types.
Smack does implement those exact types. If your server deals with other types, then your server is not speaking XMPP.

You could try catching the parsing exception using AbstractXMPPConnection.setParsingExceptionCallback(ParsingExceptionCallback callback), but I’m not sure if this will lead to your desired result.

If I was in your position I’d probably try to change your server implementation to adhere to the standard. The X in XMPP means eXtensible, it means that you can extend the protocol easily by creating your own extension elements (also proprietary ones).

1 Like

Forgot to specify… I have no control over what the server sends. It’s a painful server to work with but I have no choice in the matter. :slightly_smiling_face:

When the server sends out that message through XMPP it also sends it out as a push notification. I’m handling the message via push notification so I don’t need to one sent via XMPP. All I need is for the stream to not close when it can’t handle parsing the message.

Thanks for the reply and I will try the Parsing Exception Callback as I think that will work in my situation. :+1:

EDIT: The solution worked perfectly… Thanks!

2 Likes

Glad to hear that :slight_smile:

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.