Synchronized Message's attributes operations as it can cause ConcurrentModificationException sometime.
This commit is contained in:
parent
547c568d9d
commit
dce3326061
@ -446,7 +446,8 @@ public abstract class Message
|
|||||||
{
|
{
|
||||||
char length = 0;
|
char length = 0;
|
||||||
|
|
||||||
for (Attribute att : attributes.values())
|
List<Attribute> attrs = getAttributes();
|
||||||
|
for (Attribute att : attrs)
|
||||||
{
|
{
|
||||||
int attLen = att.getDataLength() + Attribute.HEADER_LENGTH;
|
int attLen = att.getDataLength() + Attribute.HEADER_LENGTH;
|
||||||
|
|
||||||
@ -468,7 +469,9 @@ public abstract class Message
|
|||||||
{
|
{
|
||||||
char length = 0;
|
char length = 0;
|
||||||
|
|
||||||
for (Attribute att : attributes.values())
|
List<Attribute> attrs = getAttributes();
|
||||||
|
|
||||||
|
for (Attribute att : attrs)
|
||||||
{
|
{
|
||||||
int attLen = att.getDataLength() + Attribute.HEADER_LENGTH;
|
int attLen = att.getDataLength() + Attribute.HEADER_LENGTH;
|
||||||
length += attLen;
|
length += attLen;
|
||||||
@ -497,8 +500,11 @@ public abstract class Message
|
|||||||
+ getName());
|
+ getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized(attributes)
|
||||||
|
{
|
||||||
attributes.put(attribute.getAttributeType(), attribute);
|
attributes.put(attribute.getAttributeType(), attribute);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <tt>true</tt> if the this <tt>Message</tt> contains an attribute
|
* Returns <tt>true</tt> if the this <tt>Message</tt> contains an attribute
|
||||||
@ -523,9 +529,12 @@ public abstract class Message
|
|||||||
* attribute exists
|
* attribute exists
|
||||||
*/
|
*/
|
||||||
public Attribute getAttribute(char attributeType)
|
public Attribute getAttribute(char attributeType)
|
||||||
|
{
|
||||||
|
synchronized(attributes)
|
||||||
{
|
{
|
||||||
return attributes.get(attributeType);
|
return attributes.get(attributeType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a copy of all {@link Attribute}s in this {@link Message}.
|
* Returns a copy of all {@link Attribute}s in this {@link Message}.
|
||||||
@ -533,9 +542,12 @@ public abstract class Message
|
|||||||
* @return a copy of all {@link Attribute}s in this {@link Message}.
|
* @return a copy of all {@link Attribute}s in this {@link Message}.
|
||||||
*/
|
*/
|
||||||
public List<Attribute> getAttributes()
|
public List<Attribute> getAttributes()
|
||||||
|
{
|
||||||
|
synchronized(attributes)
|
||||||
{
|
{
|
||||||
return new LinkedList<Attribute>(attributes.values());
|
return new LinkedList<Attribute>(attributes.values());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified attribute.
|
* Removes the specified attribute.
|
||||||
@ -545,9 +557,12 @@ public abstract class Message
|
|||||||
* @return the <tt>Attribute</tt> we've just removed.
|
* @return the <tt>Attribute</tt> we've just removed.
|
||||||
*/
|
*/
|
||||||
public Attribute removeAttribute(char attributeType)
|
public Attribute removeAttribute(char attributeType)
|
||||||
|
{
|
||||||
|
synchronized(attributes)
|
||||||
{
|
{
|
||||||
return attributes.remove(attributeType);
|
return attributes.remove(attributeType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of attributes, currently contained by the message.
|
* Returns the number of attributes, currently contained by the message.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user