#57 MessageImpl.getOrderedParts() bug

open
nobody
None
5
2011-04-14
2011-04-14
redmitry
No

The method returns duplicated parts when a part was reinserted into the message.

Part part = definition.createPart();
part.setName("part");

message.addPart(part);
message.removePart(part.getName());
message.addPart(part);

message.getOrderedParts(null) // returns 2 (!) parts

Actually whole getOrderedParts() is a mess...

Would it be better to use LinkedHashMap instead of HashMap for parts and reimplement the method:

public List getOrderedParts(List partOrder)
{
if (partOrder == null)
{
return new ArrayList(parts.values());
}

List orderedParts = new ArrayList();

Iterator partNameIterator = partOrder.iterator();

while (partNameIterator.hasNext())
{
String partName = (String)partNameIterator.next();
Part part = getPart(partName);

if (part != null)
{
orderedParts.add(part);
}
}

Discussion