Account for a null attributes object

* field attributesCanBeModified - a null attributes object can't be modified in its current state
* method makeAttributesModifiable() - initialize a null attributes object to empty
This commit is contained in:
Joel Thibault 2012-06-22 16:56:04 -04:00
parent d0cf8bcc80
commit f0c54d99ed
1 changed files with 8 additions and 1 deletions

View File

@ -182,7 +182,13 @@ public class VariantContextBuilder {
* @param attributes
*/
public VariantContextBuilder attributes(final Map<String, Object> attributes) {
this.attributes = attributes;
if (attributes != null) {
this.attributes = attributes;
}
else {
this.attributes = new HashMap<String, Object>();
}
this.attributesCanBeModified = true;
return this;
}
@ -220,6 +226,7 @@ public class VariantContextBuilder {
* Makes the attributes field modifiable. In many cases attributes is just a pointer to an immutable
* collection, so methods that want to add / remove records require the attributes to be copied to a
*/
@Ensures({"this.attributesCanBeModified"})
private void makeAttributesModifiable() {
if ( ! attributesCanBeModified ) {
this.attributesCanBeModified = true;