Using the simple VCBuilder constructor and then subsequently trying to modify attributes was throwing a NPE. This is easily solved (without a performance hit) by initializing the attributes map to an immutable Collections.emptyMap(). Added unit test to cover this case.
This commit is contained in:
parent
9e76e8aa0b
commit
94540ccc27
|
|
@ -94,6 +94,7 @@ public class VariantContextBuilder {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.stop = stop;
|
this.stop = stop;
|
||||||
this.alleles = alleles;
|
this.alleles = alleles;
|
||||||
|
this.attributes = Collections.emptyMap(); // immutable
|
||||||
toValidate.add(VariantContext.Validation.ALLELES);
|
toValidate.add(VariantContext.Validation.ALLELES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -750,6 +750,10 @@ public class VariantContextUnitTest extends BaseTest {
|
||||||
modified = new VariantContextBuilder(modified).attributes(null).attribute("AC", 1).make();
|
modified = new VariantContextBuilder(modified).attributes(null).attribute("AC", 1).make();
|
||||||
Assert.assertEquals(modified.getAttribute("AC"), 1);
|
Assert.assertEquals(modified.getAttribute("AC"), 1);
|
||||||
|
|
||||||
|
// test the behavior when the builder's attribute object is not initialized
|
||||||
|
modified = new VariantContextBuilder(modified.getSource(), modified.getChr(), modified.getStart(), modified.getEnd(), modified.getAlleles()).attribute("AC", 1).make();
|
||||||
|
|
||||||
|
// test normal attribute modification
|
||||||
modified = new VariantContextBuilder(cfg.vc).attribute("AC", 1).make();
|
modified = new VariantContextBuilder(cfg.vc).attribute("AC", 1).make();
|
||||||
Assert.assertEquals(modified.getAttribute("AC"), 1);
|
Assert.assertEquals(modified.getAttribute("AC"), 1);
|
||||||
modified = new VariantContextBuilder(modified).attribute("AC", 2).make();
|
modified = new VariantContextBuilder(modified).attribute("AC", 2).make();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue