The method initializeAsResultFor() instead of reverse IQ.to and IQ.from Jid’s, it duplicates iq.to to both the IQ.to and IQ.from jid’s, as it does not save a copy of iq.from before the setFrom statement.
protected final void initializeAsResultFor(IQ request) {
if (!(request.getType() == Type.get || request.getType() == Type.set)) {
throw new IllegalArgumentException(
"IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
}
setStanzaId(request.getStanzaId());
setFrom(request.getTo());
setTo(request.getFrom());
setType(Type.result);
}
Yes, this is how I was using it. During aTalk implementation for XEP-0070, the deny reply for the IQ Request needs to include the sender stanza; So instead of create new reply IQ, my initial though was just using the iqRequest for reply by reversing the to/from attributes, then add in the StanzaError element.
To avoid future confusion and mistake made by user, would smack considers to save a copy of request.getFrom() before the setFrom(), and then use it in setTo().
I’d rather like to steer Smack into a direction where stanzas and extension elements are immutable, so that this can not happen again. Hence I consider adding a safeguard assert against this kind of misuse.