Fixes GitHub issue #19: NPE in MediaDescription#setAttribute() because CandidateAttribute#attribute is null.

This commit is contained in:
Lyubomir Marinov 2015-07-28 15:33:39 -05:00
parent 7072173ed3
commit 26200eab21

View File

@ -32,6 +32,7 @@ public class CandidateAttribute extends AttributeField
protected CandidateAttribute()
{
this(null);
}
/**
@ -44,6 +45,29 @@ public class CandidateAttribute extends AttributeField
this.candidate = candidate;
}
/**
* {@inheritDoc}
*/
public NameValue getAttribute()
{
// We've overridden the method getValue() of AttributeField. The
// NameValue pair of the method getAttribute() should return the value of
// the method getValue() of AttributeField then. Unfortunately, NameValue
// accesses its field value in multiple places so it is not a question of
// simply overriding a method or two. As a compromise, initialize a new
// NameValue with the current name and value upon each invocation.
NameValue attribute = super.getAttribute();
String name = getName();
if ((attribute == null)
|| (name.equals(attribute.getName())
&& (attribute.getValue() == null)))
{
attribute = new NameValue(name, getValue());
}
return attribute;
}
/**
* Returns the name of this attribute
*