Smack 4.4.6: IQ error stanza generation does not allow adding of an extension element

With refer to the xep document below:
XEP-0070: Verifying HTTP Requests via XMPP#4.6 XMPP Client Confirms Request via XMPP

Example 8. XMPP Client Denies Request via IQ

If the user wishes to deny the request, the <iq/> response stanza MUST be of type "error", MAY contain the original <confirm/> child element (although this is not necessary since the XMPP 'id' attribute can be used for tracking purposes), and MUST specify an error, which SHOULD be <not-authorized/>:

Although the inclusion of the <confirm/> element received from the requester is optional, it is found that some server require the <confirm/> element to work properly e.g. ‘’.

However in smack IQ class method appendInnerXml(), it is being disabled by designed (see attached source comment); also the IQ source does not allow @override these in sub-class.

     * Append the sub-element XML section of the IQ stanza.
     * @param xml the XmlStringBuilder to append to.
    private void appendInnerXml(XmlStringBuilder xml) {
        if (type == Type.error) {
            // Add the error sub-packet, if there is one.
           // *** cmeng; must comment out below 'return' to include <confirm/> in error response ***/
        if (childElementName == null) {

        // Add the query section if there is one.
        IQChildElementXmlStringBuilder iqChildElement = getIQChildElementBuilder(
                        new IQChildElementXmlStringBuilder(getChildElementName(), getChildElementNamespace(), null, xml.getXmlEnvironment()));
        // TOOD: Document the cases where iqChildElement is null but childElementName not. And if there are none, change
        // the logic.
        if (iqChildElement == null) {


        List<ExtensionElement> extensionsXml = getExtensions();
        if (iqChildElement.isEmptyElement) {
            if (extensionsXml.isEmpty()) {



aTalk generated IQ error stanza when ‘return’ is commented out:

2023-03-01 06:58:19.923 1725-2177/ D/SMACK: RECV (0): 
    <iq xml:lang='en' to='' from='' type='result' id='IVIGU-27'>
      <query xmlns=''>
        <streamhost port='7777' host='' jid=''/>

2023-03-01 06:58:20.287 1725-2176/ D/SMACK: SENT (0): 
    <iq to='' id='54' type='error'>
      <error type='auth'>
        <not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
      <confirm xmlns='' id='36FCSc' method='POST' url=''/>

As I read RFC6120 section 8.2.3, an IQ stanza of type error must include an error child element, and may include another child element, one that matches the child element from the associated get or set request. IQ ‘error’ stanzas are different from regular stanzas that way, as they allow for more than one child element where IQ stanzas of other types only allow for one.

XEP-0070 seems to specify that the additional child element that is added to the error is from the associated request, so that tracks well with the definition in the RFC.

I think that the return statement that you reference prevents the child element from the associated request stanza to be attached, which would seem like an omission, or possibly even a bug to me. I’ll defer to @Flow for confirmation.

The return is there by design. You must use Iq.createErrorResponse(IQ, StanzaError) to create error-type IQs. This should be better documented in Smack, I’ll see to create a PR.

I am sorry, I think I am being stupid and I had another return in mind. In any case, after looking at the code again, I think you are right that the early return prevents the attachment of the optional original request in the IQ error response. Investigating.


And, fwiw, the following is the return that I had in mind:

Created SMACK-931.