powered by Jive Software

Bug: packet.getExtension() fails after iterating extensions

…If this winds up doubled, I apologize. I thought I posted this but now can’t find it.

Desc: If I iterate over the extension set on a packet looking for my PacketExtension, I find it just fine. However if I then look for it directly after iteration via packet.getExtension(), it is not found.

If I ask for it directly and then iterate, both calls succeed. Code fragment follows – this path works as expected.

public void processPacket(Packet packet) {

log.debug("[processPacket ]" + packet.toXML());

if (packet instanceof Message) {

// some syntactic sugar because parenthesis are endangered and casting wastes them

Message m = (Message)packet;

boolean contentHandled = false;

PacketExtension pe2 = m.getExtension(“content”, XMLConstants.AV_CORTEXT_NAMESPACE);

if(pe2 != null){

log.debug("found a cortext message with content element in namespace: " + pe2.getNamespace());

// connection.sendPacket(cmf.handleContent(m, botDirectory));


Iterator i = m.getExtensions().iterator();


PacketExtension pe = i.next();

log.debug("extension: " + pe.getClass().getCanonicalName() + " " + pe.getElementName() + " " + pe.getNamespace());


log.debug("found content element: ");

log.debug("it is a: " + ((ContentExtension)pe).getMimeType());

// connection.sendPacket(cmf.handleContent(m, botDirectory));

contentHandled = true; // set flag so that we don’t handle it again




// … code elided …


If you move the block that starts with:

PacketExtension pe2 = m.getExtension(“content”, XMLConstants.AV_CORTEXT_NAMESPACE);

so that it is called to after the iteration, it gets back null instead of the expected PacketExtension
webchat.war (2232143 Bytes)