Skip navigation
3449 Views 1 Reply Latest reply: Jan 3, 2008 1:13 PM by Guus der Kinderen RSS
Guus der Kinderen KeyContributor 770 posts since
Sep 8, 2005
Currently Being Moderated

Nov 9, 2007 5:09 AM

bug: Nullpointer in LocalOutgoingServerSession (+fix)

This is an excerpt from LocalOutgoingServerSession#returnErrorToSender(Packet packet):

 


if (packet instanceof IQ) {
    IQ reply = new IQ();
    reply.setID(packet.getID());
    reply.setTo(packet.getFrom());
    reply.setFrom(packet.getTo());
    reply.setChildElement(((IQ) packet).getChildElement().createCopy());
    reply.setError(PacketError.Condition.remote_server_not_found);
    routingTable.routePacket(reply.getTo(), reply, true);
}

 

This code will throw a NullPointerException if the IQ that is being replied to doesn't have a child element (this is valid for IQ types 'result' and 'error'). It is in any case a violation of RFC-3920 to respond with an 'error' stanza to an 'error' or 'result' stanza.

 

Something like this should fix the problem. It does no longer notify the sender that a problem occurred though:


if (packet instanceof IQ) {
     IQ iq = (IQ) packet;
     if (iq.getType().equals(IQ.Type.result) || iq.getType().equals(IQ.Type.error)) {
          Log.warn("XMPP specs forbid us to respond with an IQ error to: " + packet);
          return;
     }
     IQ reply = new IQ();
     reply.setID(packet.getID());
     reply.setTo(packet.getFrom());
     reply.setFrom(packet.getTo());
     reply.setChildElement(iq.getChildElement().createCopy());
     reply.setError(PacketError.Condition.remote_server_not_found);
     routingTable.routePacket(reply.getTo(), reply, true);
}

 

More Like This

  • Retrieving data ...

Bookmarked By (0)