4

I am facing an issue with the library smack. I got an exception like below when I update to Android studio to 4.1 and Gradle to 6.5

  Caused by: java.lang.AssertionError
    at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:686)
    at com.app.modules.rnxmpp.service.XmppServiceSmackImpl.sendStanza(XmppServiceSmackImpl.java:713)
    at com.app.modules.rnxmpp.RNXMPPModule.sendStanza(RNXMPPModule.java:189)

Before 4.1 and Gradle 6.0.1, there is no error in the code nor any crash. This only happens when I update the studio and Gradle.

The error is causing by the code in the smack library

//org.jivesoftware.smack.AbstractXMPPConnection
     @Override
    public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
        Objects.requireNonNull(stanza, "Stanza must not be null");
        assert (stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);

        throwNotConnectedExceptionIfAppropriate();
        switch (fromMode) {
        case OMITTED:
            stanza.setFrom((Jid) null);
            break;
        case USER:
            stanza.setFrom(getUser());
            break;
        case UNCHANGED:
        default:
            break;
        }
        // Invoke interceptors for the new stanza that is about to be sent. Interceptors may modify
        // the content of the stanza.
        firePacketInterceptors(stanza);
        sendStanzaInternal(stanza);
    }

There is an assert call in the library file called AbstractXMPPConnection

when I call this function I got a crash and the above stack trace is shown on the log. Does anyone know what happens here? Android studio version: 4.1 gradle https://services.gradle.org/distributions/gradle-6.5-bin.zip //smack library

 implementation "org.igniterealtime.smack:smack-android-extensions:4.3.0"
implementation "org.igniterealtime.smack:smack-tcp:4.3.0"
implementation "org.igniterealtime.smack:smack-extensions:4.3.0"
implementation 'org.igniterealtime.smack:smack-sasl-provided:4.1.9'
Vinayak B
  • 4,430
  • 4
  • 28
  • 58

1 Answers1

1

I had the same problem. I'm using the MultipleRecipientManager

The problem was I've got no DomainBareJid and the method sendToIndividualRecipients(...) was called.

 public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc,
        Jid replyTo, Jid replyRoom, boolean noReply) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException {
    // Check if *only* 'to' is set and contains just *one* entry, in this case extended stanzas addressing is not
    // required at all and we can send it just as normal stanza without needing to add the extension element
    if (to != null && to.size() == 1 && (cc == null || cc.isEmpty()) && (bcc == null || bcc.isEmpty()) && !noReply
                    && StringUtils.isNullOrEmpty(replyTo) && StringUtils.isNullOrEmpty(replyRoom)) {
        Jid toJid = to.iterator().next();
        packet.setTo(toJid);
        connection.sendStanza(packet);
        return;
    }
    DomainBareJid serviceAddress = getMultipleRecipientServiceAddress(connection);
    if (serviceAddress != null) {
        // Send packet to target users using multiple recipient service provided by the server
        sendThroughService(connection, packet, to, cc, bcc, replyTo, replyRoom, noReply,
                serviceAddress);
    }
    else {
        // Server does not support XEP-33 so try to send the packet to each recipient
        if (noReply || replyTo != null ||
                replyRoom != null) {
            // Some specified XEP-33 features were requested so throw an exception alerting
            // the user that this features are not available
            throw new FeatureNotSupportedException("Extended Stanza Addressing");
        }
        // Send the packet to each individual recipient
        sendToIndividualRecipients(connection, packet, to, cc, bcc);
    }
}

An internal class PacketCopy will be send as stanza.

connection.sendStanza(new PacketCopy(packet.toXML(null)));

But the AbstractXMPPConnection assert check failed. Because the PacketCopy not extend from Message, Presence or IQ.

public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
    Objects.requireNonNull(stanza, "Stanza must not be null");
    assert (stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);

    throwNotConnectedExceptionIfAppropriate();
    switch (fromMode) {
    case OMITTED:
        stanza.setFrom((Jid) null);
        break;
    case USER:
        stanza.setFrom(getUser());
        break;
    case UNCHANGED:
    default:
        break;
    }
    // Invoke interceptors for the new stanza that is about to be sent. Interceptors may modify
    // the content of the stanza.
    firePacketInterceptors(stanza);
    sendStanzaInternal(stanza);
}

My Solution: Before I've updated my ejabberd docker image and I've forgot to enable the mod_multicast module. After enabling the mod_multicast module. I've got a DomainBareJid and the correct Stanza type (in my case Message) will be send.

Dennis
  • 11
  • 2
  • I am using Ejabberd SASS. So I can't change anything. this code works fine on Gradle 6.1.1. and if I update to 6.5 then I got issues – Vinayak B Nov 02 '20 at 13:00