powered by Jive Software

Smack 4.4.0-alpha3 throws Concurrent Modification Exception in XmlStringBuilder.appendXmlTo()

Preformatted textSmack-4.4.0-alpha3-SNAPSHOT has ConcurrentModificationException in XmlStringBuilder#appendXmlTo() as shown in aTalk capture log below
believe to be caused by object LazyStringBuilder sb;

2019-10-03 10:00:52.429 18487-19125/org.atalk.android I/aTalk: [23497] org.jivesoftware.smack.AbstractXMPPConnection.notifyConnectionError() Connection was already disconnected when attempting to handle java.util.ConcurrentModificationException
    java.util.ConcurrentModificationException
        at java.util.ArrayList$Itr.next(ArrayList.java:860)
        at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1084)
        at org.jivesoftware.smack.util.XmlStringBuilder.appendXmlTo(XmlStringBuilder.java:642)
        at org.jivesoftware.smack.util.XmlStringBuilder.write(XmlStringBuilder.java:622)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1352)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$3400(XMPPTCPConnection.java:1159)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1211)
        at java.lang.Thread.run(Thread.java:764)

After I applied a simple source changed as below to eliminate ConcurrentModificationException i.e.

    private void appendXmlTo(Appendable appendable, XmlEnvironment enclosingXmlEnvironment) throws IOException {
        List<CharSequence> sbList = new ArrayList<>();
        sbList.addAll(sb.getAsList());
        for (CharSequence csq : sbList) {
            if (csq instanceof XmlStringBuilder) {
                ((XmlStringBuilder) csq).appendXmlTo(appendable, enclosingXmlEnvironment);
            }
            else if (csq instanceof XmlNsAttribute) {
                XmlNsAttribute xmlNsAttribute = (XmlNsAttribute) csq;
                if (!xmlNsAttribute.value.equals(enclosingXmlEnvironment.getEffectiveNamespace())) {
                    sb.append(xmlNsAttribute);
                    enclosingXmlEnvironment = new XmlEnvironment(xmlNsAttribute.value);
                }
            }
            else {
                appendable.append(csq);
            }
        }
    }

However user login in still failed as the last stanza sent from aTalk has empty content?
i.e.: <starttls> </starttls>

Any advice what can be the problem.

2019-10-03 11:22:57.620 30907-31230/org.atalk.android D/SMACK: SENT (0): 
    <stream:stream xmlns='jabber:client' to='atalk.org' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en-GB'>
2019-10-03 11:22:57.641 30907-31231/org.atalk.android D/SMACK: RECV (0): ?xml version='1.0'?>
    <stream:stream id='2565774255654660775' version='1.0' xml:lang='en-GB' xmlns:stream='http://etherx.jabber.org/streams' from='atalk.org' xmlns='jabber:client'>
    <stream:features>
      <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>
        <required/>
      </starttls>
    </stream:features>
2019-10-03 11:22:57.645 30907-31230/org.atalk.android D/SMACK: SENT (0): 
    <starttls>
    </starttls>
2019-10-03 11:23:27.607 30907-31231/org.atalk.android D/SMACK: RECV (0): 
    <stream:error>
      <connection-timeout xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
      <text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>
        Idle connection
      </text>
    </stream:error>
    </stream:stream>

If I’m not mistaken this is already reported in link and fixed with commit.

Thanks. Yes the commit fixes both the reported problem.

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