From 26200eab218900ebf5dcd1ef5a0abd33883a49bc Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Tue, 28 Jul 2015 15:33:39 -0500 Subject: [PATCH] Fixes GitHub issue #19: NPE in MediaDescription#setAttribute() because CandidateAttribute#attribute is null. --- .../org/ice4j/ice/sdp/CandidateAttribute.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/ice4j/ice/sdp/CandidateAttribute.java b/src/main/java/org/ice4j/ice/sdp/CandidateAttribute.java index 578e21e..f2deb76 100644 --- a/src/main/java/org/ice4j/ice/sdp/CandidateAttribute.java +++ b/src/main/java/org/ice4j/ice/sdp/CandidateAttribute.java @@ -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 *