powered by Jive Software

Smack 4.4.0. Message#getBody() and Message#getSubject() returns null string for non-empty body content in message

smack Message.getBody() returns null for the following message sent from server.
Debug trace shows that getBody() failed the test condition i.e.:
if (Objects.equals(language, body.language) || (language != null && language.equals(this.language) && body.language == null)

based on the actual derived parameters i.e.:
where language == null and body.language == “en”

Similarly it also failed for Message#getSubject()

    private Body getMessageBody(String language) {
        language = determineLanguage(language);
        for (Body body : getBodies()) {
            if (Objects.equals(language, body.language) || (language != null && language.equals(this.language) && body.language == null)) {
                return body;
            }
        }
        return null;
    }

=========== server welcome message ==============

2019-09-12 07:25:05.230 23763-24342/org.atalk.android D/SMACK: RECV (4): 
    <message to='test4@atalk.sytes.net/atalk' from='atalk.sytes.net'>
      <delay xmlns='urn:xmpp:delay' from='atalk.sytes.net' stamp='2019-09-11T23:24:57.760894Z'>
        Offline Storage
      </delay>
      <body xml:lang='en'>
        Welcome to aTalk XMPP server. 
    For information visit: https://atalk.sytes.net
      </body>
      <subject xml:lang='en'>
        Welcome!
      </subject>
    </message>

https://xmpp.org/rfcs/rfc3920.html

9.1.5. xml:lang

A stanza SHOULD possess an ‘xml:lang’ attribute (as defined in Section 2.12 of [XML]) if the stanza contains XML character data that is intended to be presented to a human user (as explained in RFC 2277 [CHARSET], “internationalization is for humans”). The value of the ‘xml:lang’ attribute specifies the default language of any such human-readable XML character data, which MAY be overridden by the ‘xml:lang’ attribute of a specific child element. If a stanza does not possess an ‘xml:lang’ attribute, an implementation MUST assume that the default language is that specified for the stream as defined under Stream Attributes above. The value of the ‘xml:lang’ attribute MUST be an NMTOKEN and MUST conform to the format defined in RFC 3066 [LANGTAGS].

If the stream has an xml:lang set to ‘en’, then this should be “fixed” with

Thanks. New implementation has been verified working.

1 Like

Can you mark @Flow’s reply as the answer?